diff --git a/CNAME b/CNAME new file mode 100644 index 000000000..fb0e8d032 --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +konvajs.org \ No newline at end of file diff --git a/android-chrome-192x192.png b/android-chrome-192x192.png new file mode 100644 index 000000000..a24ebbafc Binary files /dev/null and b/android-chrome-192x192.png differ diff --git a/android-chrome-256x256.png b/android-chrome-256x256.png new file mode 100644 index 000000000..c78d344cc Binary files /dev/null and b/android-chrome-256x256.png differ diff --git a/android-chrome-manifest.json b/android-chrome-manifest.json new file mode 100644 index 000000000..52dd82061 --- /dev/null +++ b/android-chrome-manifest.json @@ -0,0 +1 @@ +{"name":"KonvaJS","icons":[{"src":"/android-chrome-36x36.png","sizes":"36x36","type":"image/png","density":"0.75"},{"src":"/android-chrome-48x48.png","sizes":"48x48","type":"image/png","density":"1.0"},{"src":"/android-chrome-72x72.png","sizes":"72x72","type":"image/png","density":"1.5"},{"src":"/android-chrome-96x96.png","sizes":"96x96","type":"image/png","density":"2.0"},{"src":"/android-chrome-145.0.3.png","sizes":"145.0.3","type":"image/png","density":"3.0"},{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png","density":"4.0"}]} \ No newline at end of file diff --git a/api/Konva.Animation.html b/api/Konva.Animation.html new file mode 100644 index 000000000..e79d0480f --- /dev/null +++ b/api/Konva.Animation.html @@ -0,0 +1,1287 @@ + + + + + + + Konva Class: Animation + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Animation

+
+ +
+ +

+ Konva~ + + Animation +

+ +

Animation constructor.

+ + +
+ + +
+
+ + +
+
+

new Animation(func [, layers])

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
func + + +AnimationFn + + + + + + + + + + +

function executed on each animation frame. The function is passed a frame object, which contains
+timeDiff, lastTime, time, and frameRate properties. The timeDiff property is the number of milliseconds that have passed
+since the last animation frame. The time property is the time in milliseconds that elapsed from the moment the animation started
+to the current animation frame. The lastTime property is a time value from the previous frame. The frameRate property is the current frame rate in frames / second.
+Return false from function, if you don't need to redraw layer/layers on some frames.

layers + + +Konva.Layer +| + +Array + + + + + + + <optional>
+ + + + + +

layer(s) to be redrawn on each animation frame. Can be a layer, an array of layers, or null.
+Not specifying a node will result in no redraw.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
// move a node to the right at 50 pixels / second
+var velocity = 50;
+
+var anim = new Konva.Animation(function(frame) {
+  var dist = velocity * (frame.timeDiff / 1000);
+  node.move({x: dist, y: 0});
+}, layer);
+
+anim.start();
+ + + +
+ + +
+ + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

addLayer(layer)

+ + +
+
+ + +
+

add layer. Returns true if the layer was added, and false if it was not

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
layer + + +Konva.Layer + + + + +

to add

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

true if layer is added to animation, otherwise false

+
+ + + +
+
+ Type +
+
+ +Bool + + + +
+
+ + + + + +
+ + + +
+
+

getLayers()

+ + +
+
+ + +
+

get layers

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

Array of Konva.Layer

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
+ + + +
+
+

isRunning()

+ + +
+
+ + +
+

determine if animation is running or not. returns true or false

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

is animation running?

+
+ + + +
+
+ Type +
+
+ +Bool + + + +
+
+ + + + + +
+ + + +
+
+

setLayers( [layers])

+ + +
+
+ + +
+

set layers to be redrawn on each animation frame

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
layers + + +Konva.Layer +| + +Array + + + + + + + <optional>
+ + + + + +

layer(s) to be redrawn. Can be a layer, an array of layers, or null. Not specifying a node will result in no redraw.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +Konva.Animation + + + +
+
+ + + + + +
+ + + +
+
+

start()

+ + +
+
+ + +
+

start animation

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +Konva.Animation + + + +
+
+ + + + + +
+ + + +
+
+

stop()

+ + +
+
+ + +
+

stop animation

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +Konva.Animation + + + +
+
+ + + + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Arc.html b/api/Konva.Arc.html new file mode 100644 index 000000000..3f4f4f3ac --- /dev/null +++ b/api/Konva.Arc.html @@ -0,0 +1,34630 @@ + + + + + + + Konva Class: Arc + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Arc

+
+ +
+ +

+ Konva. + + Arc +

+ +

Arc constructor

+ + +
+ + +
+
+ + +
+
+

new Arc(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
angle + + +Number + + + + + + + + + + +

in degrees

innerRadius + + +Number + + + + + + + + + + +
outerRadius + + +Number + + + + + + + + + + +
clockwise + + +Boolean + + + + + + + <optional>
+ + + + + +
fill + + +String + + + + + + + <optional>
+ + + + + +

fill color

fillPatternImage + + +Image + + + + + + + <optional>
+ + + + + +

fill pattern image

fillPatternX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScale + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternScaleX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScaleY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRotation + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRepeat + + +String + + + + + + + <optional>
+ + + + + +

can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"

fillLinearGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillRadialGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the fill. The default value is true

fillPriority + + +String + + + + + + + <optional>
+ + + + + +

can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration

stroke + + +String + + + + + + + <optional>
+ + + + + +

stroke color

strokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

stroke width

fillAfterStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw fill AFTER stroke? Default is false.

hitStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth

strokeHitEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke hit region. The default is true

perfectDrawEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables using buffer canvas. The default is true

shadowForStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables shadow for stroke. The default is true

strokeScaleEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke scale. The default is true

strokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the stroke. The default value is true

lineJoin + + +String + + + + + + + <optional>
+ + + + + +

can be miter, round, or bevel. The default
+is miter

lineCap + + +String + + + + + + + <optional>
+ + + + + +

can be butt, round, or square. The default
+is butt

shadowColor + + +String + + + + + + + <optional>
+ + + + + +
shadowBlur + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

shadowOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
shadowOpacity + + +Number + + + + + + + <optional>
+ + + + + +

shadow opacity. Can be any real number
+between 0 and 1

shadowEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the shadow. The default value is true

dash + + +Array + + + + + + + <optional>
+ + + + + +
dashEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the dashArray. The default value is true

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
// draw a Arc that's pointing downwards
+var arc = new Konva.Arc({
+  innerRadius: 40,
+  outerRadius: 80,
+  fill: 'red',
+  stroke: 'black'
+  strokeWidth: 5,
+  angle: 60,
+  rotationDeg: -120
+});
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

angle(angle)

+ + +
+
+ + +
+

get/set angle in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
angle + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get angle
+var angle = arc.angle();
+
+// set angle
+arc.angle(20);
+ + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clockwise(clockwise)

+ + +
+
+ + +
+

get/set clockwise flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
clockwise + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get clockwise flag
+var clockwise = arc.clockwise();
+
+// draw arc counter-clockwise
+arc.clockwise(false);
+
+// draw arc clockwise
+arc.clockwise(true);
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash array for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart
+ line.dash([10, 5]);
+ // apply dashed stroke that is made up of alternating dashed
+ // lines that are 10px long and 20px apart, and dots that have
+ // a radius of 5px and are 20px apart
+ line.dash([10, 20, 0.001, 20]);
+ + + +
+ + + +
+
+

dashEnabled(enabled)

+ + +
+
+ + +
+

get/set dash enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get dash enabled flag
+var dashEnabled = shape.dashEnabled();
+
+// disable dash
+shape.dashEnabled(false);
+
+// enable dash
+shape.dashEnabled(true);
+ + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

drawHitFromCache(alphaThreshold)

+ + +
+
+ + +
+

draw hit graph using the cached scene canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alphaThreshold + + +Integer + + + + +

alpha channel threshold that determines whether or not
+a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
+The default is 0

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
shape.cache();
+shape.drawHitFromCache();
+ + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

fill(color)

+ + +
+
+ + +
+

get/set fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill color
+var fill = shape.fill();
+
+// set fill color with color string
+shape.fill('green');
+
+// set fill color with hex
+shape.fill('#00ff00');
+
+// set fill color with rgb
+shape.fill('rgb(0,255,0)');
+
+// set fill color with rgba and make it 50% opaque
+shape.fill('rgba(0,255,0,0.5');
+
+// shape without fill
+shape.fill(null);
+ + + +
+ + + +
+
+

fillAfterStrokeEnabled(fillAfterStrokeEnabled)

+ + +
+
+ + +
+

get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
+In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
+Especially useful for Text objects.
+Default is false.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fillAfterStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
+
+// set stroke width
+shape.fillAfterStrokeEnabled(true);
+ + + +
+ + + +
+
+

fillEnabled(enabled)

+ + +
+
+ + +
+

get/set fill enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get fill enabled flag
+var fillEnabled = shape.fillEnabled();
+
+// disable fill
+shape.fillEnabled(false);
+
+// enable fill
+shape.fillEnabled(true);
+ + + +
+ + + +
+
+

fillLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient color stops
+var colorStops = shape.fillLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point
+var endPoint = shape.fillLinearGradientEndPoint();
+
+// set fill linear gradient end point
+shape.fillLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point x
+var endPointX = shape.fillLinearGradientEndPointX();
+
+// set fill linear gradient end point x
+shape.fillLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point y
+var endPointY = shape.fillLinearGradientEndPointY();
+
+// set fill linear gradient end point y
+shape.fillLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point
+var startPoint = shape.fillLinearGradientStartPoint();
+
+// set fill linear gradient start point
+shape.fillLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point x
+var startPointX = shape.fillLinearGradientStartPointX();
+
+// set fill linear gradient start point x
+shape.fillLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point y
+var startPointY = shape.fillLinearGradientStartPointY();
+
+// set fill linear gradient start point y
+shape.fillLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillPatternImage(image)

+ + +
+
+ + +
+

get/set fill pattern image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +

object

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get fill pattern image
+var fillPatternImage = shape.fillPatternImage();
+
+// set fill pattern image
+var imageObj = new Image();
+imageObj.onload = function() {
+  shape.fillPatternImage(imageObj);
+};
+imageObj.src = 'path/to/image/jpg';
+ + + +
+ + + +
+
+

fillPatternOffset(offset)

+ + +
+
+ + +
+

get/set fill pattern offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset
+var patternOffset = shape.fillPatternOffset();
+
+// set fill pattern offset
+shape.fillPatternOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillPatternOffsetX(x)

+ + +
+
+ + +
+

get/set fill pattern offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset x
+var patternOffsetX = shape.fillPatternOffsetX();
+
+// set fill pattern offset x
+shape.fillPatternOffsetX(20);
+ + + +
+ + + +
+
+

fillPatternOffsetY(y)

+ + +
+
+ + +
+

get/set fill pattern offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset y
+var patternOffsetY = shape.fillPatternOffsetY();
+
+// set fill pattern offset y
+shape.fillPatternOffsetY(10);
+ + + +
+ + + +
+
+

fillPatternRepeat(repeat)

+ + +
+
+ + +
+

get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
repeat + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill pattern repeat
+var repeat = shape.fillPatternRepeat();
+
+// repeat pattern in x direction only
+shape.fillPatternRepeat('repeat-x');
+
+// do not repeat the pattern
+shape.fillPatternRepeat('no-repeat');
+ + + +
+ + + +
+
+

fillPatternRotation(rotation)

+ + +
+
+ + +
+

get/set fill pattern rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill pattern rotation
+var patternRotation = shape.fillPatternRotation();
+
+// set fill pattern rotation
+shape.fillPatternRotation(20);
+ + + +
+ + + +
+
+

fillPatternScale(scale)

+ + +
+
+ + +
+

get/set fill pattern scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale
+var patternScale = shape.fillPatternScale();
+
+// set fill pattern scale
+shape.fillPatternScale({
+  x: 2,
+  y: 2
+});
+ + + +
+ + + +
+
+

fillPatternScaleX(x)

+ + +
+
+ + +
+

get/set fill pattern scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale x
+var patternScaleX = shape.fillPatternScaleX();
+
+// set fill pattern scale x
+shape.fillPatternScaleX(2);
+ + + +
+ + + +
+
+

fillPatternScaleY(y)

+ + +
+
+ + +
+

get/set fill pattern scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale y
+var patternScaleY = shape.fillPatternScaleY();
+
+// set fill pattern scale y
+shape.fillPatternScaleY(2);
+ + + +
+ + + +
+
+

fillPatternX(x)

+ + +
+
+ + +
+

get/set fill pattern x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern x
+var fillPatternX = shape.fillPatternX();
+// set fill pattern x
+shape.fillPatternX(20);
+ + + +
+ + + +
+
+

fillPatternY(y)

+ + +
+
+ + +
+

get/set fill pattern y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern y
+var fillPatternY = shape.fillPatternY();
+// set fill pattern y
+shape.fillPatternY(20);
+ + + +
+ + + +
+
+

fillPriority(priority)

+ + +
+
+ + +
+

get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
+This is handy if you want to toggle between different fill types.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
priority + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill priority
+var fillPriority = shape.fillPriority();
+
+// set fill priority
+shape.fillPriority('linear-gradient');
+ + + +
+ + + +
+
+

fillRadialGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill radial gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient color stops
+var colorStops = shape.fillRadialGradientColorStops();
+
+// create a radial gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillRadialGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill radial gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point
+var endPoint = shape.fillRadialGradientEndPoint();
+
+// set fill radial gradient end point
+shape.fillRadialGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point x
+var endPointX = shape.fillRadialGradientEndPointX();
+
+// set fill radial gradient end point x
+shape.fillRadialGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point y
+var endPointY = shape.fillRadialGradientEndPointY();
+
+// set fill radial gradient end point y
+shape.fillRadialGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient end radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient end radius
+var endRadius = shape.fillRadialGradientEndRadius();
+
+// set radial gradient end radius
+shape.fillRadialGradientEndRadius(100);
+ + + +
+ + + +
+
+

fillRadialGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill radial gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point
+var startPoint = shape.fillRadialGradientStartPoint();
+
+// set fill radial gradient start point
+shape.fillRadialGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point x
+var startPointX = shape.fillRadialGradientStartPointX();
+
+// set fill radial gradient start point x
+shape.fillRadialGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point y
+var startPointY = shape.fillRadialGradientStartPointY();
+
+// set fill radial gradient start point y
+shape.fillRadialGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient start radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient start radius
+var startRadius = shape.fillRadialGradientStartRadius();
+
+// set radial gradient start radius
+shape.fillRadialGradientStartRadius(0);
+ + + +
+ + + +
+
+

fillRule(rotation)

+ + +
+
+ + +
+

get/set fill rule

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +CanvasFillRule + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill rule
+var fillRule = shape.fillRule();
+
+// set fill rule
+shape.fillRule('evenodd');
+ + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getSelfRect()

+ + +
+
+ + +
+

return self rectangle (x, y, width, height) of shape.
+This method are not taken into account transformation and styles.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
rect.getSelfRect();  // return {x:0, y:0, width:rect.width(), height:rect.height()}
+circle.getSelfRect();  // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasFill()

+ + +
+
+ + +
+

returns whether or not the shape will be filled

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

hasShadow()

+ + +
+
+ + +
+

returns whether or not a shadow will be rendered

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasStroke()

+ + +
+
+ + +
+

returns whether or not the shape will be stroked

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitFunc(drawFunc)

+ + +
+
+ + +
+

get/set hit draw function. That function is used to draw custom hit area of a shape.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get hit draw function
+var hitFunc = shape.hitFunc();
+
+// set hit draw function
+shape.hitFunc(function(context) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

hitStrokeWidth(hitStrokeWidth)

+ + +
+
+ + +
+

get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var hitStrokeWidth = shape.hitStrokeWidth();
+
+// set hit stroke width
+shape.hitStrokeWidth(20);
+// set hit stroke width always equals to scene stroke width
+shape.hitStrokeWidth('auto');
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

innerRadius(innerRadius)

+ + +
+
+ + +
+

get/set innerRadius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
innerRadius + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get inner radius
+var innerRadius = arc.innerRadius();
+
+// set inner radius
+arc.innerRadius(20);
+ + + +
+ + + +
+
+

intersects(point)

+ + +
+
+ + +
+

determines if point is in the shape, regardless if other shapes are on top of it. Note: because
+this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
+consecutively. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

linearLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set stroke linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point x
+var startPointX = shape.strokeLinearGradientStartPointX();
+
+// set stroke linear gradient start point x
+shape.strokeLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

lineCap(lineCap)

+ + +
+
+ + +
+

get/set line cap. Can be butt, round, or square

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineCap + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line cap
+var lineCap = shape.lineCap();
+
+// set line cap
+shape.lineCap('round');
+ + + +
+ + + +
+
+

lineJoin(lineJoin)

+ + +
+
+ + +
+

get/set line join. Can be miter, round, or bevel. The
+default is miter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineJoin + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line join
+var lineJoin = shape.lineJoin();
+
+// set line join
+shape.lineJoin('round');
+ + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

outerRadius(outerRadius)

+ + +
+
+ + +
+

get/set outerRadius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
outerRadius + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get outer radius
+var outerRadius = arc.outerRadius();
+
+// set outer radius
+arc.outerRadius(20);
+ + + +
+ + + +
+
+

perfectDrawEnabled(perfectDrawEnabled)

+ + +
+
+ + +
+

get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set perfectDrawEnabled to false to improve performance.
+See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
perfectDrawEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get perfectDrawEnabled
+var perfectDrawEnabled = shape.perfectDrawEnabled();
+
+// set perfectDrawEnabled
+shape.perfectDrawEnabled();
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

sceneFunc(drawFunc)

+ + +
+
+ + +
+

get/set scene draw function. That function is used to draw the shape on a canvas.
+Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get scene draw function
+var sceneFunc = shape.sceneFunc();
+
+// set scene draw function
+shape.sceneFunc(function(context, shape) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  // like stroke and fill
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

shadowBlur(blur)

+ + +
+
+ + +
+

get/set shadow blur

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blur + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow blur
+var shadowBlur = shape.shadowBlur();
+
+// set shadow blur
+shape.shadowBlur(10);
+ + + +
+ + + +
+
+

shadowColor(color)

+ + +
+
+ + +
+

get/set shadow color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get shadow color
+var shadow = shape.shadowColor();
+
+// set shadow color with color string
+shape.shadowColor('green');
+
+// set shadow color with hex
+shape.shadowColor('#00ff00');
+
+// set shadow color with rgb
+shape.shadowColor('rgb(0,255,0)');
+
+// set shadow color with rgba and make it 50% opaque
+shape.shadowColor('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

shadowEnabled(enabled)

+ + +
+
+ + +
+

get/set shadow enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadow enabled flag
+var shadowEnabled = shape.shadowEnabled();
+
+// disable shadow
+shape.shadowEnabled(false);
+
+// enable shadow
+shape.shadowEnabled(true);
+ + + +
+ + + +
+
+

shadowForStrokeEnabled(shadowForStrokeEnabled)

+ + +
+
+ + +
+

get/set shadowForStrokeEnabled. Useful for performance optimization.
+You may set shape.shadowForStrokeEnabled(false). In this case stroke will no effect shadow.
+Remember if you set shadowForStrokeEnabled = false for non closed line - that line will have no shadow!.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shadowForStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadowForStrokeEnabled
+var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
+
+// set shadowForStrokeEnabled
+shape.shadowForStrokeEnabled();
+ + + +
+ + + +
+
+

shadowOffset(offset)

+ + +
+
+ + +
+

get/set shadow offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get shadow offset
+var shadowOffset = shape.shadowOffset();
+
+// set shadow offset
+shape.shadowOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

shadowOffsetX(x)

+ + +
+
+ + +
+

get/set shadow offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset x
+var shadowOffsetX = shape.shadowOffsetX();
+
+// set shadow offset x
+shape.shadowOffsetX(5);
+ + + +
+ + + +
+
+

shadowOffsetY(y)

+ + +
+
+ + +
+

get/set shadow offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset y
+var shadowOffsetY = shape.shadowOffsetY();
+
+// set shadow offset y
+shape.shadowOffsetY(5);
+ + + +
+ + + +
+
+

shadowOpacity(opacity)

+ + +
+
+ + +
+

get/set shadow opacity. must be a value between 0 and 1

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow opacity
+var shadowOpacity = shape.shadowOpacity();
+
+// set shadow opacity
+shape.shadowOpacity(0.5);
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke(color)

+ + +
+
+ + +
+

get/set stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get stroke color
+var stroke = shape.stroke();
+
+// set stroke color with color string
+shape.stroke('green');
+
+// set stroke color with hex
+shape.stroke('#00ff00');
+
+// set stroke color with rgb
+shape.stroke('rgb(0,255,0)');
+
+// set stroke color with rgba and make it 50% opaque
+shape.stroke('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

strokeEnabled(enabled)

+ + +
+
+ + +
+

get/set stroke enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke enabled flag
+var strokeEnabled = shape.strokeEnabled();
+
+// disable stroke
+shape.strokeEnabled(false);
+
+// enable stroke
+shape.strokeEnabled(true);
+ + + +
+ + + +
+
+

strokeHitEnabled(strokeHitEnabled)

+ + +
+
+ + +
+

deprecated, use hitStrokeWidth instead! get/set strokeHitEnabled property. Useful for performance optimization.
+You may set shape.strokeHitEnabled(false). In this case stroke will be no draw on hit canvas, so hit area
+of shape will be decreased (by lineWidth / 2). Remember that non closed line with strokeHitEnabled = false
+will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
+Default value is true.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeHitEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get strokeHitEnabled
+var strokeHitEnabled = shape.strokeHitEnabled();
+
+// set strokeHitEnabled
+shape.strokeHitEnabled();
+ + + +
+ + + +
+
+

strokeLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set stroke linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient color stops
+var colorStops = shape.strokeLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point
+var endPoint = shape.strokeLinearGradientEndPoint();
+
+// set stroke linear gradient end point
+shape.strokeLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point x
+var endPointX = shape.strokeLinearGradientEndPointX();
+
+// set stroke linear gradient end point x
+shape.strokeLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point y
+var endPointY = shape.strokeLinearGradientEndPointY();
+
+// set stroke linear gradient end point y
+shape.strokeLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

strokeLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point
+var startPoint = shape.strokeLinearGradientStartPoint();
+
+// set stroke linear gradient start point
+shape.strokeLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point y
+var startPointY = shape.strokeLinearGradientStartPointY();
+
+// set stroke linear gradient start point y
+shape.strokeLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

strokeScaleEnabled(enabled)

+ + +
+
+ + +
+

get/set strokeScale enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke scale enabled flag
+var strokeScaleEnabled = shape.strokeScaleEnabled();
+
+// disable stroke scale
+shape.strokeScaleEnabled(false);
+
+// enable stroke scale
+shape.strokeScaleEnabled(true);
+ + + +
+ + + +
+
+

strokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var strokeWidth = shape.strokeWidth();
+
+// set stroke width
+shape.strokeWidth(10);
+ + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Arrow.html b/api/Konva.Arrow.html new file mode 100644 index 000000000..e69d2a90c --- /dev/null +++ b/api/Konva.Arrow.html @@ -0,0 +1,35379 @@ + + + + + + + Konva Class: Arrow + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Arrow

+
+ +
+ +

+ Konva. + + Arrow +

+ +

Arrow constructor

+ + +
+ + +
+
+ + +
+
+

new Arrow(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
points + + +Array + + + + + + + + + + +

Flat array of points coordinates. You should define them as [x1, y1, x2, y2, x3, y3].

tension + + +Number + + + + + + + <optional>
+ + + + + +

Higher values will result in a more curvy line. A value of 0 will result in no interpolation.
+The default is 0

pointerLength + + +Number + + + + + + + + + + +

Arrow pointer length. Default value is 10.

pointerWidth + + +Number + + + + + + + + + + +

Arrow pointer width. Default value is 10.

pointerAtBeginning + + +Boolean + + + + + + + + + + +

Do we need to draw pointer on beginning position?. Default false.

pointerAtEnding + + +Boolean + + + + + + + + + + +

Do we need to draw pointer on ending position?. Default true.

fill + + +String + + + + + + + <optional>
+ + + + + +

fill color

fillPatternImage + + +Image + + + + + + + <optional>
+ + + + + +

fill pattern image

fillPatternX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScale + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternScaleX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScaleY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRotation + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRepeat + + +String + + + + + + + <optional>
+ + + + + +

can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"

fillLinearGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillRadialGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the fill. The default value is true

fillPriority + + +String + + + + + + + <optional>
+ + + + + +

can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration

stroke + + +String + + + + + + + <optional>
+ + + + + +

stroke color

strokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

stroke width

fillAfterStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw fill AFTER stroke? Default is false.

hitStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth

strokeHitEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke hit region. The default is true

perfectDrawEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables using buffer canvas. The default is true

shadowForStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables shadow for stroke. The default is true

strokeScaleEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke scale. The default is true

strokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the stroke. The default value is true

lineJoin + + +String + + + + + + + <optional>
+ + + + + +

can be miter, round, or bevel. The default
+is miter

lineCap + + +String + + + + + + + <optional>
+ + + + + +

can be butt, round, or square. The default
+is butt

shadowColor + + +String + + + + + + + <optional>
+ + + + + +
shadowBlur + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

shadowOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
shadowOpacity + + +Number + + + + + + + <optional>
+ + + + + +

shadow opacity. Can be any real number
+between 0 and 1

shadowEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the shadow. The default value is true

dash + + +Array + + + + + + + <optional>
+ + + + + +
dashEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the dashArray. The default value is true

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var line = new Konva.Line({
+  points: [73, 70, 340, 23, 450, 60, 500, 20],
+  stroke: 'red',
+  tension: 1,
+  pointerLength : 10,
+  pointerWidth : 12
+});
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

bezier(bezier)

+ + +
+
+ + +
+

get/set bezier flag. The default is false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bezier + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get whether the line is a bezier
+var isBezier = line.bezier();
+
+// set whether the line is a bezier
+line.bezier(true);
+ + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

closed(closed)

+ + +
+
+ + +
+

get/set closed flag. The default is false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
closed + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get closed flag
+var closed = line.closed();
+
+// close the shape
+line.closed(true);
+
+// open the shape
+line.closed(false);
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash array for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart
+ line.dash([10, 5]);
+ // apply dashed stroke that is made up of alternating dashed
+ // lines that are 10px long and 20px apart, and dots that have
+ // a radius of 5px and are 20px apart
+ line.dash([10, 20, 0.001, 20]);
+ + + +
+ + + +
+
+

dashEnabled(enabled)

+ + +
+
+ + +
+

get/set dash enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get dash enabled flag
+var dashEnabled = shape.dashEnabled();
+
+// disable dash
+shape.dashEnabled(false);
+
+// enable dash
+shape.dashEnabled(true);
+ + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

drawHitFromCache(alphaThreshold)

+ + +
+
+ + +
+

draw hit graph using the cached scene canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alphaThreshold + + +Integer + + + + +

alpha channel threshold that determines whether or not
+a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
+The default is 0

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
shape.cache();
+shape.drawHitFromCache();
+ + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

fill(color)

+ + +
+
+ + +
+

get/set fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill color
+var fill = shape.fill();
+
+// set fill color with color string
+shape.fill('green');
+
+// set fill color with hex
+shape.fill('#00ff00');
+
+// set fill color with rgb
+shape.fill('rgb(0,255,0)');
+
+// set fill color with rgba and make it 50% opaque
+shape.fill('rgba(0,255,0,0.5');
+
+// shape without fill
+shape.fill(null);
+ + + +
+ + + +
+
+

fillAfterStrokeEnabled(fillAfterStrokeEnabled)

+ + +
+
+ + +
+

get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
+In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
+Especially useful for Text objects.
+Default is false.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fillAfterStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
+
+// set stroke width
+shape.fillAfterStrokeEnabled(true);
+ + + +
+ + + +
+
+

fillEnabled(enabled)

+ + +
+
+ + +
+

get/set fill enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get fill enabled flag
+var fillEnabled = shape.fillEnabled();
+
+// disable fill
+shape.fillEnabled(false);
+
+// enable fill
+shape.fillEnabled(true);
+ + + +
+ + + +
+
+

fillLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient color stops
+var colorStops = shape.fillLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point
+var endPoint = shape.fillLinearGradientEndPoint();
+
+// set fill linear gradient end point
+shape.fillLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point x
+var endPointX = shape.fillLinearGradientEndPointX();
+
+// set fill linear gradient end point x
+shape.fillLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point y
+var endPointY = shape.fillLinearGradientEndPointY();
+
+// set fill linear gradient end point y
+shape.fillLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point
+var startPoint = shape.fillLinearGradientStartPoint();
+
+// set fill linear gradient start point
+shape.fillLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point x
+var startPointX = shape.fillLinearGradientStartPointX();
+
+// set fill linear gradient start point x
+shape.fillLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point y
+var startPointY = shape.fillLinearGradientStartPointY();
+
+// set fill linear gradient start point y
+shape.fillLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillPatternImage(image)

+ + +
+
+ + +
+

get/set fill pattern image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +

object

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get fill pattern image
+var fillPatternImage = shape.fillPatternImage();
+
+// set fill pattern image
+var imageObj = new Image();
+imageObj.onload = function() {
+  shape.fillPatternImage(imageObj);
+};
+imageObj.src = 'path/to/image/jpg';
+ + + +
+ + + +
+
+

fillPatternOffset(offset)

+ + +
+
+ + +
+

get/set fill pattern offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset
+var patternOffset = shape.fillPatternOffset();
+
+// set fill pattern offset
+shape.fillPatternOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillPatternOffsetX(x)

+ + +
+
+ + +
+

get/set fill pattern offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset x
+var patternOffsetX = shape.fillPatternOffsetX();
+
+// set fill pattern offset x
+shape.fillPatternOffsetX(20);
+ + + +
+ + + +
+
+

fillPatternOffsetY(y)

+ + +
+
+ + +
+

get/set fill pattern offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset y
+var patternOffsetY = shape.fillPatternOffsetY();
+
+// set fill pattern offset y
+shape.fillPatternOffsetY(10);
+ + + +
+ + + +
+
+

fillPatternRepeat(repeat)

+ + +
+
+ + +
+

get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
repeat + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill pattern repeat
+var repeat = shape.fillPatternRepeat();
+
+// repeat pattern in x direction only
+shape.fillPatternRepeat('repeat-x');
+
+// do not repeat the pattern
+shape.fillPatternRepeat('no-repeat');
+ + + +
+ + + +
+
+

fillPatternRotation(rotation)

+ + +
+
+ + +
+

get/set fill pattern rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill pattern rotation
+var patternRotation = shape.fillPatternRotation();
+
+// set fill pattern rotation
+shape.fillPatternRotation(20);
+ + + +
+ + + +
+
+

fillPatternScale(scale)

+ + +
+
+ + +
+

get/set fill pattern scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale
+var patternScale = shape.fillPatternScale();
+
+// set fill pattern scale
+shape.fillPatternScale({
+  x: 2,
+  y: 2
+});
+ + + +
+ + + +
+
+

fillPatternScaleX(x)

+ + +
+
+ + +
+

get/set fill pattern scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale x
+var patternScaleX = shape.fillPatternScaleX();
+
+// set fill pattern scale x
+shape.fillPatternScaleX(2);
+ + + +
+ + + +
+
+

fillPatternScaleY(y)

+ + +
+
+ + +
+

get/set fill pattern scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale y
+var patternScaleY = shape.fillPatternScaleY();
+
+// set fill pattern scale y
+shape.fillPatternScaleY(2);
+ + + +
+ + + +
+
+

fillPatternX(x)

+ + +
+
+ + +
+

get/set fill pattern x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern x
+var fillPatternX = shape.fillPatternX();
+// set fill pattern x
+shape.fillPatternX(20);
+ + + +
+ + + +
+
+

fillPatternY(y)

+ + +
+
+ + +
+

get/set fill pattern y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern y
+var fillPatternY = shape.fillPatternY();
+// set fill pattern y
+shape.fillPatternY(20);
+ + + +
+ + + +
+
+

fillPriority(priority)

+ + +
+
+ + +
+

get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
+This is handy if you want to toggle between different fill types.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
priority + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill priority
+var fillPriority = shape.fillPriority();
+
+// set fill priority
+shape.fillPriority('linear-gradient');
+ + + +
+ + + +
+
+

fillRadialGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill radial gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient color stops
+var colorStops = shape.fillRadialGradientColorStops();
+
+// create a radial gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillRadialGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill radial gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point
+var endPoint = shape.fillRadialGradientEndPoint();
+
+// set fill radial gradient end point
+shape.fillRadialGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point x
+var endPointX = shape.fillRadialGradientEndPointX();
+
+// set fill radial gradient end point x
+shape.fillRadialGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point y
+var endPointY = shape.fillRadialGradientEndPointY();
+
+// set fill radial gradient end point y
+shape.fillRadialGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient end radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient end radius
+var endRadius = shape.fillRadialGradientEndRadius();
+
+// set radial gradient end radius
+shape.fillRadialGradientEndRadius(100);
+ + + +
+ + + +
+
+

fillRadialGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill radial gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point
+var startPoint = shape.fillRadialGradientStartPoint();
+
+// set fill radial gradient start point
+shape.fillRadialGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point x
+var startPointX = shape.fillRadialGradientStartPointX();
+
+// set fill radial gradient start point x
+shape.fillRadialGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point y
+var startPointY = shape.fillRadialGradientStartPointY();
+
+// set fill radial gradient start point y
+shape.fillRadialGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient start radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient start radius
+var startRadius = shape.fillRadialGradientStartRadius();
+
+// set radial gradient start radius
+shape.fillRadialGradientStartRadius(0);
+ + + +
+ + + +
+
+

fillRule(rotation)

+ + +
+
+ + +
+

get/set fill rule

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +CanvasFillRule + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill rule
+var fillRule = shape.fillRule();
+
+// set fill rule
+shape.fillRule('evenodd');
+ + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getSelfRect()

+ + +
+
+ + +
+

return self rectangle (x, y, width, height) of shape.
+This method are not taken into account transformation and styles.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
rect.getSelfRect();  // return {x:0, y:0, width:rect.width(), height:rect.height()}
+circle.getSelfRect();  // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasFill()

+ + +
+
+ + +
+

returns whether or not the shape will be filled

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

hasShadow()

+ + +
+
+ + +
+

returns whether or not a shadow will be rendered

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasStroke()

+ + +
+
+ + +
+

returns whether or not the shape will be stroked

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitFunc(drawFunc)

+ + +
+
+ + +
+

get/set hit draw function. That function is used to draw custom hit area of a shape.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get hit draw function
+var hitFunc = shape.hitFunc();
+
+// set hit draw function
+shape.hitFunc(function(context) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

hitStrokeWidth(hitStrokeWidth)

+ + +
+
+ + +
+

get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var hitStrokeWidth = shape.hitStrokeWidth();
+
+// set hit stroke width
+shape.hitStrokeWidth(20);
+// set hit stroke width always equals to scene stroke width
+shape.hitStrokeWidth('auto');
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

intersects(point)

+ + +
+
+ + +
+

determines if point is in the shape, regardless if other shapes are on top of it. Note: because
+this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
+consecutively. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

linearLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set stroke linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point x
+var startPointX = shape.strokeLinearGradientStartPointX();
+
+// set stroke linear gradient start point x
+shape.strokeLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

lineCap(lineCap)

+ + +
+
+ + +
+

get/set line cap. Can be butt, round, or square

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineCap + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line cap
+var lineCap = shape.lineCap();
+
+// set line cap
+shape.lineCap('round');
+ + + +
+ + + +
+
+

lineJoin(lineJoin)

+ + +
+
+ + +
+

get/set line join. Can be miter, round, or bevel. The
+default is miter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineJoin + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line join
+var lineJoin = shape.lineJoin();
+
+// set line join
+shape.lineJoin('round');
+ + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

perfectDrawEnabled(perfectDrawEnabled)

+ + +
+
+ + +
+

get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set perfectDrawEnabled to false to improve performance.
+See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
perfectDrawEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get perfectDrawEnabled
+var perfectDrawEnabled = shape.perfectDrawEnabled();
+
+// set perfectDrawEnabled
+shape.perfectDrawEnabled();
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

pointerAtBeginning(Should)

+ + +
+
+ + +
+

get/set pointerAtBeginning

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Should + + +Number + + + + +

pointer displayed at beginning of arrow. The default is false.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get value
+var pointerAtBeginning = line.pointerAtBeginning();
+
+// set value
+line.pointerAtBeginning(true);
+ + + +
+ + + +
+
+

pointerAtEnding(Should)

+ + +
+
+ + +
+

get/set pointerAtEnding

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Should + + +Number + + + + +

pointer displayed at ending of arrow. The default is true.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get value
+var pointerAtEnding = line.pointerAtEnding();
+
+// set value
+line.pointerAtEnding(false);
+ + + +
+ + + +
+
+

pointerLength(Length)

+ + +
+
+ + +
+

get/set pointerLength

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Length + + +Number + + + + +

of pointer of arrow. The default is 10.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get length
+var pointerLength = line.pointerLength();
+
+// set length
+line.pointerLength(15);
+ + + +
+ + + +
+
+

pointerWidth(Width)

+ + +
+
+ + +
+

get/set pointerWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Width + + +Number + + + + +

of pointer of arrow.
+The default is 10.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var pointerWidth = line.pointerWidth();
+
+// set width
+line.pointerWidth(15);
+ + + +
+ + + +
+
+

points(points)

+ + +
+
+ + +
+

get/set points array. Points is a flat array [x1, y1, x2, y2]. It is flat for performance reasons.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
points + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get points
+var points = line.points();
+
+// set points
+line.points([10, 20, 30, 40, 50, 60]);
+
+// push a new point
+line.points(line.points().concat([70, 80]));
+ + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

sceneFunc(drawFunc)

+ + +
+
+ + +
+

get/set scene draw function. That function is used to draw the shape on a canvas.
+Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get scene draw function
+var sceneFunc = shape.sceneFunc();
+
+// set scene draw function
+shape.sceneFunc(function(context, shape) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  // like stroke and fill
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

shadowBlur(blur)

+ + +
+
+ + +
+

get/set shadow blur

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blur + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow blur
+var shadowBlur = shape.shadowBlur();
+
+// set shadow blur
+shape.shadowBlur(10);
+ + + +
+ + + +
+
+

shadowColor(color)

+ + +
+
+ + +
+

get/set shadow color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get shadow color
+var shadow = shape.shadowColor();
+
+// set shadow color with color string
+shape.shadowColor('green');
+
+// set shadow color with hex
+shape.shadowColor('#00ff00');
+
+// set shadow color with rgb
+shape.shadowColor('rgb(0,255,0)');
+
+// set shadow color with rgba and make it 50% opaque
+shape.shadowColor('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

shadowEnabled(enabled)

+ + +
+
+ + +
+

get/set shadow enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadow enabled flag
+var shadowEnabled = shape.shadowEnabled();
+
+// disable shadow
+shape.shadowEnabled(false);
+
+// enable shadow
+shape.shadowEnabled(true);
+ + + +
+ + + +
+
+

shadowForStrokeEnabled(shadowForStrokeEnabled)

+ + +
+
+ + +
+

get/set shadowForStrokeEnabled. Useful for performance optimization.
+You may set shape.shadowForStrokeEnabled(false). In this case stroke will no effect shadow.
+Remember if you set shadowForStrokeEnabled = false for non closed line - that line will have no shadow!.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shadowForStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadowForStrokeEnabled
+var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
+
+// set shadowForStrokeEnabled
+shape.shadowForStrokeEnabled();
+ + + +
+ + + +
+
+

shadowOffset(offset)

+ + +
+
+ + +
+

get/set shadow offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get shadow offset
+var shadowOffset = shape.shadowOffset();
+
+// set shadow offset
+shape.shadowOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

shadowOffsetX(x)

+ + +
+
+ + +
+

get/set shadow offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset x
+var shadowOffsetX = shape.shadowOffsetX();
+
+// set shadow offset x
+shape.shadowOffsetX(5);
+ + + +
+ + + +
+
+

shadowOffsetY(y)

+ + +
+
+ + +
+

get/set shadow offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset y
+var shadowOffsetY = shape.shadowOffsetY();
+
+// set shadow offset y
+shape.shadowOffsetY(5);
+ + + +
+ + + +
+
+

shadowOpacity(opacity)

+ + +
+
+ + +
+

get/set shadow opacity. must be a value between 0 and 1

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow opacity
+var shadowOpacity = shape.shadowOpacity();
+
+// set shadow opacity
+shape.shadowOpacity(0.5);
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke(color)

+ + +
+
+ + +
+

get/set stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get stroke color
+var stroke = shape.stroke();
+
+// set stroke color with color string
+shape.stroke('green');
+
+// set stroke color with hex
+shape.stroke('#00ff00');
+
+// set stroke color with rgb
+shape.stroke('rgb(0,255,0)');
+
+// set stroke color with rgba and make it 50% opaque
+shape.stroke('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

strokeEnabled(enabled)

+ + +
+
+ + +
+

get/set stroke enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke enabled flag
+var strokeEnabled = shape.strokeEnabled();
+
+// disable stroke
+shape.strokeEnabled(false);
+
+// enable stroke
+shape.strokeEnabled(true);
+ + + +
+ + + +
+
+

strokeHitEnabled(strokeHitEnabled)

+ + +
+
+ + +
+

deprecated, use hitStrokeWidth instead! get/set strokeHitEnabled property. Useful for performance optimization.
+You may set shape.strokeHitEnabled(false). In this case stroke will be no draw on hit canvas, so hit area
+of shape will be decreased (by lineWidth / 2). Remember that non closed line with strokeHitEnabled = false
+will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
+Default value is true.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeHitEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get strokeHitEnabled
+var strokeHitEnabled = shape.strokeHitEnabled();
+
+// set strokeHitEnabled
+shape.strokeHitEnabled();
+ + + +
+ + + +
+
+

strokeLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set stroke linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient color stops
+var colorStops = shape.strokeLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point
+var endPoint = shape.strokeLinearGradientEndPoint();
+
+// set stroke linear gradient end point
+shape.strokeLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point x
+var endPointX = shape.strokeLinearGradientEndPointX();
+
+// set stroke linear gradient end point x
+shape.strokeLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point y
+var endPointY = shape.strokeLinearGradientEndPointY();
+
+// set stroke linear gradient end point y
+shape.strokeLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

strokeLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point
+var startPoint = shape.strokeLinearGradientStartPoint();
+
+// set stroke linear gradient start point
+shape.strokeLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point y
+var startPointY = shape.strokeLinearGradientStartPointY();
+
+// set stroke linear gradient start point y
+shape.strokeLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

strokeScaleEnabled(enabled)

+ + +
+
+ + +
+

get/set strokeScale enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke scale enabled flag
+var strokeScaleEnabled = shape.strokeScaleEnabled();
+
+// disable stroke scale
+shape.strokeScaleEnabled(false);
+
+// enable stroke scale
+shape.strokeScaleEnabled(true);
+ + + +
+ + + +
+
+

strokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var strokeWidth = shape.strokeWidth();
+
+// set stroke width
+shape.strokeWidth(10);
+ + + +
+ + + +
+
+

tension(tension)

+ + +
+
+ + +
+

get/set tension

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tension + + +Number + + + + +

Higher values will result in a more curvy line. A value of 0 will result in no interpolation. The default is 0

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get tension
+var tension = line.tension();
+
+// set tension
+line.tension(3);
+ + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Canvas.html b/api/Konva.Canvas.html new file mode 100644 index 000000000..37f7f60c7 --- /dev/null +++ b/api/Konva.Canvas.html @@ -0,0 +1,1021 @@ + + + + + + + Konva Class: Canvas + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Canvas

+
+ +
+ +

+ Konva~ + + Canvas +

+ +

Canvas Renderer constructor. It is a wrapper around native canvas element.
+Usually you don't need to use it manually.

+ + +
+ + +
+
+ + +
+
+

<abstract> new Canvas(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
pixelRatio + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + +
+ + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

getContext()

+ + +
+
+ + +
+

get canvas context

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

context

+
+ + + +
+
+ Type +
+
+ +CanvasContext + + + +
+
+ + + + + +
+ + + +
+
+

pixelRatio(pixelRatio)

+ + +
+
+ + +
+

get/set pixel ratio.
+KonvaJS automatically handles pixel ratio adustments in order to render crisp drawings
+on all devices. Most desktops, low end tablets, and low end phones, have device pixel ratios
+of 1. Some high end tablets and phones, like iPhones and iPads have a device pixel ratio
+of 2. Some Macbook Pros, and iMacs also have a device pixel ratio of 2. Some high end Android devices have pixel
+ratios of 2 or 3. Some browsers like Firefox allow you to configure the pixel ratio of the viewport. Unless otherwise
+specificed, the pixel ratio will be defaulted to the actual device pixel ratio. You can override the device pixel
+ratio for special situations, or, if you don't want the pixel ratio to be taken into account, you can set it to 1.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelRatio + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get
+var pixelRatio = layer.getCanvas.pixelRatio();
+
+// set
+layer.getCanvas().pixelRatio(3);
+ + + +
+ + + +
+
+

toDataURL(mimeType, quality)

+ + +
+
+ + +
+

to data url

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
mimeType + + +String + + + + +
quality + + +Number + + + + +

between 0 and 1 for jpg mime types

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

data url string

+
+ + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Circle.html b/api/Konva.Circle.html new file mode 100644 index 000000000..d09e5a650 --- /dev/null +++ b/api/Konva.Circle.html @@ -0,0 +1,34032 @@ + + + + + + + Konva Class: Circle + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Circle

+
+ +
+ +

+ Konva. + + Circle +

+ +

Circle constructor

+ + +
+ + +
+
+ + +
+
+

new Circle(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
radius + + +Number + + + + + + + + + + +
fill + + +String + + + + + + + <optional>
+ + + + + +

fill color

fillPatternImage + + +Image + + + + + + + <optional>
+ + + + + +

fill pattern image

fillPatternX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScale + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternScaleX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScaleY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRotation + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRepeat + + +String + + + + + + + <optional>
+ + + + + +

can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"

fillLinearGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillRadialGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the fill. The default value is true

fillPriority + + +String + + + + + + + <optional>
+ + + + + +

can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration

stroke + + +String + + + + + + + <optional>
+ + + + + +

stroke color

strokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

stroke width

fillAfterStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw fill AFTER stroke? Default is false.

hitStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth

strokeHitEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke hit region. The default is true

perfectDrawEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables using buffer canvas. The default is true

shadowForStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables shadow for stroke. The default is true

strokeScaleEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke scale. The default is true

strokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the stroke. The default value is true

lineJoin + + +String + + + + + + + <optional>
+ + + + + +

can be miter, round, or bevel. The default
+is miter

lineCap + + +String + + + + + + + <optional>
+ + + + + +

can be butt, round, or square. The default
+is butt

shadowColor + + +String + + + + + + + <optional>
+ + + + + +
shadowBlur + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

shadowOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
shadowOpacity + + +Number + + + + + + + <optional>
+ + + + + +

shadow opacity. Can be any real number
+between 0 and 1

shadowEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the shadow. The default value is true

dash + + +Array + + + + + + + <optional>
+ + + + + +
dashEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the dashArray. The default value is true

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
// create circle
+var circle = new Konva.Circle({
+  radius: 40,
+  fill: 'red',
+  stroke: 'black',
+  strokeWidth: 5
+});
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash array for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart
+ line.dash([10, 5]);
+ // apply dashed stroke that is made up of alternating dashed
+ // lines that are 10px long and 20px apart, and dots that have
+ // a radius of 5px and are 20px apart
+ line.dash([10, 20, 0.001, 20]);
+ + + +
+ + + +
+
+

dashEnabled(enabled)

+ + +
+
+ + +
+

get/set dash enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get dash enabled flag
+var dashEnabled = shape.dashEnabled();
+
+// disable dash
+shape.dashEnabled(false);
+
+// enable dash
+shape.dashEnabled(true);
+ + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

drawHitFromCache(alphaThreshold)

+ + +
+
+ + +
+

draw hit graph using the cached scene canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alphaThreshold + + +Integer + + + + +

alpha channel threshold that determines whether or not
+a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
+The default is 0

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
shape.cache();
+shape.drawHitFromCache();
+ + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

fill(color)

+ + +
+
+ + +
+

get/set fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill color
+var fill = shape.fill();
+
+// set fill color with color string
+shape.fill('green');
+
+// set fill color with hex
+shape.fill('#00ff00');
+
+// set fill color with rgb
+shape.fill('rgb(0,255,0)');
+
+// set fill color with rgba and make it 50% opaque
+shape.fill('rgba(0,255,0,0.5');
+
+// shape without fill
+shape.fill(null);
+ + + +
+ + + +
+
+

fillAfterStrokeEnabled(fillAfterStrokeEnabled)

+ + +
+
+ + +
+

get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
+In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
+Especially useful for Text objects.
+Default is false.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fillAfterStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
+
+// set stroke width
+shape.fillAfterStrokeEnabled(true);
+ + + +
+ + + +
+
+

fillEnabled(enabled)

+ + +
+
+ + +
+

get/set fill enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get fill enabled flag
+var fillEnabled = shape.fillEnabled();
+
+// disable fill
+shape.fillEnabled(false);
+
+// enable fill
+shape.fillEnabled(true);
+ + + +
+ + + +
+
+

fillLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient color stops
+var colorStops = shape.fillLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point
+var endPoint = shape.fillLinearGradientEndPoint();
+
+// set fill linear gradient end point
+shape.fillLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point x
+var endPointX = shape.fillLinearGradientEndPointX();
+
+// set fill linear gradient end point x
+shape.fillLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point y
+var endPointY = shape.fillLinearGradientEndPointY();
+
+// set fill linear gradient end point y
+shape.fillLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point
+var startPoint = shape.fillLinearGradientStartPoint();
+
+// set fill linear gradient start point
+shape.fillLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point x
+var startPointX = shape.fillLinearGradientStartPointX();
+
+// set fill linear gradient start point x
+shape.fillLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point y
+var startPointY = shape.fillLinearGradientStartPointY();
+
+// set fill linear gradient start point y
+shape.fillLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillPatternImage(image)

+ + +
+
+ + +
+

get/set fill pattern image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +

object

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get fill pattern image
+var fillPatternImage = shape.fillPatternImage();
+
+// set fill pattern image
+var imageObj = new Image();
+imageObj.onload = function() {
+  shape.fillPatternImage(imageObj);
+};
+imageObj.src = 'path/to/image/jpg';
+ + + +
+ + + +
+
+

fillPatternOffset(offset)

+ + +
+
+ + +
+

get/set fill pattern offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset
+var patternOffset = shape.fillPatternOffset();
+
+// set fill pattern offset
+shape.fillPatternOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillPatternOffsetX(x)

+ + +
+
+ + +
+

get/set fill pattern offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset x
+var patternOffsetX = shape.fillPatternOffsetX();
+
+// set fill pattern offset x
+shape.fillPatternOffsetX(20);
+ + + +
+ + + +
+
+

fillPatternOffsetY(y)

+ + +
+
+ + +
+

get/set fill pattern offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset y
+var patternOffsetY = shape.fillPatternOffsetY();
+
+// set fill pattern offset y
+shape.fillPatternOffsetY(10);
+ + + +
+ + + +
+
+

fillPatternRepeat(repeat)

+ + +
+
+ + +
+

get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
repeat + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill pattern repeat
+var repeat = shape.fillPatternRepeat();
+
+// repeat pattern in x direction only
+shape.fillPatternRepeat('repeat-x');
+
+// do not repeat the pattern
+shape.fillPatternRepeat('no-repeat');
+ + + +
+ + + +
+
+

fillPatternRotation(rotation)

+ + +
+
+ + +
+

get/set fill pattern rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill pattern rotation
+var patternRotation = shape.fillPatternRotation();
+
+// set fill pattern rotation
+shape.fillPatternRotation(20);
+ + + +
+ + + +
+
+

fillPatternScale(scale)

+ + +
+
+ + +
+

get/set fill pattern scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale
+var patternScale = shape.fillPatternScale();
+
+// set fill pattern scale
+shape.fillPatternScale({
+  x: 2,
+  y: 2
+});
+ + + +
+ + + +
+
+

fillPatternScaleX(x)

+ + +
+
+ + +
+

get/set fill pattern scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale x
+var patternScaleX = shape.fillPatternScaleX();
+
+// set fill pattern scale x
+shape.fillPatternScaleX(2);
+ + + +
+ + + +
+
+

fillPatternScaleY(y)

+ + +
+
+ + +
+

get/set fill pattern scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale y
+var patternScaleY = shape.fillPatternScaleY();
+
+// set fill pattern scale y
+shape.fillPatternScaleY(2);
+ + + +
+ + + +
+
+

fillPatternX(x)

+ + +
+
+ + +
+

get/set fill pattern x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern x
+var fillPatternX = shape.fillPatternX();
+// set fill pattern x
+shape.fillPatternX(20);
+ + + +
+ + + +
+
+

fillPatternY(y)

+ + +
+
+ + +
+

get/set fill pattern y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern y
+var fillPatternY = shape.fillPatternY();
+// set fill pattern y
+shape.fillPatternY(20);
+ + + +
+ + + +
+
+

fillPriority(priority)

+ + +
+
+ + +
+

get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
+This is handy if you want to toggle between different fill types.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
priority + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill priority
+var fillPriority = shape.fillPriority();
+
+// set fill priority
+shape.fillPriority('linear-gradient');
+ + + +
+ + + +
+
+

fillRadialGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill radial gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient color stops
+var colorStops = shape.fillRadialGradientColorStops();
+
+// create a radial gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillRadialGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill radial gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point
+var endPoint = shape.fillRadialGradientEndPoint();
+
+// set fill radial gradient end point
+shape.fillRadialGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point x
+var endPointX = shape.fillRadialGradientEndPointX();
+
+// set fill radial gradient end point x
+shape.fillRadialGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point y
+var endPointY = shape.fillRadialGradientEndPointY();
+
+// set fill radial gradient end point y
+shape.fillRadialGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient end radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient end radius
+var endRadius = shape.fillRadialGradientEndRadius();
+
+// set radial gradient end radius
+shape.fillRadialGradientEndRadius(100);
+ + + +
+ + + +
+
+

fillRadialGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill radial gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point
+var startPoint = shape.fillRadialGradientStartPoint();
+
+// set fill radial gradient start point
+shape.fillRadialGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point x
+var startPointX = shape.fillRadialGradientStartPointX();
+
+// set fill radial gradient start point x
+shape.fillRadialGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point y
+var startPointY = shape.fillRadialGradientStartPointY();
+
+// set fill radial gradient start point y
+shape.fillRadialGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient start radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient start radius
+var startRadius = shape.fillRadialGradientStartRadius();
+
+// set radial gradient start radius
+shape.fillRadialGradientStartRadius(0);
+ + + +
+ + + +
+
+

fillRule(rotation)

+ + +
+
+ + +
+

get/set fill rule

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +CanvasFillRule + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill rule
+var fillRule = shape.fillRule();
+
+// set fill rule
+shape.fillRule('evenodd');
+ + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getSelfRect()

+ + +
+
+ + +
+

return self rectangle (x, y, width, height) of shape.
+This method are not taken into account transformation and styles.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
rect.getSelfRect();  // return {x:0, y:0, width:rect.width(), height:rect.height()}
+circle.getSelfRect();  // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasFill()

+ + +
+
+ + +
+

returns whether or not the shape will be filled

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

hasShadow()

+ + +
+
+ + +
+

returns whether or not a shadow will be rendered

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasStroke()

+ + +
+
+ + +
+

returns whether or not the shape will be stroked

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitFunc(drawFunc)

+ + +
+
+ + +
+

get/set hit draw function. That function is used to draw custom hit area of a shape.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get hit draw function
+var hitFunc = shape.hitFunc();
+
+// set hit draw function
+shape.hitFunc(function(context) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

hitStrokeWidth(hitStrokeWidth)

+ + +
+
+ + +
+

get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var hitStrokeWidth = shape.hitStrokeWidth();
+
+// set hit stroke width
+shape.hitStrokeWidth(20);
+// set hit stroke width always equals to scene stroke width
+shape.hitStrokeWidth('auto');
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

intersects(point)

+ + +
+
+ + +
+

determines if point is in the shape, regardless if other shapes are on top of it. Note: because
+this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
+consecutively. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

linearLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set stroke linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point x
+var startPointX = shape.strokeLinearGradientStartPointX();
+
+// set stroke linear gradient start point x
+shape.strokeLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

lineCap(lineCap)

+ + +
+
+ + +
+

get/set line cap. Can be butt, round, or square

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineCap + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line cap
+var lineCap = shape.lineCap();
+
+// set line cap
+shape.lineCap('round');
+ + + +
+ + + +
+
+

lineJoin(lineJoin)

+ + +
+
+ + +
+

get/set line join. Can be miter, round, or bevel. The
+default is miter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineJoin + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line join
+var lineJoin = shape.lineJoin();
+
+// set line join
+shape.lineJoin('round');
+ + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

perfectDrawEnabled(perfectDrawEnabled)

+ + +
+
+ + +
+

get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set perfectDrawEnabled to false to improve performance.
+See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
perfectDrawEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get perfectDrawEnabled
+var perfectDrawEnabled = shape.perfectDrawEnabled();
+
+// set perfectDrawEnabled
+shape.perfectDrawEnabled();
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

radius(radius)

+ + +
+
+ + +
+

get/set radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radius
+var radius = circle.radius();
+
+// set radius
+circle.radius(10);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

sceneFunc(drawFunc)

+ + +
+
+ + +
+

get/set scene draw function. That function is used to draw the shape on a canvas.
+Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get scene draw function
+var sceneFunc = shape.sceneFunc();
+
+// set scene draw function
+shape.sceneFunc(function(context, shape) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  // like stroke and fill
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

shadowBlur(blur)

+ + +
+
+ + +
+

get/set shadow blur

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blur + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow blur
+var shadowBlur = shape.shadowBlur();
+
+// set shadow blur
+shape.shadowBlur(10);
+ + + +
+ + + +
+
+

shadowColor(color)

+ + +
+
+ + +
+

get/set shadow color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get shadow color
+var shadow = shape.shadowColor();
+
+// set shadow color with color string
+shape.shadowColor('green');
+
+// set shadow color with hex
+shape.shadowColor('#00ff00');
+
+// set shadow color with rgb
+shape.shadowColor('rgb(0,255,0)');
+
+// set shadow color with rgba and make it 50% opaque
+shape.shadowColor('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

shadowEnabled(enabled)

+ + +
+
+ + +
+

get/set shadow enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadow enabled flag
+var shadowEnabled = shape.shadowEnabled();
+
+// disable shadow
+shape.shadowEnabled(false);
+
+// enable shadow
+shape.shadowEnabled(true);
+ + + +
+ + + +
+
+

shadowForStrokeEnabled(shadowForStrokeEnabled)

+ + +
+
+ + +
+

get/set shadowForStrokeEnabled. Useful for performance optimization.
+You may set shape.shadowForStrokeEnabled(false). In this case stroke will no effect shadow.
+Remember if you set shadowForStrokeEnabled = false for non closed line - that line will have no shadow!.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shadowForStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadowForStrokeEnabled
+var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
+
+// set shadowForStrokeEnabled
+shape.shadowForStrokeEnabled();
+ + + +
+ + + +
+
+

shadowOffset(offset)

+ + +
+
+ + +
+

get/set shadow offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get shadow offset
+var shadowOffset = shape.shadowOffset();
+
+// set shadow offset
+shape.shadowOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

shadowOffsetX(x)

+ + +
+
+ + +
+

get/set shadow offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset x
+var shadowOffsetX = shape.shadowOffsetX();
+
+// set shadow offset x
+shape.shadowOffsetX(5);
+ + + +
+ + + +
+
+

shadowOffsetY(y)

+ + +
+
+ + +
+

get/set shadow offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset y
+var shadowOffsetY = shape.shadowOffsetY();
+
+// set shadow offset y
+shape.shadowOffsetY(5);
+ + + +
+ + + +
+
+

shadowOpacity(opacity)

+ + +
+
+ + +
+

get/set shadow opacity. must be a value between 0 and 1

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow opacity
+var shadowOpacity = shape.shadowOpacity();
+
+// set shadow opacity
+shape.shadowOpacity(0.5);
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke(color)

+ + +
+
+ + +
+

get/set stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get stroke color
+var stroke = shape.stroke();
+
+// set stroke color with color string
+shape.stroke('green');
+
+// set stroke color with hex
+shape.stroke('#00ff00');
+
+// set stroke color with rgb
+shape.stroke('rgb(0,255,0)');
+
+// set stroke color with rgba and make it 50% opaque
+shape.stroke('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

strokeEnabled(enabled)

+ + +
+
+ + +
+

get/set stroke enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke enabled flag
+var strokeEnabled = shape.strokeEnabled();
+
+// disable stroke
+shape.strokeEnabled(false);
+
+// enable stroke
+shape.strokeEnabled(true);
+ + + +
+ + + +
+
+

strokeHitEnabled(strokeHitEnabled)

+ + +
+
+ + +
+

deprecated, use hitStrokeWidth instead! get/set strokeHitEnabled property. Useful for performance optimization.
+You may set shape.strokeHitEnabled(false). In this case stroke will be no draw on hit canvas, so hit area
+of shape will be decreased (by lineWidth / 2). Remember that non closed line with strokeHitEnabled = false
+will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
+Default value is true.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeHitEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get strokeHitEnabled
+var strokeHitEnabled = shape.strokeHitEnabled();
+
+// set strokeHitEnabled
+shape.strokeHitEnabled();
+ + + +
+ + + +
+
+

strokeLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set stroke linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient color stops
+var colorStops = shape.strokeLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point
+var endPoint = shape.strokeLinearGradientEndPoint();
+
+// set stroke linear gradient end point
+shape.strokeLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point x
+var endPointX = shape.strokeLinearGradientEndPointX();
+
+// set stroke linear gradient end point x
+shape.strokeLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point y
+var endPointY = shape.strokeLinearGradientEndPointY();
+
+// set stroke linear gradient end point y
+shape.strokeLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

strokeLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point
+var startPoint = shape.strokeLinearGradientStartPoint();
+
+// set stroke linear gradient start point
+shape.strokeLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point y
+var startPointY = shape.strokeLinearGradientStartPointY();
+
+// set stroke linear gradient start point y
+shape.strokeLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

strokeScaleEnabled(enabled)

+ + +
+
+ + +
+

get/set strokeScale enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke scale enabled flag
+var strokeScaleEnabled = shape.strokeScaleEnabled();
+
+// disable stroke scale
+shape.strokeScaleEnabled(false);
+
+// enable stroke scale
+shape.strokeScaleEnabled(true);
+ + + +
+ + + +
+
+

strokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var strokeWidth = shape.strokeWidth();
+
+// set stroke width
+shape.strokeWidth(10);
+ + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Container.html b/api/Konva.Container.html new file mode 100644 index 000000000..330b4396a --- /dev/null +++ b/api/Konva.Container.html @@ -0,0 +1,23324 @@ + + + + + + + Konva Class: Container + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Container

+
+ +
+ +

+ Konva~ + + Container +

+ +

Container constructor.  Containers are used to contain nodes or other containers

+ + +
+ + +
+
+ + +
+
+

<abstract> new Container(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
    +
  • @param {Object} [config.clip] set clip
  • +
clipX + + +Number + + + + + + + <optional>
+ + + + + +

set clip x

clipY + + +Number + + + + + + + <optional>
+ + + + + +

set clip y

clipWidth + + +Number + + + + + + + <optional>
+ + + + + +

set clip width

clipHeight + + +Number + + + + + + + <optional>
+ + + + + +

set clip height

clipFunc + + +function + + + + + + + <optional>
+ + + + + +

set clip func

+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

add(children)

+ + +
+
+ + +
+

add a child and children into container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
children + + +Konva.Node + + + + + + + + + + + <repeatable>
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Container + + + +
+
+ + + + + +
Example
+ +
layer.add(rect);
+layer.add(shape1, shape2, shape3);
+// empty arrays are accepted, though each individual child must be defined
+layer.add(...shapes);
+// remember to redraw layer if you changed something
+layer.draw();
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clip(clip)

+ + +
+
+ + +
+

get/set clip

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
clip + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get clip
+var clip = container.clip();
+
+// set clip
+container.clip({
+  x: 20,
+  y: 20,
+  width: 20,
+  height: 20
+});
+ + + +
+ + + +
+
+

clipFunc(function)

+ + +
+
+ + +
+

get/set clip function

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
function + + +function + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get clip function
+var clipFunction = container.clipFunc();
+
+// set clip function
+container.clipFunc(function(ctx) {
+  ctx.rect(0, 0, 100, 100);
+});
+
+container.clipFunc(function(ctx) {
+  // optionally return a clip Path2D and clip-rule or just the clip-rule
+  return [new Path2D('M0 0v50h50Z'), 'evenodd']
+});
+ + + +
+ + + +
+
+

clipHeight(height)

+ + +
+
+ + +
+

get/set clip height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clip height
+var clipHeight = container.clipHeight();
+
+// set clip height
+container.clipHeight(100);
+ + + +
+ + + +
+
+

clipWidth(width)

+ + +
+
+ + +
+

get/set clip width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clip width
+var clipWidth = container.clipWidth();
+
+// set clip width
+container.clipWidth(100);
+ + + +
+ + + +
+
+

clipX(x)

+ + +
+
+ + +
+

get/set clip x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clip x
+var clipX = container.clipX();
+
+// set clip x
+container.clipX(10);
+ + + +
+ + + +
+
+

clipY(y)

+ + +
+
+ + +
+

get/set clip y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clip y
+var clipY = container.clipY();
+
+// set clip y
+container.clipY(10);
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

destroyChildren()

+ + +
+
+ + +
+

destroy all children nodes.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

find(selector)

+ + +
+
+ + +
+

return an array of nodes that match the selector.
+You can provide a string with '#' for id selections and '.' for name selections.
+Or a function that will return true/false when a node is passed through. See example below.
+With strings you can also select by type or class name. Pass multiple selectors
+separated by a comma.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
selector + + +String +| + +function + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
Passing a string as a selector
+// select node with id foo
+var node = stage.find('#foo');
+
+// select nodes with name bar inside layer
+var nodes = layer.find('.bar');
+
+// select all groups inside layer
+var nodes = layer.find('Group');
+
+// select all rectangles inside layer
+var nodes = layer.find('Rect');
+
+// select node with an id of foo or a name of bar inside layer
+var nodes = layer.find('#foo, .bar');
+
+Passing a function as a selector
+
+// get all groups with a function
+var groups = stage.find(node => {
+ return node.getType() === 'Group';
+});
+
+// get only Nodes with partial opacity
+var alphaNodes = layer.find(node => {
+ return node.getType() === 'Node' && node.getAbsoluteOpacity() < 1;
+});
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

findOne(selector)

+ + +
+
+ + +
+

return a first node from find method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
selector + + +String +| + +function + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node +| + +Undefined + + + +
+
+ + + + + +
Example
+ +
// select node with id foo
+var node = stage.findOne('#foo');
+
+// select node with name bar inside layer
+var nodes = layer.findOne('.bar');
+
+// select the first node to return true in a function
+var node = stage.findOne(node => {
+ return node.getType() === 'Shape'
+})
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAllIntersections(pos)

+ + +
+
+ + +
+

get all shapes that intersect a point. Note: because this method must clear a temporary
+canvas and redraw every shape inside the container, it should only be used for special situations
+because it performs very poorly. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better
+nodes with listening set to false will not be detected

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

array of shapes

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getChildren( [filterFunc])

+ + +
+
+ + +
+

returns an array of direct descendant nodes

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
filterFunc + + +function + + + + + + + <optional>
+ + + + + +

filter function

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get all children
+var children = layer.getChildren();
+
+// get only circles
+var circles = layer.getChildren(function(node){
+   return node.getClassName() === 'Circle';
+});
+ + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasChildren()

+ + +
+
+ + +
+

determine if node has children

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

isAncestorOf(node)

+ + +
+
+ + +
+

determine if node is an ancestor
+of descendant

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
node + + +Konva.Node + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeChildren()

+ + +
+
+ + +
+

remove all children. Children will be still in memory.
+If you want to completely destroy all children please use "destroyChildren" method instead

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Context.html b/api/Konva.Context.html new file mode 100644 index 000000000..7685505ec --- /dev/null +++ b/api/Konva.Context.html @@ -0,0 +1,4234 @@ + + + + + + + Konva Class: Context + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Context

+
+ +
+ +

+ Konva~ + + Context +

+ +

Konva wrapper around native 2d canvas context. It has almost the same API of 2d context with some additional functions.
+With core Konva shapes you don't need to use this object. But you will use it if you want to create
+a custom shape or a custom hit regions.
+For full information about each 2d context API use MDN documentation

+ + +
+ + +
+
+ + +
+
+

new Context()

+ + +
+
+ + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
const rect = new Konva.Shape({
+   fill: 'red',
+   width: 100,
+   height: 100,
+   sceneFunc: (ctx, shape) => {
+     // ctx - is context wrapper
+     // shape - is instance of Konva.Shape, so it equals to "rect" variable
+     ctx.rect(0, 0, shape.getAttr('width'), shape.getAttr('height'));
+
+     // automatically fill shape from props and draw hit region
+     ctx.fillStrokeShape(shape);
+   }
+})
+ + + +
+ + +
+ + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

arc()

+ + +
+
+ + +
+

arc function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

arcTo()

+ + +
+
+ + +
+

arcTo function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

beginPath()

+ + +
+
+ + +
+

beginPath function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

bezierCurveTo()

+ + +
+
+ + +
+

bezierCurveTo function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

clear( [bounds])

+ + +
+
+ + +
+

clear canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
bounds + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

clearRect()

+ + +
+
+ + +
+

clearRect function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

closePath()

+ + +
+
+ + +
+

closePath function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

createImageData()

+ + +
+
+ + +
+

createImageData function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

createLinearGradient()

+ + +
+
+ + +
+

createLinearGradient function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

createPattern()

+ + +
+
+ + +
+

createPattern function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

createRadialGradient()

+ + +
+
+ + +
+

createRadialGradient function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

drawImage()

+ + +
+
+ + +
+

drawImage function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

ellipse()

+ + +
+
+ + +
+

ellipse function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

fillRect()

+ + +
+
+ + +
+

fillRect function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

fillShape(shape)

+ + +
+
+ + +
+

fill shape

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shape + + +Konva.Shape + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

fillStrokeShape(shape)

+ + +
+
+ + +
+

fill then stroke

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shape + + +Konva.Shape + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

fillText()

+ + +
+
+ + +
+

fillText function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

getCanvas()

+ + +
+
+ + +
+

get canvas wrapper

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Canvas + + + +
+
+ + + + + +
+ + + +
+
+

getImageData()

+ + +
+
+ + +
+

getImageData function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

getLineDash()

+ + +
+
+ + +
+

getLineDash function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isPointInPath()

+ + +
+
+ + +
+

isPointInPath function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

lineTo()

+ + +
+
+ + +
+

lineTo function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

measureText()

+ + +
+
+ + +
+

measureText function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

moveTo()

+ + +
+
+ + +
+

moveTo function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

putImageData()

+ + +
+
+ + +
+

putImageData function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

quadraticCurveTo()

+ + +
+
+ + +
+

quadraticCurveTo function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

rect()

+ + +
+
+ + +
+

rect function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

reset()

+ + +
+
+ + +
+

reset canvas context transform

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

restore()

+ + +
+
+ + +
+

restore function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

rotate()

+ + +
+
+ + +
+

rotate function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

roundRect()

+ + +
+
+ + +
+

roundRect function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

save()

+ + +
+
+ + +
+

save function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

scale()

+ + +
+
+ + +
+

scale function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

setLineDash()

+ + +
+
+ + +
+

setLineDash function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

setTransform()

+ + +
+
+ + +
+

setTransform function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke()

+ + +
+
+ + +
+

stroke function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

strokeRect()

+ + +
+
+ + +
+

strokeRect function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

strokeShape(shape)

+ + +
+
+ + +
+

stroke shape

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shape + + +Konva.Shape + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

strokeText()

+ + +
+
+ + +
+

strokeText function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

transform()

+ + +
+
+ + +
+

transform function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

translate()

+ + +
+
+ + +
+

translate function.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Easings.html b/api/Konva.Easings.html new file mode 100644 index 000000000..6f9bf6843 --- /dev/null +++ b/api/Konva.Easings.html @@ -0,0 +1,1710 @@ + + + + + + + Konva Namespace: Easings + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Namespace: Easings

+
+ +
+ +

+ Konva. + + Easings +

+ + +
+ + +
+
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

<static> BackEaseIn()

+ + +
+
+ + +
+

back ease in

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

<static> BackEaseInOut()

+ + +
+
+ + +
+

back ease in out

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

<static> BackEaseOut()

+ + +
+
+ + +
+

back ease out

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

<static> BounceEaseIn()

+ + +
+
+ + +
+

bounce ease in

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

<static> BounceEaseInOut()

+ + +
+
+ + +
+

bounce ease in out

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

<static> BounceEaseOut()

+ + +
+
+ + +
+

bounce ease out

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

<static> EaseIn()

+ + +
+
+ + +
+

ease in

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

<static> EaseInOut()

+ + +
+
+ + +
+

ease in out

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

<static> EaseOut()

+ + +
+
+ + +
+

ease out

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

<static> ElasticEaseIn()

+ + +
+
+ + +
+

elastic ease in

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

<static> ElasticEaseInOut()

+ + +
+
+ + +
+

elastic ease in out

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

<static> ElasticEaseOut()

+ + +
+
+ + +
+

elastic ease out

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

<static> Linear()

+ + +
+
+ + +
+

linear

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

<static> StrongEaseIn()

+ + +
+
+ + +
+

strong ease in

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

<static> StrongEaseInOut()

+ + +
+
+ + +
+

strong ease in out

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

<static> StrongEaseOut()

+ + +
+
+ + +
+

strong ease out

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Ellipse.html b/api/Konva.Ellipse.html new file mode 100644 index 000000000..b6b76109f --- /dev/null +++ b/api/Konva.Ellipse.html @@ -0,0 +1,34435 @@ + + + + + + + Konva Class: Ellipse + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Ellipse

+
+ +
+ +

+ Konva. + + Ellipse +

+ +

Ellipse constructor

+ + +
+ + +
+
+ + +
+
+

new Ellipse(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
radius + + +Object + + + + + + + + + + +

defines x and y radius

fill + + +String + + + + + + + <optional>
+ + + + + +

fill color

fillPatternImage + + +Image + + + + + + + <optional>
+ + + + + +

fill pattern image

fillPatternX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScale + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternScaleX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScaleY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRotation + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRepeat + + +String + + + + + + + <optional>
+ + + + + +

can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"

fillLinearGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillRadialGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the fill. The default value is true

fillPriority + + +String + + + + + + + <optional>
+ + + + + +

can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration

stroke + + +String + + + + + + + <optional>
+ + + + + +

stroke color

strokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

stroke width

fillAfterStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw fill AFTER stroke? Default is false.

hitStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth

strokeHitEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke hit region. The default is true

perfectDrawEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables using buffer canvas. The default is true

shadowForStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables shadow for stroke. The default is true

strokeScaleEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke scale. The default is true

strokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the stroke. The default value is true

lineJoin + + +String + + + + + + + <optional>
+ + + + + +

can be miter, round, or bevel. The default
+is miter

lineCap + + +String + + + + + + + <optional>
+ + + + + +

can be butt, round, or square. The default
+is butt

shadowColor + + +String + + + + + + + <optional>
+ + + + + +
shadowBlur + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

shadowOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
shadowOpacity + + +Number + + + + + + + <optional>
+ + + + + +

shadow opacity. Can be any real number
+between 0 and 1

shadowEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the shadow. The default value is true

dash + + +Array + + + + + + + <optional>
+ + + + + +
dashEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the dashArray. The default value is true

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var ellipse = new Konva.Ellipse({
+  radius : {
+    x : 50,
+    y : 50
+  },
+  fill: 'red'
+});
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash array for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart
+ line.dash([10, 5]);
+ // apply dashed stroke that is made up of alternating dashed
+ // lines that are 10px long and 20px apart, and dots that have
+ // a radius of 5px and are 20px apart
+ line.dash([10, 20, 0.001, 20]);
+ + + +
+ + + +
+
+

dashEnabled(enabled)

+ + +
+
+ + +
+

get/set dash enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get dash enabled flag
+var dashEnabled = shape.dashEnabled();
+
+// disable dash
+shape.dashEnabled(false);
+
+// enable dash
+shape.dashEnabled(true);
+ + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

drawHitFromCache(alphaThreshold)

+ + +
+
+ + +
+

draw hit graph using the cached scene canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alphaThreshold + + +Integer + + + + +

alpha channel threshold that determines whether or not
+a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
+The default is 0

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
shape.cache();
+shape.drawHitFromCache();
+ + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

fill(color)

+ + +
+
+ + +
+

get/set fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill color
+var fill = shape.fill();
+
+// set fill color with color string
+shape.fill('green');
+
+// set fill color with hex
+shape.fill('#00ff00');
+
+// set fill color with rgb
+shape.fill('rgb(0,255,0)');
+
+// set fill color with rgba and make it 50% opaque
+shape.fill('rgba(0,255,0,0.5');
+
+// shape without fill
+shape.fill(null);
+ + + +
+ + + +
+
+

fillAfterStrokeEnabled(fillAfterStrokeEnabled)

+ + +
+
+ + +
+

get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
+In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
+Especially useful for Text objects.
+Default is false.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fillAfterStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
+
+// set stroke width
+shape.fillAfterStrokeEnabled(true);
+ + + +
+ + + +
+
+

fillEnabled(enabled)

+ + +
+
+ + +
+

get/set fill enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get fill enabled flag
+var fillEnabled = shape.fillEnabled();
+
+// disable fill
+shape.fillEnabled(false);
+
+// enable fill
+shape.fillEnabled(true);
+ + + +
+ + + +
+
+

fillLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient color stops
+var colorStops = shape.fillLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point
+var endPoint = shape.fillLinearGradientEndPoint();
+
+// set fill linear gradient end point
+shape.fillLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point x
+var endPointX = shape.fillLinearGradientEndPointX();
+
+// set fill linear gradient end point x
+shape.fillLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point y
+var endPointY = shape.fillLinearGradientEndPointY();
+
+// set fill linear gradient end point y
+shape.fillLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point
+var startPoint = shape.fillLinearGradientStartPoint();
+
+// set fill linear gradient start point
+shape.fillLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point x
+var startPointX = shape.fillLinearGradientStartPointX();
+
+// set fill linear gradient start point x
+shape.fillLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point y
+var startPointY = shape.fillLinearGradientStartPointY();
+
+// set fill linear gradient start point y
+shape.fillLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillPatternImage(image)

+ + +
+
+ + +
+

get/set fill pattern image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +

object

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get fill pattern image
+var fillPatternImage = shape.fillPatternImage();
+
+// set fill pattern image
+var imageObj = new Image();
+imageObj.onload = function() {
+  shape.fillPatternImage(imageObj);
+};
+imageObj.src = 'path/to/image/jpg';
+ + + +
+ + + +
+
+

fillPatternOffset(offset)

+ + +
+
+ + +
+

get/set fill pattern offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset
+var patternOffset = shape.fillPatternOffset();
+
+// set fill pattern offset
+shape.fillPatternOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillPatternOffsetX(x)

+ + +
+
+ + +
+

get/set fill pattern offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset x
+var patternOffsetX = shape.fillPatternOffsetX();
+
+// set fill pattern offset x
+shape.fillPatternOffsetX(20);
+ + + +
+ + + +
+
+

fillPatternOffsetY(y)

+ + +
+
+ + +
+

get/set fill pattern offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset y
+var patternOffsetY = shape.fillPatternOffsetY();
+
+// set fill pattern offset y
+shape.fillPatternOffsetY(10);
+ + + +
+ + + +
+
+

fillPatternRepeat(repeat)

+ + +
+
+ + +
+

get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
repeat + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill pattern repeat
+var repeat = shape.fillPatternRepeat();
+
+// repeat pattern in x direction only
+shape.fillPatternRepeat('repeat-x');
+
+// do not repeat the pattern
+shape.fillPatternRepeat('no-repeat');
+ + + +
+ + + +
+
+

fillPatternRotation(rotation)

+ + +
+
+ + +
+

get/set fill pattern rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill pattern rotation
+var patternRotation = shape.fillPatternRotation();
+
+// set fill pattern rotation
+shape.fillPatternRotation(20);
+ + + +
+ + + +
+
+

fillPatternScale(scale)

+ + +
+
+ + +
+

get/set fill pattern scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale
+var patternScale = shape.fillPatternScale();
+
+// set fill pattern scale
+shape.fillPatternScale({
+  x: 2,
+  y: 2
+});
+ + + +
+ + + +
+
+

fillPatternScaleX(x)

+ + +
+
+ + +
+

get/set fill pattern scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale x
+var patternScaleX = shape.fillPatternScaleX();
+
+// set fill pattern scale x
+shape.fillPatternScaleX(2);
+ + + +
+ + + +
+
+

fillPatternScaleY(y)

+ + +
+
+ + +
+

get/set fill pattern scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale y
+var patternScaleY = shape.fillPatternScaleY();
+
+// set fill pattern scale y
+shape.fillPatternScaleY(2);
+ + + +
+ + + +
+
+

fillPatternX(x)

+ + +
+
+ + +
+

get/set fill pattern x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern x
+var fillPatternX = shape.fillPatternX();
+// set fill pattern x
+shape.fillPatternX(20);
+ + + +
+ + + +
+
+

fillPatternY(y)

+ + +
+
+ + +
+

get/set fill pattern y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern y
+var fillPatternY = shape.fillPatternY();
+// set fill pattern y
+shape.fillPatternY(20);
+ + + +
+ + + +
+
+

fillPriority(priority)

+ + +
+
+ + +
+

get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
+This is handy if you want to toggle between different fill types.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
priority + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill priority
+var fillPriority = shape.fillPriority();
+
+// set fill priority
+shape.fillPriority('linear-gradient');
+ + + +
+ + + +
+
+

fillRadialGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill radial gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient color stops
+var colorStops = shape.fillRadialGradientColorStops();
+
+// create a radial gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillRadialGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill radial gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point
+var endPoint = shape.fillRadialGradientEndPoint();
+
+// set fill radial gradient end point
+shape.fillRadialGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point x
+var endPointX = shape.fillRadialGradientEndPointX();
+
+// set fill radial gradient end point x
+shape.fillRadialGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point y
+var endPointY = shape.fillRadialGradientEndPointY();
+
+// set fill radial gradient end point y
+shape.fillRadialGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient end radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient end radius
+var endRadius = shape.fillRadialGradientEndRadius();
+
+// set radial gradient end radius
+shape.fillRadialGradientEndRadius(100);
+ + + +
+ + + +
+
+

fillRadialGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill radial gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point
+var startPoint = shape.fillRadialGradientStartPoint();
+
+// set fill radial gradient start point
+shape.fillRadialGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point x
+var startPointX = shape.fillRadialGradientStartPointX();
+
+// set fill radial gradient start point x
+shape.fillRadialGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point y
+var startPointY = shape.fillRadialGradientStartPointY();
+
+// set fill radial gradient start point y
+shape.fillRadialGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient start radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient start radius
+var startRadius = shape.fillRadialGradientStartRadius();
+
+// set radial gradient start radius
+shape.fillRadialGradientStartRadius(0);
+ + + +
+ + + +
+
+

fillRule(rotation)

+ + +
+
+ + +
+

get/set fill rule

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +CanvasFillRule + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill rule
+var fillRule = shape.fillRule();
+
+// set fill rule
+shape.fillRule('evenodd');
+ + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getSelfRect()

+ + +
+
+ + +
+

return self rectangle (x, y, width, height) of shape.
+This method are not taken into account transformation and styles.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
rect.getSelfRect();  // return {x:0, y:0, width:rect.width(), height:rect.height()}
+circle.getSelfRect();  // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasFill()

+ + +
+
+ + +
+

returns whether or not the shape will be filled

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

hasShadow()

+ + +
+
+ + +
+

returns whether or not a shadow will be rendered

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasStroke()

+ + +
+
+ + +
+

returns whether or not the shape will be stroked

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitFunc(drawFunc)

+ + +
+
+ + +
+

get/set hit draw function. That function is used to draw custom hit area of a shape.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get hit draw function
+var hitFunc = shape.hitFunc();
+
+// set hit draw function
+shape.hitFunc(function(context) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

hitStrokeWidth(hitStrokeWidth)

+ + +
+
+ + +
+

get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var hitStrokeWidth = shape.hitStrokeWidth();
+
+// set hit stroke width
+shape.hitStrokeWidth(20);
+// set hit stroke width always equals to scene stroke width
+shape.hitStrokeWidth('auto');
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

intersects(point)

+ + +
+
+ + +
+

determines if point is in the shape, regardless if other shapes are on top of it. Note: because
+this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
+consecutively. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

linearLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set stroke linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point x
+var startPointX = shape.strokeLinearGradientStartPointX();
+
+// set stroke linear gradient start point x
+shape.strokeLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

lineCap(lineCap)

+ + +
+
+ + +
+

get/set line cap. Can be butt, round, or square

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineCap + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line cap
+var lineCap = shape.lineCap();
+
+// set line cap
+shape.lineCap('round');
+ + + +
+ + + +
+
+

lineJoin(lineJoin)

+ + +
+
+ + +
+

get/set line join. Can be miter, round, or bevel. The
+default is miter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineJoin + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line join
+var lineJoin = shape.lineJoin();
+
+// set line join
+shape.lineJoin('round');
+ + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

perfectDrawEnabled(perfectDrawEnabled)

+ + +
+
+ + +
+

get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set perfectDrawEnabled to false to improve performance.
+See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
perfectDrawEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get perfectDrawEnabled
+var perfectDrawEnabled = shape.perfectDrawEnabled();
+
+// set perfectDrawEnabled
+shape.perfectDrawEnabled();
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

radius(radius)

+ + +
+
+ + +
+

get/set radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get radius
+var radius = ellipse.radius();
+
+// set radius
+ellipse.radius({
+  x: 200,
+  y: 100
+});
+ + + +
+ + + +
+
+

radiusX(x)

+ + +
+
+ + +
+

get/set radius x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radius x
+var radiusX = ellipse.radiusX();
+
+// set radius x
+ellipse.radiusX(200);
+ + + +
+ + + +
+
+

radiusY(y)

+ + +
+
+ + +
+

get/set radius y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radius y
+var radiusY = ellipse.radiusY();
+
+// set radius y
+ellipse.radiusY(200);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

sceneFunc(drawFunc)

+ + +
+
+ + +
+

get/set scene draw function. That function is used to draw the shape on a canvas.
+Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get scene draw function
+var sceneFunc = shape.sceneFunc();
+
+// set scene draw function
+shape.sceneFunc(function(context, shape) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  // like stroke and fill
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

shadowBlur(blur)

+ + +
+
+ + +
+

get/set shadow blur

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blur + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow blur
+var shadowBlur = shape.shadowBlur();
+
+// set shadow blur
+shape.shadowBlur(10);
+ + + +
+ + + +
+
+

shadowColor(color)

+ + +
+
+ + +
+

get/set shadow color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get shadow color
+var shadow = shape.shadowColor();
+
+// set shadow color with color string
+shape.shadowColor('green');
+
+// set shadow color with hex
+shape.shadowColor('#00ff00');
+
+// set shadow color with rgb
+shape.shadowColor('rgb(0,255,0)');
+
+// set shadow color with rgba and make it 50% opaque
+shape.shadowColor('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

shadowEnabled(enabled)

+ + +
+
+ + +
+

get/set shadow enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadow enabled flag
+var shadowEnabled = shape.shadowEnabled();
+
+// disable shadow
+shape.shadowEnabled(false);
+
+// enable shadow
+shape.shadowEnabled(true);
+ + + +
+ + + +
+
+

shadowForStrokeEnabled(shadowForStrokeEnabled)

+ + +
+
+ + +
+

get/set shadowForStrokeEnabled. Useful for performance optimization.
+You may set shape.shadowForStrokeEnabled(false). In this case stroke will no effect shadow.
+Remember if you set shadowForStrokeEnabled = false for non closed line - that line will have no shadow!.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shadowForStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadowForStrokeEnabled
+var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
+
+// set shadowForStrokeEnabled
+shape.shadowForStrokeEnabled();
+ + + +
+ + + +
+
+

shadowOffset(offset)

+ + +
+
+ + +
+

get/set shadow offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get shadow offset
+var shadowOffset = shape.shadowOffset();
+
+// set shadow offset
+shape.shadowOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

shadowOffsetX(x)

+ + +
+
+ + +
+

get/set shadow offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset x
+var shadowOffsetX = shape.shadowOffsetX();
+
+// set shadow offset x
+shape.shadowOffsetX(5);
+ + + +
+ + + +
+
+

shadowOffsetY(y)

+ + +
+
+ + +
+

get/set shadow offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset y
+var shadowOffsetY = shape.shadowOffsetY();
+
+// set shadow offset y
+shape.shadowOffsetY(5);
+ + + +
+ + + +
+
+

shadowOpacity(opacity)

+ + +
+
+ + +
+

get/set shadow opacity. must be a value between 0 and 1

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow opacity
+var shadowOpacity = shape.shadowOpacity();
+
+// set shadow opacity
+shape.shadowOpacity(0.5);
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke(color)

+ + +
+
+ + +
+

get/set stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get stroke color
+var stroke = shape.stroke();
+
+// set stroke color with color string
+shape.stroke('green');
+
+// set stroke color with hex
+shape.stroke('#00ff00');
+
+// set stroke color with rgb
+shape.stroke('rgb(0,255,0)');
+
+// set stroke color with rgba and make it 50% opaque
+shape.stroke('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

strokeEnabled(enabled)

+ + +
+
+ + +
+

get/set stroke enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke enabled flag
+var strokeEnabled = shape.strokeEnabled();
+
+// disable stroke
+shape.strokeEnabled(false);
+
+// enable stroke
+shape.strokeEnabled(true);
+ + + +
+ + + +
+
+

strokeHitEnabled(strokeHitEnabled)

+ + +
+
+ + +
+

deprecated, use hitStrokeWidth instead! get/set strokeHitEnabled property. Useful for performance optimization.
+You may set shape.strokeHitEnabled(false). In this case stroke will be no draw on hit canvas, so hit area
+of shape will be decreased (by lineWidth / 2). Remember that non closed line with strokeHitEnabled = false
+will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
+Default value is true.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeHitEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get strokeHitEnabled
+var strokeHitEnabled = shape.strokeHitEnabled();
+
+// set strokeHitEnabled
+shape.strokeHitEnabled();
+ + + +
+ + + +
+
+

strokeLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set stroke linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient color stops
+var colorStops = shape.strokeLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point
+var endPoint = shape.strokeLinearGradientEndPoint();
+
+// set stroke linear gradient end point
+shape.strokeLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point x
+var endPointX = shape.strokeLinearGradientEndPointX();
+
+// set stroke linear gradient end point x
+shape.strokeLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point y
+var endPointY = shape.strokeLinearGradientEndPointY();
+
+// set stroke linear gradient end point y
+shape.strokeLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

strokeLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point
+var startPoint = shape.strokeLinearGradientStartPoint();
+
+// set stroke linear gradient start point
+shape.strokeLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point y
+var startPointY = shape.strokeLinearGradientStartPointY();
+
+// set stroke linear gradient start point y
+shape.strokeLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

strokeScaleEnabled(enabled)

+ + +
+
+ + +
+

get/set strokeScale enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke scale enabled flag
+var strokeScaleEnabled = shape.strokeScaleEnabled();
+
+// disable stroke scale
+shape.strokeScaleEnabled(false);
+
+// enable stroke scale
+shape.strokeScaleEnabled(true);
+ + + +
+ + + +
+
+

strokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var strokeWidth = shape.strokeWidth();
+
+// set stroke width
+shape.strokeWidth(10);
+ + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.FastLayer.html b/api/Konva.FastLayer.html new file mode 100644 index 000000000..c8687daf4 --- /dev/null +++ b/api/Konva.FastLayer.html @@ -0,0 +1,628 @@ + + + + + + + Konva Class: FastLayer + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: FastLayer

+
+ +
+ +

+ Konva~ + + FastLayer +

+ +

FastLayer constructor. DEPRECATED! Please use Konva.Layer({ listening: false}) instead. Layers are tied to their own canvas element and are used
+to contain shapes only. If you don't need node nesting, mouse and touch interactions,
+or event pub/sub, you should use FastLayer instead of Layer to create your layers.
+It renders about 2x faster than normal layers.

+ + +
+ + +
+
+ + +
+
+

new FastLayer()

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config.clipX + + +Number + + + + + + + <optional>
+ + + + + +

set clip x

config.clipY + + +Number + + + + + + + <optional>
+ + + + + +

set clip y

config.clipWidth + + +Number + + + + + + + <optional>
+ + + + + +

set clip width

config.clipHeight + + +Number + + + + + + + <optional>
+ + + + + +

set clip height

config.clipFunc + + +function + + + + + + + <optional>
+ + + + + +

set clip func

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var layer = new Konva.FastLayer();
+ + + +
+ + +
+ + +

Extends

+ + + + +
    +
  • Object
  • +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Filters.html b/api/Konva.Filters.html new file mode 100644 index 000000000..7ffc211da --- /dev/null +++ b/api/Konva.Filters.html @@ -0,0 +1,2992 @@ + + + + + + + Konva Namespace: Filters + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Namespace: Filters

+
+ +
+ +

+ Konva. + + Filters +

+ + +
+ + +
+
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

<static> Blur(imageData)

+ + +
+
+ + +
+

Blur Filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.cache();
+node.filters([Konva.Filters.Blur]);
+node.blurRadius(10);
+ + + +
+ + + +
+
+

<static> Brighten(imageData)

+ + +
+
+ + +
+

Brighten Filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.cache();
+node.filters([Konva.Filters.Brighten]);
+node.brightness(0.8);
+ + + +
+ + + +
+
+

<static> Contrast(imageData)

+ + +
+
+ + +
+

Contrast Filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.cache();
+node.filters([Konva.Filters.Contrast]);
+node.contrast(10);
+ + + +
+ + + +
+
+

<static> Emboss(imageData)

+ + +
+
+ + +
+

Emboss Filter.
+Pixastic Lib - Emboss filter - v0.1.0
+Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
+License: [http://www.pixastic.com/lib/license.txt]

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.cache();
+node.filters([Konva.Filters.Emboss]);
+node.embossStrength(0.8);
+node.embossWhiteLevel(0.3);
+node.embossDirection('right');
+node.embossBlend(true);
+ + + +
+ + + +
+
+

<static> Enhance(imageData)

+ + +
+
+ + +
+

Enhance Filter. Adjusts the colors so that they span the widest
+possible range (ie 0-255). Performs wh pixel reads and wh pixel
+writes.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + +
Author:
+
+
    +
  • ippo615
  • +
+
+ + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.cache();
+node.filters([Konva.Filters.Enhance]);
+node.enhance(0.4);
+ + + +
+ + + +
+
+

<static> Grayscale(imageData)

+ + +
+
+ + +
+

Grayscale Filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.cache();
+node.filters([Konva.Filters.Grayscale]);
+ + + +
+ + + +
+
+

<static> HSL(imageData)

+ + +
+
+ + +
+

HSL Filter. Adjusts the hue, saturation and luminance (or lightness)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + +
Author:
+
+
    +
  • ippo615
  • +
+
+ + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
image.filters([Konva.Filters.HSL]);
+image.luminance(0.2);
+ + + +
+ + + +
+
+

<static> HSV(imageData)

+ + +
+
+ + +
+

HSV Filter. Adjusts the hue, saturation and value

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + +
Author:
+
+
    +
  • ippo615
  • +
+
+ + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
image.filters([Konva.Filters.HSV]);
+image.value(200);
+ + + +
+ + + +
+
+

<static> Invert(imageData)

+ + +
+
+ + +
+

Invert Filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.cache();
+node.filters([Konva.Filters.Invert]);
+ + + +
+ + + +
+
+

<static> Mask(imageData)

+ + +
+
+ + +
+

Mask Filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.cache();
+node.filters([Konva.Filters.Mask]);
+node.threshold(200);
+ + + +
+ + + +
+
+

<static> Noise(imageData)

+ + +
+
+ + +
+

Noise Filter. Randomly adds or substracts to the color channels

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + +
Author:
+
+
    +
  • ippo615
  • +
+
+ + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.cache();
+node.filters([Konva.Filters.Noise]);
+node.noise(0.8);
+ + + +
+ + + +
+
+

<static> Pixelate(imageData)

+ + +
+
+ + +
+

Pixelate Filter. Averages groups of pixels and redraws
+them as larger pixels

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + +
Author:
+
+
    +
  • ippo615
  • +
+
+ + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.cache();
+node.filters([Konva.Filters.Pixelate]);
+node.pixelSize(10);
+ + + +
+ + + +
+
+

<static> Posterize(imageData)

+ + +
+
+ + +
+

Posterize Filter. Adjusts the channels so that there are no more
+than n different values for that channel. This is also applied
+to the alpha channel.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + +
Author:
+
+
    +
  • ippo615
  • +
+
+ + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.cache();
+node.filters([Konva.Filters.Posterize]);
+node.levels(0.8); // between 0 and 1
+ + + +
+ + + +
+
+

<static> RGB(imageData)

+ + +
+
+ + +
+

RGB Filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + +
Author:
+
+
    +
  • ippo615
  • +
+
+ + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.cache();
+node.filters([Konva.Filters.RGB]);
+node.blue(120);
+node.green(200);
+ + + +
+ + + +
+
+

<static> RGBA(imageData)

+ + +
+
+ + +
+

RGBA Filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + +
Author:
+
+
    +
  • codefo
  • +
+
+ + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.cache();
+node.filters([Konva.Filters.RGBA]);
+node.blue(120);
+node.green(200);
+node.alpha(0.3);
+ + + +
+ + + +
+
+

<static> Sepia(imageData)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.cache();
+node.filters([Konva.Filters.Sepia]);
+ + + +
+ + + +
+
+

<static> Solarize(imageData)

+ + +
+
+ + +
+

Solarize Filter
+Pixastic Lib - Solarize filter - v0.1.0
+Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
+License: [http://www.pixastic.com/lib/license.txt]

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.cache();
+node.filters([Konva.Filters.Solarize]);
+ + + +
+ + + +
+
+

<static> Threshold(imageData)

+ + +
+
+ + +
+

Threshold Filter. Pushes any value above the mid point to
+the max and any value below the mid point to the min.
+This affects the alpha channel.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageData + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + +
Author:
+
+
    +
  • ippo615
  • +
+
+ + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.cache();
+node.filters([Konva.Filters.Threshold]);
+node.threshold(0.1);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Group.html b/api/Konva.Group.html new file mode 100644 index 000000000..49b918c43 --- /dev/null +++ b/api/Konva.Group.html @@ -0,0 +1,22925 @@ + + + + + + + Konva Class: Group + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Group

+
+ +
+ +

+ Konva. + + Group +

+ +

Group constructor. Groups are used to contain shapes or other groups.

+ + +
+ + +
+
+ + +
+
+

new Group(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
    +
  • @param {Object} [config.clip] set clip
  • +
clipX + + +Number + + + + + + + <optional>
+ + + + + +

set clip x

clipY + + +Number + + + + + + + <optional>
+ + + + + +

set clip y

clipWidth + + +Number + + + + + + + <optional>
+ + + + + +

set clip width

clipHeight + + +Number + + + + + + + <optional>
+ + + + + +

set clip height

clipFunc + + +function + + + + + + + <optional>
+ + + + + +

set clip func

+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var group = new Konva.Group();
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

add(children)

+ + +
+
+ + +
+

add a child and children into container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
children + + +Konva.Node + + + + + + + + + + + <repeatable>
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Container + + + +
+
+ + + + + +
Example
+ +
layer.add(rect);
+layer.add(shape1, shape2, shape3);
+// empty arrays are accepted, though each individual child must be defined
+layer.add(...shapes);
+// remember to redraw layer if you changed something
+layer.draw();
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clip(clip)

+ + +
+
+ + +
+

get/set clip

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
clip + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get clip
+var clip = container.clip();
+
+// set clip
+container.clip({
+  x: 20,
+  y: 20,
+  width: 20,
+  height: 20
+});
+ + + +
+ + + +
+
+

clipFunc(function)

+ + +
+
+ + +
+

get/set clip function

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
function + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get clip function
+var clipFunction = container.clipFunc();
+
+// set clip function
+container.clipFunc(function(ctx) {
+  ctx.rect(0, 0, 100, 100);
+});
+
+container.clipFunc(function(ctx) {
+  // optionally return a clip Path2D and clip-rule or just the clip-rule
+  return [new Path2D('M0 0v50h50Z'), 'evenodd']
+});
+ + + +
+ + + +
+
+

clipHeight(height)

+ + +
+
+ + +
+

get/set clip height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clip height
+var clipHeight = container.clipHeight();
+
+// set clip height
+container.clipHeight(100);
+ + + +
+ + + +
+
+

clipWidth(width)

+ + +
+
+ + +
+

get/set clip width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clip width
+var clipWidth = container.clipWidth();
+
+// set clip width
+container.clipWidth(100);
+ + + +
+ + + +
+
+

clipX(x)

+ + +
+
+ + +
+

get/set clip x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clip x
+var clipX = container.clipX();
+
+// set clip x
+container.clipX(10);
+ + + +
+ + + +
+
+

clipY(y)

+ + +
+
+ + +
+

get/set clip y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clip y
+var clipY = container.clipY();
+
+// set clip y
+container.clipY(10);
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

destroyChildren()

+ + +
+
+ + +
+

destroy all children nodes.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

find(selector)

+ + +
+
+ + +
+

return an array of nodes that match the selector.
+You can provide a string with '#' for id selections and '.' for name selections.
+Or a function that will return true/false when a node is passed through. See example below.
+With strings you can also select by type or class name. Pass multiple selectors
+separated by a comma.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
selector + + +String +| + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
Passing a string as a selector
+// select node with id foo
+var node = stage.find('#foo');
+
+// select nodes with name bar inside layer
+var nodes = layer.find('.bar');
+
+// select all groups inside layer
+var nodes = layer.find('Group');
+
+// select all rectangles inside layer
+var nodes = layer.find('Rect');
+
+// select node with an id of foo or a name of bar inside layer
+var nodes = layer.find('#foo, .bar');
+
+Passing a function as a selector
+
+// get all groups with a function
+var groups = stage.find(node => {
+ return node.getType() === 'Group';
+});
+
+// get only Nodes with partial opacity
+var alphaNodes = layer.find(node => {
+ return node.getType() === 'Node' && node.getAbsoluteOpacity() < 1;
+});
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

findOne(selector)

+ + +
+
+ + +
+

return a first node from find method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
selector + + +String +| + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node +| + +Undefined + + + +
+
+ + + + + +
Example
+ +
// select node with id foo
+var node = stage.findOne('#foo');
+
+// select node with name bar inside layer
+var nodes = layer.findOne('.bar');
+
+// select the first node to return true in a function
+var node = stage.findOne(node => {
+ return node.getType() === 'Shape'
+})
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAllIntersections(pos)

+ + +
+
+ + +
+

get all shapes that intersect a point. Note: because this method must clear a temporary
+canvas and redraw every shape inside the container, it should only be used for special situations
+because it performs very poorly. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better
+nodes with listening set to false will not be detected

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

array of shapes

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getChildren( [filterFunc])

+ + +
+
+ + +
+

returns an array of direct descendant nodes

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
filterFunc + + +function + + + + + + + <optional>
+ + + + + +

filter function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get all children
+var children = layer.getChildren();
+
+// get only circles
+var circles = layer.getChildren(function(node){
+   return node.getClassName() === 'Circle';
+});
+ + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasChildren()

+ + +
+
+ + +
+

determine if node has children

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

isAncestorOf(node)

+ + +
+
+ + +
+

determine if node is an ancestor
+of descendant

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
node + + +Konva.Node + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeChildren()

+ + +
+
+ + +
+

remove all children. Children will be still in memory.
+If you want to completely destroy all children please use "destroyChildren" method instead

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Image.html b/api/Konva.Image.html new file mode 100644 index 000000000..985b7b845 --- /dev/null +++ b/api/Konva.Image.html @@ -0,0 +1,36251 @@ + + + + + + + Konva Class: Image + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Image

+
+ +
+ +

+ Konva~ + + Image +

+ +

Image constructor

+ + +
+ + +
+
+ + +
+
+

new Image(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
image + + +Image + + + + + + + + + + +
crop + + +Object + + + + + + + <optional>
+ + + + + +
fill + + +String + + + + + + + <optional>
+ + + + + +

fill color

fillPatternImage + + +Image + + + + + + + <optional>
+ + + + + +

fill pattern image

fillPatternX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScale + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternScaleX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScaleY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRotation + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRepeat + + +String + + + + + + + <optional>
+ + + + + +

can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"

fillLinearGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillRadialGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the fill. The default value is true

fillPriority + + +String + + + + + + + <optional>
+ + + + + +

can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration

stroke + + +String + + + + + + + <optional>
+ + + + + +

stroke color

strokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

stroke width

fillAfterStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw fill AFTER stroke? Default is false.

hitStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth

strokeHitEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke hit region. The default is true

perfectDrawEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables using buffer canvas. The default is true

shadowForStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables shadow for stroke. The default is true

strokeScaleEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke scale. The default is true

strokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the stroke. The default value is true

lineJoin + + +String + + + + + + + <optional>
+ + + + + +

can be miter, round, or bevel. The default
+is miter

lineCap + + +String + + + + + + + <optional>
+ + + + + +

can be butt, round, or square. The default
+is butt

shadowColor + + +String + + + + + + + <optional>
+ + + + + +
shadowBlur + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

shadowOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
shadowOpacity + + +Number + + + + + + + <optional>
+ + + + + +

shadow opacity. Can be any real number
+between 0 and 1

shadowEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the shadow. The default value is true

dash + + +Array + + + + + + + <optional>
+ + + + + +
dashEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the dashArray. The default value is true

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var imageObj = new Image();
+imageObj.onload = function() {
+  var image = new Konva.Image({
+    x: 200,
+    y: 50,
+    image: imageObj,
+    width: 100,
+    height: 100
+  });
+};
+imageObj.src = '/path/to/image.jpg'
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

<static> Image.fromURL(url, callback, onError)

+ + +
+
+ + +
+

load image from given url and create Konva.Image instance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
url + + +String + + + + + + +

image source

callback + + +function + + + + + + +

with Konva.Image instance as first argument

onError + + +function + + + + + + + null + +

optional error handler

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
Konva.Image.fromURL(imageURL, function(image){
+   // image is Konva.Image instance
+   layer.add(image);
+   layer.draw();
+ });
+ + + +
+ + + +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cornerRadius(cornerRadius)

+ + +
+
+ + +
+

get/set corner radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
cornerRadius + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get corner radius
+var cornerRadius = image.cornerRadius();
+
+// set corner radius
+image.cornerRadius(10);
+
+// set different corner radius values
+// top-left, top-right, bottom-right, bottom-left
+image.cornerRadius([0, 10, 20, 30]);
+ + + +
+ + + +
+
+

crop(crop)

+ + +
+
+ + +
+

get/set crop

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
crop + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get crop
+var crop = image.crop();
+
+// set crop
+image.crop({
+  x: 20,
+  y: 20,
+  width: 20,
+  height: 20
+});
+ + + +
+ + + +
+
+

cropHeight(height)

+ + +
+
+ + +
+

get/set crop height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get crop height
+var cropHeight = image.cropHeight();
+
+// set crop height
+image.cropHeight(20);
+ + + +
+ + + +
+
+

cropWidth(width)

+ + +
+
+ + +
+

get/set crop width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get crop width
+var cropWidth = image.cropWidth();
+
+// set crop width
+image.cropWidth(20);
+ + + +
+ + + +
+
+

cropX(x)

+ + +
+
+ + +
+

get/set crop x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get crop x
+var cropX = image.cropX();
+
+// set crop x
+image.cropX(20);
+ + + +
+ + + +
+
+

cropY(y)

+ + +
+
+ + +
+

get/set crop y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get crop y
+var cropY = image.cropY();
+
+// set crop y
+image.cropY(20);
+ + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash array for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart
+ line.dash([10, 5]);
+ // apply dashed stroke that is made up of alternating dashed
+ // lines that are 10px long and 20px apart, and dots that have
+ // a radius of 5px and are 20px apart
+ line.dash([10, 20, 0.001, 20]);
+ + + +
+ + + +
+
+

dashEnabled(enabled)

+ + +
+
+ + +
+

get/set dash enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get dash enabled flag
+var dashEnabled = shape.dashEnabled();
+
+// disable dash
+shape.dashEnabled(false);
+
+// enable dash
+shape.dashEnabled(true);
+ + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

drawHitFromCache(alphaThreshold)

+ + +
+
+ + +
+

draw hit graph using the cached scene canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alphaThreshold + + +Integer + + + + +

alpha channel threshold that determines whether or not
+a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
+The default is 0

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
shape.cache();
+shape.drawHitFromCache();
+ + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

fill(color)

+ + +
+
+ + +
+

get/set fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill color
+var fill = shape.fill();
+
+// set fill color with color string
+shape.fill('green');
+
+// set fill color with hex
+shape.fill('#00ff00');
+
+// set fill color with rgb
+shape.fill('rgb(0,255,0)');
+
+// set fill color with rgba and make it 50% opaque
+shape.fill('rgba(0,255,0,0.5');
+
+// shape without fill
+shape.fill(null);
+ + + +
+ + + +
+
+

fillAfterStrokeEnabled(fillAfterStrokeEnabled)

+ + +
+
+ + +
+

get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
+In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
+Especially useful for Text objects.
+Default is false.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fillAfterStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
+
+// set stroke width
+shape.fillAfterStrokeEnabled(true);
+ + + +
+ + + +
+
+

fillEnabled(enabled)

+ + +
+
+ + +
+

get/set fill enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get fill enabled flag
+var fillEnabled = shape.fillEnabled();
+
+// disable fill
+shape.fillEnabled(false);
+
+// enable fill
+shape.fillEnabled(true);
+ + + +
+ + + +
+
+

fillLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient color stops
+var colorStops = shape.fillLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point
+var endPoint = shape.fillLinearGradientEndPoint();
+
+// set fill linear gradient end point
+shape.fillLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point x
+var endPointX = shape.fillLinearGradientEndPointX();
+
+// set fill linear gradient end point x
+shape.fillLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point y
+var endPointY = shape.fillLinearGradientEndPointY();
+
+// set fill linear gradient end point y
+shape.fillLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point
+var startPoint = shape.fillLinearGradientStartPoint();
+
+// set fill linear gradient start point
+shape.fillLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point x
+var startPointX = shape.fillLinearGradientStartPointX();
+
+// set fill linear gradient start point x
+shape.fillLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point y
+var startPointY = shape.fillLinearGradientStartPointY();
+
+// set fill linear gradient start point y
+shape.fillLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillPatternImage(image)

+ + +
+
+ + +
+

get/set fill pattern image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +

object

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get fill pattern image
+var fillPatternImage = shape.fillPatternImage();
+
+// set fill pattern image
+var imageObj = new Image();
+imageObj.onload = function() {
+  shape.fillPatternImage(imageObj);
+};
+imageObj.src = 'path/to/image/jpg';
+ + + +
+ + + +
+
+

fillPatternOffset(offset)

+ + +
+
+ + +
+

get/set fill pattern offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset
+var patternOffset = shape.fillPatternOffset();
+
+// set fill pattern offset
+shape.fillPatternOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillPatternOffsetX(x)

+ + +
+
+ + +
+

get/set fill pattern offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset x
+var patternOffsetX = shape.fillPatternOffsetX();
+
+// set fill pattern offset x
+shape.fillPatternOffsetX(20);
+ + + +
+ + + +
+
+

fillPatternOffsetY(y)

+ + +
+
+ + +
+

get/set fill pattern offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset y
+var patternOffsetY = shape.fillPatternOffsetY();
+
+// set fill pattern offset y
+shape.fillPatternOffsetY(10);
+ + + +
+ + + +
+
+

fillPatternRepeat(repeat)

+ + +
+
+ + +
+

get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
repeat + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill pattern repeat
+var repeat = shape.fillPatternRepeat();
+
+// repeat pattern in x direction only
+shape.fillPatternRepeat('repeat-x');
+
+// do not repeat the pattern
+shape.fillPatternRepeat('no-repeat');
+ + + +
+ + + +
+
+

fillPatternRotation(rotation)

+ + +
+
+ + +
+

get/set fill pattern rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill pattern rotation
+var patternRotation = shape.fillPatternRotation();
+
+// set fill pattern rotation
+shape.fillPatternRotation(20);
+ + + +
+ + + +
+
+

fillPatternScale(scale)

+ + +
+
+ + +
+

get/set fill pattern scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale
+var patternScale = shape.fillPatternScale();
+
+// set fill pattern scale
+shape.fillPatternScale({
+  x: 2,
+  y: 2
+});
+ + + +
+ + + +
+
+

fillPatternScaleX(x)

+ + +
+
+ + +
+

get/set fill pattern scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale x
+var patternScaleX = shape.fillPatternScaleX();
+
+// set fill pattern scale x
+shape.fillPatternScaleX(2);
+ + + +
+ + + +
+
+

fillPatternScaleY(y)

+ + +
+
+ + +
+

get/set fill pattern scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale y
+var patternScaleY = shape.fillPatternScaleY();
+
+// set fill pattern scale y
+shape.fillPatternScaleY(2);
+ + + +
+ + + +
+
+

fillPatternX(x)

+ + +
+
+ + +
+

get/set fill pattern x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern x
+var fillPatternX = shape.fillPatternX();
+// set fill pattern x
+shape.fillPatternX(20);
+ + + +
+ + + +
+
+

fillPatternY(y)

+ + +
+
+ + +
+

get/set fill pattern y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern y
+var fillPatternY = shape.fillPatternY();
+// set fill pattern y
+shape.fillPatternY(20);
+ + + +
+ + + +
+
+

fillPriority(priority)

+ + +
+
+ + +
+

get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
+This is handy if you want to toggle between different fill types.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
priority + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill priority
+var fillPriority = shape.fillPriority();
+
+// set fill priority
+shape.fillPriority('linear-gradient');
+ + + +
+ + + +
+
+

fillRadialGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill radial gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient color stops
+var colorStops = shape.fillRadialGradientColorStops();
+
+// create a radial gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillRadialGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill radial gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point
+var endPoint = shape.fillRadialGradientEndPoint();
+
+// set fill radial gradient end point
+shape.fillRadialGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point x
+var endPointX = shape.fillRadialGradientEndPointX();
+
+// set fill radial gradient end point x
+shape.fillRadialGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point y
+var endPointY = shape.fillRadialGradientEndPointY();
+
+// set fill radial gradient end point y
+shape.fillRadialGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient end radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient end radius
+var endRadius = shape.fillRadialGradientEndRadius();
+
+// set radial gradient end radius
+shape.fillRadialGradientEndRadius(100);
+ + + +
+ + + +
+
+

fillRadialGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill radial gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point
+var startPoint = shape.fillRadialGradientStartPoint();
+
+// set fill radial gradient start point
+shape.fillRadialGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point x
+var startPointX = shape.fillRadialGradientStartPointX();
+
+// set fill radial gradient start point x
+shape.fillRadialGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point y
+var startPointY = shape.fillRadialGradientStartPointY();
+
+// set fill radial gradient start point y
+shape.fillRadialGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient start radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient start radius
+var startRadius = shape.fillRadialGradientStartRadius();
+
+// set radial gradient start radius
+shape.fillRadialGradientStartRadius(0);
+ + + +
+ + + +
+
+

fillRule(rotation)

+ + +
+
+ + +
+

get/set fill rule

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +CanvasFillRule + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill rule
+var fillRule = shape.fillRule();
+
+// set fill rule
+shape.fillRule('evenodd');
+ + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getSelfRect()

+ + +
+
+ + +
+

return self rectangle (x, y, width, height) of shape.
+This method are not taken into account transformation and styles.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
rect.getSelfRect();  // return {x:0, y:0, width:rect.width(), height:rect.height()}
+circle.getSelfRect();  // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasFill()

+ + +
+
+ + +
+

returns whether or not the shape will be filled

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

hasShadow()

+ + +
+
+ + +
+

returns whether or not a shadow will be rendered

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasStroke()

+ + +
+
+ + +
+

returns whether or not the shape will be stroked

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitFunc(drawFunc)

+ + +
+
+ + +
+

get/set hit draw function. That function is used to draw custom hit area of a shape.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get hit draw function
+var hitFunc = shape.hitFunc();
+
+// set hit draw function
+shape.hitFunc(function(context) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

hitStrokeWidth(hitStrokeWidth)

+ + +
+
+ + +
+

get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var hitStrokeWidth = shape.hitStrokeWidth();
+
+// set hit stroke width
+shape.hitStrokeWidth(20);
+// set hit stroke width always equals to scene stroke width
+shape.hitStrokeWidth('auto');
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

image(image)

+ + +
+
+ + +
+

get/set image source. It can be image, canvas or video element

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Object + + + + +

source

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get value
+var image = shape.image();
+
+// set value
+shape.image(img);
+ + + +
+ + + +
+
+

intersects(point)

+ + +
+
+ + +
+

determines if point is in the shape, regardless if other shapes are on top of it. Note: because
+this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
+consecutively. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

linearLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set stroke linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point x
+var startPointX = shape.strokeLinearGradientStartPointX();
+
+// set stroke linear gradient start point x
+shape.strokeLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

lineCap(lineCap)

+ + +
+
+ + +
+

get/set line cap. Can be butt, round, or square

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineCap + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line cap
+var lineCap = shape.lineCap();
+
+// set line cap
+shape.lineCap('round');
+ + + +
+ + + +
+
+

lineJoin(lineJoin)

+ + +
+
+ + +
+

get/set line join. Can be miter, round, or bevel. The
+default is miter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineJoin + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line join
+var lineJoin = shape.lineJoin();
+
+// set line join
+shape.lineJoin('round');
+ + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

perfectDrawEnabled(perfectDrawEnabled)

+ + +
+
+ + +
+

get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set perfectDrawEnabled to false to improve performance.
+See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
perfectDrawEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get perfectDrawEnabled
+var perfectDrawEnabled = shape.perfectDrawEnabled();
+
+// set perfectDrawEnabled
+shape.perfectDrawEnabled();
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

sceneFunc(drawFunc)

+ + +
+
+ + +
+

get/set scene draw function. That function is used to draw the shape on a canvas.
+Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get scene draw function
+var sceneFunc = shape.sceneFunc();
+
+// set scene draw function
+shape.sceneFunc(function(context, shape) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  // like stroke and fill
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

shadowBlur(blur)

+ + +
+
+ + +
+

get/set shadow blur

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blur + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow blur
+var shadowBlur = shape.shadowBlur();
+
+// set shadow blur
+shape.shadowBlur(10);
+ + + +
+ + + +
+
+

shadowColor(color)

+ + +
+
+ + +
+

get/set shadow color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get shadow color
+var shadow = shape.shadowColor();
+
+// set shadow color with color string
+shape.shadowColor('green');
+
+// set shadow color with hex
+shape.shadowColor('#00ff00');
+
+// set shadow color with rgb
+shape.shadowColor('rgb(0,255,0)');
+
+// set shadow color with rgba and make it 50% opaque
+shape.shadowColor('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

shadowEnabled(enabled)

+ + +
+
+ + +
+

get/set shadow enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadow enabled flag
+var shadowEnabled = shape.shadowEnabled();
+
+// disable shadow
+shape.shadowEnabled(false);
+
+// enable shadow
+shape.shadowEnabled(true);
+ + + +
+ + + +
+
+

shadowForStrokeEnabled(shadowForStrokeEnabled)

+ + +
+
+ + +
+

get/set shadowForStrokeEnabled. Useful for performance optimization.
+You may set shape.shadowForStrokeEnabled(false). In this case stroke will no effect shadow.
+Remember if you set shadowForStrokeEnabled = false for non closed line - that line will have no shadow!.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shadowForStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadowForStrokeEnabled
+var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
+
+// set shadowForStrokeEnabled
+shape.shadowForStrokeEnabled();
+ + + +
+ + + +
+
+

shadowOffset(offset)

+ + +
+
+ + +
+

get/set shadow offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get shadow offset
+var shadowOffset = shape.shadowOffset();
+
+// set shadow offset
+shape.shadowOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

shadowOffsetX(x)

+ + +
+
+ + +
+

get/set shadow offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset x
+var shadowOffsetX = shape.shadowOffsetX();
+
+// set shadow offset x
+shape.shadowOffsetX(5);
+ + + +
+ + + +
+
+

shadowOffsetY(y)

+ + +
+
+ + +
+

get/set shadow offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset y
+var shadowOffsetY = shape.shadowOffsetY();
+
+// set shadow offset y
+shape.shadowOffsetY(5);
+ + + +
+ + + +
+
+

shadowOpacity(opacity)

+ + +
+
+ + +
+

get/set shadow opacity. must be a value between 0 and 1

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow opacity
+var shadowOpacity = shape.shadowOpacity();
+
+// set shadow opacity
+shape.shadowOpacity(0.5);
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke(color)

+ + +
+
+ + +
+

get/set stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get stroke color
+var stroke = shape.stroke();
+
+// set stroke color with color string
+shape.stroke('green');
+
+// set stroke color with hex
+shape.stroke('#00ff00');
+
+// set stroke color with rgb
+shape.stroke('rgb(0,255,0)');
+
+// set stroke color with rgba and make it 50% opaque
+shape.stroke('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

strokeEnabled(enabled)

+ + +
+
+ + +
+

get/set stroke enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke enabled flag
+var strokeEnabled = shape.strokeEnabled();
+
+// disable stroke
+shape.strokeEnabled(false);
+
+// enable stroke
+shape.strokeEnabled(true);
+ + + +
+ + + +
+
+

strokeHitEnabled(strokeHitEnabled)

+ + +
+
+ + +
+

deprecated, use hitStrokeWidth instead! get/set strokeHitEnabled property. Useful for performance optimization.
+You may set shape.strokeHitEnabled(false). In this case stroke will be no draw on hit canvas, so hit area
+of shape will be decreased (by lineWidth / 2). Remember that non closed line with strokeHitEnabled = false
+will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
+Default value is true.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeHitEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get strokeHitEnabled
+var strokeHitEnabled = shape.strokeHitEnabled();
+
+// set strokeHitEnabled
+shape.strokeHitEnabled();
+ + + +
+ + + +
+
+

strokeLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set stroke linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient color stops
+var colorStops = shape.strokeLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point
+var endPoint = shape.strokeLinearGradientEndPoint();
+
+// set stroke linear gradient end point
+shape.strokeLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point x
+var endPointX = shape.strokeLinearGradientEndPointX();
+
+// set stroke linear gradient end point x
+shape.strokeLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point y
+var endPointY = shape.strokeLinearGradientEndPointY();
+
+// set stroke linear gradient end point y
+shape.strokeLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

strokeLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point
+var startPoint = shape.strokeLinearGradientStartPoint();
+
+// set stroke linear gradient start point
+shape.strokeLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point y
+var startPointY = shape.strokeLinearGradientStartPointY();
+
+// set stroke linear gradient start point y
+shape.strokeLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

strokeScaleEnabled(enabled)

+ + +
+
+ + +
+

get/set strokeScale enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke scale enabled flag
+var strokeScaleEnabled = shape.strokeScaleEnabled();
+
+// disable stroke scale
+shape.strokeScaleEnabled(false);
+
+// enable stroke scale
+shape.strokeScaleEnabled(true);
+ + + +
+ + + +
+
+

strokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var strokeWidth = shape.strokeWidth();
+
+// set stroke width
+shape.strokeWidth(10);
+ + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Label.html b/api/Konva.Label.html new file mode 100644 index 000000000..fd9d41bc9 --- /dev/null +++ b/api/Konva.Label.html @@ -0,0 +1,1348 @@ + + + + + + + Konva Class: Label + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Label

+
+ +
+ +

+ Konva~ + + Label +

+ +

Label constructor.  Labels are groups that contain a Text and Tag shape

+ + +
+ + +
+
+ + +
+
+

new Label(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
// create label
+var label = new Konva.Label({
+  x: 100,
+  y: 100,
+  draggable: true
+});
+
+// add a tag to the label
+label.add(new Konva.Tag({
+  fill: '#bbb',
+  stroke: '#333',
+  shadowColor: 'black',
+  shadowBlur: 10,
+  shadowOffset: [10, 10],
+  shadowOpacity: 0.2,
+  lineJoin: 'round',
+  pointerDirection: 'up',
+  pointerWidth: 20,
+  pointerHeight: 20,
+  cornerRadius: 5
+}));
+
+// add text to the label
+label.add(new Konva.Text({
+  text: 'Hello World!',
+  fontSize: 50,
+  lineHeight: 1.2,
+  padding: 10,
+  fill: 'green'
+ }));
+ + + +
+ + +
+ + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

getTag()

+ + +
+
+ + +
+

get Tag shape for the label. You need to access the Tag shape in order to update
+the pointer properties and the corner radius

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

getText()

+ + +
+
+ + +
+

get Text shape for the label. You need to access the Text shape in order to update
+the text properties

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
label.getText().fill('red')
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Layer.html b/api/Konva.Layer.html new file mode 100644 index 000000000..077f9c39a --- /dev/null +++ b/api/Konva.Layer.html @@ -0,0 +1,24920 @@ + + + + + + + Konva Class: Layer + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Layer

+
+ +
+ +

+ Konva~ + + Layer +

+ +

Layer constructor. Layers are tied to their own canvas element and are used
+to contain groups or shapes.

+ + +
+ + +
+
+ + +
+
+

new Layer(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
clearBeforeDraw + + +Boolean + + + + + + + <optional>
+ + + + + +

set this property to false if you don't want
+to clear the canvas before each layer draw. The default value is true.

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
    +
  • @param {Object} [config.clip] set clip
  • +
clipX + + +Number + + + + + + + <optional>
+ + + + + +

set clip x

clipY + + +Number + + + + + + + <optional>
+ + + + + +

set clip y

clipWidth + + +Number + + + + + + + <optional>
+ + + + + +

set clip width

clipHeight + + +Number + + + + + + + <optional>
+ + + + + +

set clip height

clipFunc + + +function + + + + + + + <optional>
+ + + + + +

set clip func

+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var layer = new Konva.Layer();
+stage.add(layer);
+// now you can add shapes, groups into the layer
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

add(children)

+ + +
+
+ + +
+

add a child and children into container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
children + + +Konva.Node + + + + + + + + + + + <repeatable>
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Container + + + +
+
+ + + + + +
Example
+ +
layer.add(rect);
+layer.add(shape1, shape2, shape3);
+// empty arrays are accepted, though each individual child must be defined
+layer.add(...shapes);
+// remember to redraw layer if you changed something
+layer.draw();
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

batchDraw()

+ + +
+
+ + +
+

batch draw. this function will not do immediate draw
+but it will schedule drawing to next tick (requestAnimFrame)

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearBeforeDraw(clearBeforeDraw)

+ + +
+
+ + +
+

get/set clearBeforeDraw flag which determines if the layer is cleared or not
+before drawing

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
clearBeforeDraw + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get clearBeforeDraw flag
+var clearBeforeDraw = layer.clearBeforeDraw();
+
+// disable clear before draw
+layer.clearBeforeDraw(false);
+
+// enable clear before draw
+layer.clearBeforeDraw(true);
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clip(clip)

+ + +
+
+ + +
+

get/set clip

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
clip + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get clip
+var clip = container.clip();
+
+// set clip
+container.clip({
+  x: 20,
+  y: 20,
+  width: 20,
+  height: 20
+});
+ + + +
+ + + +
+
+

clipFunc(function)

+ + +
+
+ + +
+

get/set clip function

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
function + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get clip function
+var clipFunction = container.clipFunc();
+
+// set clip function
+container.clipFunc(function(ctx) {
+  ctx.rect(0, 0, 100, 100);
+});
+
+container.clipFunc(function(ctx) {
+  // optionally return a clip Path2D and clip-rule or just the clip-rule
+  return [new Path2D('M0 0v50h50Z'), 'evenodd']
+});
+ + + +
+ + + +
+
+

clipHeight(height)

+ + +
+
+ + +
+

get/set clip height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clip height
+var clipHeight = container.clipHeight();
+
+// set clip height
+container.clipHeight(100);
+ + + +
+ + + +
+
+

clipWidth(width)

+ + +
+
+ + +
+

get/set clip width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clip width
+var clipWidth = container.clipWidth();
+
+// set clip width
+container.clipWidth(100);
+ + + +
+ + + +
+
+

clipX(x)

+ + +
+
+ + +
+

get/set clip x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clip x
+var clipX = container.clipX();
+
+// set clip x
+container.clipX(10);
+ + + +
+ + + +
+
+

clipY(y)

+ + +
+
+ + +
+

get/set clip y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clip y
+var clipY = container.clipY();
+
+// set clip y
+container.clipY(10);
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

destroyChildren()

+ + +
+
+ + +
+

destroy all children nodes.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

disableHitGraph()

+ + +
+
+ + +
+

disable hit graph. DEPRECATED! Use layer.listening(false) instead.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Layer + + + +
+
+ + + + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enableHitGraph()

+ + +
+
+ + +
+

enable hit graph. DEPRECATED! Use layer.listening(true) instead.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Layer + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

find(selector)

+ + +
+
+ + +
+

return an array of nodes that match the selector.
+You can provide a string with '#' for id selections and '.' for name selections.
+Or a function that will return true/false when a node is passed through. See example below.
+With strings you can also select by type or class name. Pass multiple selectors
+separated by a comma.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
selector + + +String +| + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
Passing a string as a selector
+// select node with id foo
+var node = stage.find('#foo');
+
+// select nodes with name bar inside layer
+var nodes = layer.find('.bar');
+
+// select all groups inside layer
+var nodes = layer.find('Group');
+
+// select all rectangles inside layer
+var nodes = layer.find('Rect');
+
+// select node with an id of foo or a name of bar inside layer
+var nodes = layer.find('#foo, .bar');
+
+Passing a function as a selector
+
+// get all groups with a function
+var groups = stage.find(node => {
+ return node.getType() === 'Group';
+});
+
+// get only Nodes with partial opacity
+var alphaNodes = layer.find(node => {
+ return node.getType() === 'Node' && node.getAbsoluteOpacity() < 1;
+});
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

findOne(selector)

+ + +
+
+ + +
+

return a first node from find method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
selector + + +String +| + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node +| + +Undefined + + + +
+
+ + + + + +
Example
+ +
// select node with id foo
+var node = stage.findOne('#foo');
+
+// select node with name bar inside layer
+var nodes = layer.findOne('.bar');
+
+// select the first node to return true in a function
+var node = stage.findOne(node => {
+ return node.getType() === 'Shape'
+})
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAllIntersections(pos)

+ + +
+
+ + +
+

get all shapes that intersect a point. Note: because this method must clear a temporary
+canvas and redraw every shape inside the container, it should only be used for special situations
+because it performs very poorly. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better
+nodes with listening set to false will not be detected

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

array of shapes

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getCanvas()

+ + +
+
+ + +
+

get layer canvas wrapper

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

getChildren( [filterFunc])

+ + +
+
+ + +
+

returns an array of direct descendant nodes

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
filterFunc + + +function + + + + + + + <optional>
+ + + + + +

filter function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get all children
+var children = layer.getChildren();
+
+// get only circles
+var circles = layer.getChildren(function(node){
+   return node.getClassName() === 'Circle';
+});
+ + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getContext()

+ + +
+
+ + +
+

get layer canvas context

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getHitCanvas()

+ + +
+
+ + +
+

get layer hit canvas

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

getIntersection(pos)

+ + +
+
+ + +
+

get visible intersection shape. This is the preferred
+method for determining if a point intersects a shape or not
+also you may pass optional selector parameter to return ancestor of intersected shape
+nodes with listening set to false will not be detected

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
var shape = layer.getIntersection({x: 50, y: 50});
+ + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getNativeCanvasElement()

+ + +
+
+ + +
+

get native canvas element

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasChildren()

+ + +
+
+ + +
+

determine if node has children

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

height()

+ + +
+
+ + +
+

get/set height of layer.getter return height of stage. setter doing nothing.
+if you want change height use stage.height(value);

+
+ + + + + + + + + + +
+ + + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
var height = layer.height();
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitGraphEnabled(enabled)

+ + +
+
+ + +
+

get/set hitGraphEnabled flag. DEPRECATED! Use layer.listening(false) instead.
+Disabling the hit graph will greatly increase
+draw performance because the hit graph will not be redrawn each time the layer is
+drawn. This, however, also disables mouse/touch event detection

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get hitGraphEnabled flag
+var hitGraphEnabled = layer.hitGraphEnabled();
+
+// disable hit graph
+layer.hitGraphEnabled(false);
+
+// enable hit graph
+layer.hitGraphEnabled(true);
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

imageSmoothingEnabled(imageSmoothingEnabled)

+ + +
+
+ + +
+

get/set imageSmoothingEnabled flag
+For more info see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/imageSmoothingEnabled

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
imageSmoothingEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get imageSmoothingEnabled flag
+var imageSmoothingEnabled = layer.imageSmoothingEnabled();
+
+layer.imageSmoothingEnabled(false);
+
+layer.imageSmoothingEnabled(true);
+ + + +
+ + + +
+
+

isAncestorOf(node)

+ + +
+
+ + +
+

determine if node is an ancestor
+of descendant

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
node + + +Konva.Node + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeChildren()

+ + +
+
+ + +
+

remove all children. Children will be still in memory.
+If you want to completely destroy all children please use "destroyChildren" method instead

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toggleHitCanvas()

+ + +
+
+ + +
+

Show or hide hit canvas over the stage. May be useful for debugging custom hitFunc

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width()

+ + +
+
+ + +
+

get/set width of layer. getter return width of stage. setter doing nothing.
+if you want change width use stage.width(value);

+
+ + + + + + + + + + +
+ + + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
var width = layer.width();
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Line.html b/api/Konva.Line.html new file mode 100644 index 000000000..981444be6 --- /dev/null +++ b/api/Konva.Line.html @@ -0,0 +1,35496 @@ + + + + + + + Konva Class: Line + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Line

+
+ +
+ +

+ Konva~ + + Line +

+ +

Line constructor.  Lines are defined by an array of points and
+a tension

+ + +
+ + +
+
+ + +
+
+

new Line(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
points + + +Array + + + + + + + + + + +

Flat array of points coordinates. You should define them as [x1, y1, x2, y2, x3, y3].

tension + + +Number + + + + + + + <optional>
+ + + + + +

Higher values will result in a more curvy line. A value of 0 will result in no interpolation.
+The default is 0

closed + + +Boolean + + + + + + + <optional>
+ + + + + +

defines whether or not the line shape is closed, creating a polygon or blob

bezier + + +Boolean + + + + + + + <optional>
+ + + + + +

if no tension is provided but bezier=true, we draw the line as a bezier using the passed points

fill + + +String + + + + + + + <optional>
+ + + + + +

fill color

fillPatternImage + + +Image + + + + + + + <optional>
+ + + + + +

fill pattern image

fillPatternX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScale + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternScaleX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScaleY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRotation + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRepeat + + +String + + + + + + + <optional>
+ + + + + +

can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"

fillLinearGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillRadialGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the fill. The default value is true

fillPriority + + +String + + + + + + + <optional>
+ + + + + +

can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration

stroke + + +String + + + + + + + <optional>
+ + + + + +

stroke color

strokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

stroke width

fillAfterStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw fill AFTER stroke? Default is false.

hitStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth

strokeHitEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke hit region. The default is true

perfectDrawEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables using buffer canvas. The default is true

shadowForStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables shadow for stroke. The default is true

strokeScaleEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke scale. The default is true

strokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the stroke. The default value is true

lineJoin + + +String + + + + + + + <optional>
+ + + + + +

can be miter, round, or bevel. The default
+is miter

lineCap + + +String + + + + + + + <optional>
+ + + + + +

can be butt, round, or square. The default
+is butt

shadowColor + + +String + + + + + + + <optional>
+ + + + + +
shadowBlur + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

shadowOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
shadowOpacity + + +Number + + + + + + + <optional>
+ + + + + +

shadow opacity. Can be any real number
+between 0 and 1

shadowEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the shadow. The default value is true

dash + + +Array + + + + + + + <optional>
+ + + + + +
dashEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the dashArray. The default value is true

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var line = new Konva.Line({
+  x: 100,
+  y: 50,
+  points: [73, 70, 340, 23, 450, 60, 500, 20],
+  stroke: 'red',
+  tension: 1
+});
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

bezier(bezier)

+ + +
+
+ + +
+

get/set bezier flag. The default is false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bezier + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get whether the line is a bezier
+var isBezier = line.bezier();
+
+// set whether the line is a bezier
+line.bezier(true);
+ + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

closed(closed)

+ + +
+
+ + +
+

get/set closed flag. The default is false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
closed + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get closed flag
+var closed = line.closed();
+
+// close the shape
+line.closed(true);
+
+// open the shape
+line.closed(false);
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash array for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart
+ line.dash([10, 5]);
+ // apply dashed stroke that is made up of alternating dashed
+ // lines that are 10px long and 20px apart, and dots that have
+ // a radius of 5px and are 20px apart
+ line.dash([10, 20, 0.001, 20]);
+ + + +
+ + + +
+
+

dashEnabled(enabled)

+ + +
+
+ + +
+

get/set dash enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get dash enabled flag
+var dashEnabled = shape.dashEnabled();
+
+// disable dash
+shape.dashEnabled(false);
+
+// enable dash
+shape.dashEnabled(true);
+ + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

drawHitFromCache(alphaThreshold)

+ + +
+
+ + +
+

draw hit graph using the cached scene canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alphaThreshold + + +Integer + + + + +

alpha channel threshold that determines whether or not
+a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
+The default is 0

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
shape.cache();
+shape.drawHitFromCache();
+ + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

fill(color)

+ + +
+
+ + +
+

get/set fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill color
+var fill = shape.fill();
+
+// set fill color with color string
+shape.fill('green');
+
+// set fill color with hex
+shape.fill('#00ff00');
+
+// set fill color with rgb
+shape.fill('rgb(0,255,0)');
+
+// set fill color with rgba and make it 50% opaque
+shape.fill('rgba(0,255,0,0.5');
+
+// shape without fill
+shape.fill(null);
+ + + +
+ + + +
+
+

fillAfterStrokeEnabled(fillAfterStrokeEnabled)

+ + +
+
+ + +
+

get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
+In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
+Especially useful for Text objects.
+Default is false.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fillAfterStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
+
+// set stroke width
+shape.fillAfterStrokeEnabled(true);
+ + + +
+ + + +
+
+

fillEnabled(enabled)

+ + +
+
+ + +
+

get/set fill enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get fill enabled flag
+var fillEnabled = shape.fillEnabled();
+
+// disable fill
+shape.fillEnabled(false);
+
+// enable fill
+shape.fillEnabled(true);
+ + + +
+ + + +
+
+

fillLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient color stops
+var colorStops = shape.fillLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point
+var endPoint = shape.fillLinearGradientEndPoint();
+
+// set fill linear gradient end point
+shape.fillLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point x
+var endPointX = shape.fillLinearGradientEndPointX();
+
+// set fill linear gradient end point x
+shape.fillLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point y
+var endPointY = shape.fillLinearGradientEndPointY();
+
+// set fill linear gradient end point y
+shape.fillLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point
+var startPoint = shape.fillLinearGradientStartPoint();
+
+// set fill linear gradient start point
+shape.fillLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point x
+var startPointX = shape.fillLinearGradientStartPointX();
+
+// set fill linear gradient start point x
+shape.fillLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point y
+var startPointY = shape.fillLinearGradientStartPointY();
+
+// set fill linear gradient start point y
+shape.fillLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillPatternImage(image)

+ + +
+
+ + +
+

get/set fill pattern image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +

object

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get fill pattern image
+var fillPatternImage = shape.fillPatternImage();
+
+// set fill pattern image
+var imageObj = new Image();
+imageObj.onload = function() {
+  shape.fillPatternImage(imageObj);
+};
+imageObj.src = 'path/to/image/jpg';
+ + + +
+ + + +
+
+

fillPatternOffset(offset)

+ + +
+
+ + +
+

get/set fill pattern offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset
+var patternOffset = shape.fillPatternOffset();
+
+// set fill pattern offset
+shape.fillPatternOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillPatternOffsetX(x)

+ + +
+
+ + +
+

get/set fill pattern offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset x
+var patternOffsetX = shape.fillPatternOffsetX();
+
+// set fill pattern offset x
+shape.fillPatternOffsetX(20);
+ + + +
+ + + +
+
+

fillPatternOffsetY(y)

+ + +
+
+ + +
+

get/set fill pattern offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset y
+var patternOffsetY = shape.fillPatternOffsetY();
+
+// set fill pattern offset y
+shape.fillPatternOffsetY(10);
+ + + +
+ + + +
+
+

fillPatternRepeat(repeat)

+ + +
+
+ + +
+

get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
repeat + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill pattern repeat
+var repeat = shape.fillPatternRepeat();
+
+// repeat pattern in x direction only
+shape.fillPatternRepeat('repeat-x');
+
+// do not repeat the pattern
+shape.fillPatternRepeat('no-repeat');
+ + + +
+ + + +
+
+

fillPatternRotation(rotation)

+ + +
+
+ + +
+

get/set fill pattern rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill pattern rotation
+var patternRotation = shape.fillPatternRotation();
+
+// set fill pattern rotation
+shape.fillPatternRotation(20);
+ + + +
+ + + +
+
+

fillPatternScale(scale)

+ + +
+
+ + +
+

get/set fill pattern scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale
+var patternScale = shape.fillPatternScale();
+
+// set fill pattern scale
+shape.fillPatternScale({
+  x: 2,
+  y: 2
+});
+ + + +
+ + + +
+
+

fillPatternScaleX(x)

+ + +
+
+ + +
+

get/set fill pattern scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale x
+var patternScaleX = shape.fillPatternScaleX();
+
+// set fill pattern scale x
+shape.fillPatternScaleX(2);
+ + + +
+ + + +
+
+

fillPatternScaleY(y)

+ + +
+
+ + +
+

get/set fill pattern scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale y
+var patternScaleY = shape.fillPatternScaleY();
+
+// set fill pattern scale y
+shape.fillPatternScaleY(2);
+ + + +
+ + + +
+
+

fillPatternX(x)

+ + +
+
+ + +
+

get/set fill pattern x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern x
+var fillPatternX = shape.fillPatternX();
+// set fill pattern x
+shape.fillPatternX(20);
+ + + +
+ + + +
+
+

fillPatternY(y)

+ + +
+
+ + +
+

get/set fill pattern y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern y
+var fillPatternY = shape.fillPatternY();
+// set fill pattern y
+shape.fillPatternY(20);
+ + + +
+ + + +
+
+

fillPriority(priority)

+ + +
+
+ + +
+

get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
+This is handy if you want to toggle between different fill types.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
priority + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill priority
+var fillPriority = shape.fillPriority();
+
+// set fill priority
+shape.fillPriority('linear-gradient');
+ + + +
+ + + +
+
+

fillRadialGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill radial gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient color stops
+var colorStops = shape.fillRadialGradientColorStops();
+
+// create a radial gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillRadialGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill radial gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point
+var endPoint = shape.fillRadialGradientEndPoint();
+
+// set fill radial gradient end point
+shape.fillRadialGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point x
+var endPointX = shape.fillRadialGradientEndPointX();
+
+// set fill radial gradient end point x
+shape.fillRadialGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point y
+var endPointY = shape.fillRadialGradientEndPointY();
+
+// set fill radial gradient end point y
+shape.fillRadialGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient end radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient end radius
+var endRadius = shape.fillRadialGradientEndRadius();
+
+// set radial gradient end radius
+shape.fillRadialGradientEndRadius(100);
+ + + +
+ + + +
+
+

fillRadialGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill radial gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point
+var startPoint = shape.fillRadialGradientStartPoint();
+
+// set fill radial gradient start point
+shape.fillRadialGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point x
+var startPointX = shape.fillRadialGradientStartPointX();
+
+// set fill radial gradient start point x
+shape.fillRadialGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point y
+var startPointY = shape.fillRadialGradientStartPointY();
+
+// set fill radial gradient start point y
+shape.fillRadialGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient start radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient start radius
+var startRadius = shape.fillRadialGradientStartRadius();
+
+// set radial gradient start radius
+shape.fillRadialGradientStartRadius(0);
+ + + +
+ + + +
+
+

fillRule(rotation)

+ + +
+
+ + +
+

get/set fill rule

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +CanvasFillRule + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill rule
+var fillRule = shape.fillRule();
+
+// set fill rule
+shape.fillRule('evenodd');
+ + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getSelfRect()

+ + +
+
+ + +
+

return self rectangle (x, y, width, height) of shape.
+This method are not taken into account transformation and styles.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
rect.getSelfRect();  // return {x:0, y:0, width:rect.width(), height:rect.height()}
+circle.getSelfRect();  // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasFill()

+ + +
+
+ + +
+

returns whether or not the shape will be filled

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

hasShadow()

+ + +
+
+ + +
+

returns whether or not a shadow will be rendered

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasStroke()

+ + +
+
+ + +
+

returns whether or not the shape will be stroked

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitFunc(drawFunc)

+ + +
+
+ + +
+

get/set hit draw function. That function is used to draw custom hit area of a shape.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get hit draw function
+var hitFunc = shape.hitFunc();
+
+// set hit draw function
+shape.hitFunc(function(context) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

hitStrokeWidth(hitStrokeWidth)

+ + +
+
+ + +
+

get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var hitStrokeWidth = shape.hitStrokeWidth();
+
+// set hit stroke width
+shape.hitStrokeWidth(20);
+// set hit stroke width always equals to scene stroke width
+shape.hitStrokeWidth('auto');
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

intersects(point)

+ + +
+
+ + +
+

determines if point is in the shape, regardless if other shapes are on top of it. Note: because
+this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
+consecutively. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

linearLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set stroke linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point x
+var startPointX = shape.strokeLinearGradientStartPointX();
+
+// set stroke linear gradient start point x
+shape.strokeLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

lineCap(lineCap)

+ + +
+
+ + +
+

get/set line cap. Can be butt, round, or square

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineCap + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line cap
+var lineCap = shape.lineCap();
+
+// set line cap
+shape.lineCap('round');
+ + + +
+ + + +
+
+

lineJoin(lineJoin)

+ + +
+
+ + +
+

get/set line join. Can be miter, round, or bevel. The
+default is miter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineJoin + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line join
+var lineJoin = shape.lineJoin();
+
+// set line join
+shape.lineJoin('round');
+ + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

perfectDrawEnabled(perfectDrawEnabled)

+ + +
+
+ + +
+

get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set perfectDrawEnabled to false to improve performance.
+See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
perfectDrawEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get perfectDrawEnabled
+var perfectDrawEnabled = shape.perfectDrawEnabled();
+
+// set perfectDrawEnabled
+shape.perfectDrawEnabled();
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

points(points)

+ + +
+
+ + +
+

get/set points array. Points is a flat array [x1, y1, x2, y2]. It is flat for performance reasons.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
points + + +Array + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get points
+var points = line.points();
+
+// set points
+line.points([10, 20, 30, 40, 50, 60]);
+
+// push a new point
+line.points(line.points().concat([70, 80]));
+ + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

sceneFunc(drawFunc)

+ + +
+
+ + +
+

get/set scene draw function. That function is used to draw the shape on a canvas.
+Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get scene draw function
+var sceneFunc = shape.sceneFunc();
+
+// set scene draw function
+shape.sceneFunc(function(context, shape) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  // like stroke and fill
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

shadowBlur(blur)

+ + +
+
+ + +
+

get/set shadow blur

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blur + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow blur
+var shadowBlur = shape.shadowBlur();
+
+// set shadow blur
+shape.shadowBlur(10);
+ + + +
+ + + +
+
+

shadowColor(color)

+ + +
+
+ + +
+

get/set shadow color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get shadow color
+var shadow = shape.shadowColor();
+
+// set shadow color with color string
+shape.shadowColor('green');
+
+// set shadow color with hex
+shape.shadowColor('#00ff00');
+
+// set shadow color with rgb
+shape.shadowColor('rgb(0,255,0)');
+
+// set shadow color with rgba and make it 50% opaque
+shape.shadowColor('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

shadowEnabled(enabled)

+ + +
+
+ + +
+

get/set shadow enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadow enabled flag
+var shadowEnabled = shape.shadowEnabled();
+
+// disable shadow
+shape.shadowEnabled(false);
+
+// enable shadow
+shape.shadowEnabled(true);
+ + + +
+ + + +
+
+

shadowForStrokeEnabled(shadowForStrokeEnabled)

+ + +
+
+ + +
+

get/set shadowForStrokeEnabled. Useful for performance optimization.
+You may set shape.shadowForStrokeEnabled(false). In this case stroke will no effect shadow.
+Remember if you set shadowForStrokeEnabled = false for non closed line - that line will have no shadow!.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shadowForStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadowForStrokeEnabled
+var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
+
+// set shadowForStrokeEnabled
+shape.shadowForStrokeEnabled();
+ + + +
+ + + +
+
+

shadowOffset(offset)

+ + +
+
+ + +
+

get/set shadow offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get shadow offset
+var shadowOffset = shape.shadowOffset();
+
+// set shadow offset
+shape.shadowOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

shadowOffsetX(x)

+ + +
+
+ + +
+

get/set shadow offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset x
+var shadowOffsetX = shape.shadowOffsetX();
+
+// set shadow offset x
+shape.shadowOffsetX(5);
+ + + +
+ + + +
+
+

shadowOffsetY(y)

+ + +
+
+ + +
+

get/set shadow offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset y
+var shadowOffsetY = shape.shadowOffsetY();
+
+// set shadow offset y
+shape.shadowOffsetY(5);
+ + + +
+ + + +
+
+

shadowOpacity(opacity)

+ + +
+
+ + +
+

get/set shadow opacity. must be a value between 0 and 1

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow opacity
+var shadowOpacity = shape.shadowOpacity();
+
+// set shadow opacity
+shape.shadowOpacity(0.5);
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke(color)

+ + +
+
+ + +
+

get/set stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get stroke color
+var stroke = shape.stroke();
+
+// set stroke color with color string
+shape.stroke('green');
+
+// set stroke color with hex
+shape.stroke('#00ff00');
+
+// set stroke color with rgb
+shape.stroke('rgb(0,255,0)');
+
+// set stroke color with rgba and make it 50% opaque
+shape.stroke('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

strokeEnabled(enabled)

+ + +
+
+ + +
+

get/set stroke enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke enabled flag
+var strokeEnabled = shape.strokeEnabled();
+
+// disable stroke
+shape.strokeEnabled(false);
+
+// enable stroke
+shape.strokeEnabled(true);
+ + + +
+ + + +
+
+

strokeHitEnabled(strokeHitEnabled)

+ + +
+
+ + +
+

deprecated, use hitStrokeWidth instead! get/set strokeHitEnabled property. Useful for performance optimization.
+You may set shape.strokeHitEnabled(false). In this case stroke will be no draw on hit canvas, so hit area
+of shape will be decreased (by lineWidth / 2). Remember that non closed line with strokeHitEnabled = false
+will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
+Default value is true.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeHitEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get strokeHitEnabled
+var strokeHitEnabled = shape.strokeHitEnabled();
+
+// set strokeHitEnabled
+shape.strokeHitEnabled();
+ + + +
+ + + +
+
+

strokeLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set stroke linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient color stops
+var colorStops = shape.strokeLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point
+var endPoint = shape.strokeLinearGradientEndPoint();
+
+// set stroke linear gradient end point
+shape.strokeLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point x
+var endPointX = shape.strokeLinearGradientEndPointX();
+
+// set stroke linear gradient end point x
+shape.strokeLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point y
+var endPointY = shape.strokeLinearGradientEndPointY();
+
+// set stroke linear gradient end point y
+shape.strokeLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

strokeLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point
+var startPoint = shape.strokeLinearGradientStartPoint();
+
+// set stroke linear gradient start point
+shape.strokeLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point y
+var startPointY = shape.strokeLinearGradientStartPointY();
+
+// set stroke linear gradient start point y
+shape.strokeLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

strokeScaleEnabled(enabled)

+ + +
+
+ + +
+

get/set strokeScale enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke scale enabled flag
+var strokeScaleEnabled = shape.strokeScaleEnabled();
+
+// disable stroke scale
+shape.strokeScaleEnabled(false);
+
+// enable stroke scale
+shape.strokeScaleEnabled(true);
+ + + +
+ + + +
+
+

strokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var strokeWidth = shape.strokeWidth();
+
+// set stroke width
+shape.strokeWidth(10);
+ + + +
+ + + +
+
+

tension(tension)

+ + +
+
+ + +
+

get/set tension

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tension + + +Number + + + + +

Higher values will result in a more curvy line. A value of 0 will result in no interpolation. The default is 0

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get tension
+var tension = line.tension();
+
+// set tension
+line.tension(3);
+ + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Node.html b/api/Konva.Node.html new file mode 100644 index 000000000..1627afa7d --- /dev/null +++ b/api/Konva.Node.html @@ -0,0 +1,20111 @@ + + + + + + + Konva Class: Node + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Node

+
+ +
+ +

+ Konva~ + + Node +

+ +

Node constructor. Nodes are entities that can be transformed, layered,
+and have bound events. The stage, layers, groups, and shapes all extend Node.

+ + +
+ + +
+
+ + +
+
+

new Node(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + +
+ + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

<static> Node.create(json [, container])

+ + +
+
+ + +
+

create node with JSON string or an Object. De-serializtion does not generate custom
+shape drawing functions, images, or event handlers (this would make the
+serialized object huge). If your app uses custom shapes, images, and
+event handlers (it probably does), then you need to select the appropriate
+shapes after loading the stage and set these properties via on(), setSceneFunc(),
+and setImage() methods

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
json + + +String +| + +Object + + + + + + + + + + +

string or object

container + + +Element + + + + + + + <optional>
+ + + + + +

optional container dom element used only if you're
+creating a stage node

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Path.html b/api/Konva.Path.html new file mode 100644 index 000000000..565f55d2d --- /dev/null +++ b/api/Konva.Path.html @@ -0,0 +1,35184 @@ + + + + + + + Konva Class: Path + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Path

+
+ +
+ +

+ Konva~ + + Path +

+ +

Path constructor.

+ + +
+ + +
+
+ + +
+
+

new Path(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
data + + +String + + + + + + + + + + +

SVG data string

fill + + +String + + + + + + + <optional>
+ + + + + +

fill color

fillPatternImage + + +Image + + + + + + + <optional>
+ + + + + +

fill pattern image

fillPatternX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScale + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternScaleX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScaleY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRotation + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRepeat + + +String + + + + + + + <optional>
+ + + + + +

can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"

fillLinearGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillRadialGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the fill. The default value is true

fillPriority + + +String + + + + + + + <optional>
+ + + + + +

can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration

stroke + + +String + + + + + + + <optional>
+ + + + + +

stroke color

strokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

stroke width

fillAfterStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw fill AFTER stroke? Default is false.

hitStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth

strokeHitEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke hit region. The default is true

perfectDrawEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables using buffer canvas. The default is true

shadowForStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables shadow for stroke. The default is true

strokeScaleEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke scale. The default is true

strokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the stroke. The default value is true

lineJoin + + +String + + + + + + + <optional>
+ + + + + +

can be miter, round, or bevel. The default
+is miter

lineCap + + +String + + + + + + + <optional>
+ + + + + +

can be butt, round, or square. The default
+is butt

shadowColor + + +String + + + + + + + <optional>
+ + + + + +
shadowBlur + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

shadowOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
shadowOpacity + + +Number + + + + + + + <optional>
+ + + + + +

shadow opacity. Can be any real number
+between 0 and 1

shadowEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the shadow. The default value is true

dash + + +Array + + + + + + + <optional>
+ + + + + +
dashEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the dashArray. The default value is true

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + +
Author:
+
+
    +
  • Jason Follas
  • +
+
+ + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var path = new Konva.Path({
+  x: 240,
+  y: 40,
+  data: 'M12.582,9.551C3.251,16.237,0.921,29.021,7.08,38.564l-2.36,1.689l4.893,2.262l4.893,2.262l-0.568-5.36l-0.567-5.359l-2.365,1.694c-4.657-7.375-2.83-17.185,4.352-22.33c7.451-5.338,17.817-3.625,23.156,3.824c5.337,7.449,3.625,17.813-3.821,23.152l2.857,3.988c9.617-6.893,11.827-20.277,4.935-29.896C35.591,4.87,22.204,2.658,12.582,9.551z',
+  fill: 'green',
+  scaleX: 2,
+  scaleY: 2
+});
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash array for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart
+ line.dash([10, 5]);
+ // apply dashed stroke that is made up of alternating dashed
+ // lines that are 10px long and 20px apart, and dots that have
+ // a radius of 5px and are 20px apart
+ line.dash([10, 20, 0.001, 20]);
+ + + +
+ + + +
+
+

dashEnabled(enabled)

+ + +
+
+ + +
+

get/set dash enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get dash enabled flag
+var dashEnabled = shape.dashEnabled();
+
+// disable dash
+shape.dashEnabled(false);
+
+// enable dash
+shape.dashEnabled(true);
+ + + +
+ + + +
+
+

data(data)

+ + +
+
+ + +
+

get/set SVG path data string. This method
+also automatically parses the data string
+into a data array. Currently supported SVG data:
+M, m, L, l, H, h, V, v, Q, q, T, t, C, c, S, s, A, a, Z, z

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
data + + +String + + + + +

svg path string

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get data
+var data = path.data();
+
+// set data
+path.data('M200,100h100v50z');
+ + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

drawHitFromCache(alphaThreshold)

+ + +
+
+ + +
+

draw hit graph using the cached scene canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alphaThreshold + + +Integer + + + + +

alpha channel threshold that determines whether or not
+a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
+The default is 0

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
shape.cache();
+shape.drawHitFromCache();
+ + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

fill(color)

+ + +
+
+ + +
+

get/set fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill color
+var fill = shape.fill();
+
+// set fill color with color string
+shape.fill('green');
+
+// set fill color with hex
+shape.fill('#00ff00');
+
+// set fill color with rgb
+shape.fill('rgb(0,255,0)');
+
+// set fill color with rgba and make it 50% opaque
+shape.fill('rgba(0,255,0,0.5');
+
+// shape without fill
+shape.fill(null);
+ + + +
+ + + +
+
+

fillAfterStrokeEnabled(fillAfterStrokeEnabled)

+ + +
+
+ + +
+

get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
+In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
+Especially useful for Text objects.
+Default is false.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fillAfterStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
+
+// set stroke width
+shape.fillAfterStrokeEnabled(true);
+ + + +
+ + + +
+
+

fillEnabled(enabled)

+ + +
+
+ + +
+

get/set fill enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get fill enabled flag
+var fillEnabled = shape.fillEnabled();
+
+// disable fill
+shape.fillEnabled(false);
+
+// enable fill
+shape.fillEnabled(true);
+ + + +
+ + + +
+
+

fillLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient color stops
+var colorStops = shape.fillLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point
+var endPoint = shape.fillLinearGradientEndPoint();
+
+// set fill linear gradient end point
+shape.fillLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point x
+var endPointX = shape.fillLinearGradientEndPointX();
+
+// set fill linear gradient end point x
+shape.fillLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point y
+var endPointY = shape.fillLinearGradientEndPointY();
+
+// set fill linear gradient end point y
+shape.fillLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point
+var startPoint = shape.fillLinearGradientStartPoint();
+
+// set fill linear gradient start point
+shape.fillLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point x
+var startPointX = shape.fillLinearGradientStartPointX();
+
+// set fill linear gradient start point x
+shape.fillLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point y
+var startPointY = shape.fillLinearGradientStartPointY();
+
+// set fill linear gradient start point y
+shape.fillLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillPatternImage(image)

+ + +
+
+ + +
+

get/set fill pattern image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +

object

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get fill pattern image
+var fillPatternImage = shape.fillPatternImage();
+
+// set fill pattern image
+var imageObj = new Image();
+imageObj.onload = function() {
+  shape.fillPatternImage(imageObj);
+};
+imageObj.src = 'path/to/image/jpg';
+ + + +
+ + + +
+
+

fillPatternOffset(offset)

+ + +
+
+ + +
+

get/set fill pattern offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset
+var patternOffset = shape.fillPatternOffset();
+
+// set fill pattern offset
+shape.fillPatternOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillPatternOffsetX(x)

+ + +
+
+ + +
+

get/set fill pattern offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset x
+var patternOffsetX = shape.fillPatternOffsetX();
+
+// set fill pattern offset x
+shape.fillPatternOffsetX(20);
+ + + +
+ + + +
+
+

fillPatternOffsetY(y)

+ + +
+
+ + +
+

get/set fill pattern offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset y
+var patternOffsetY = shape.fillPatternOffsetY();
+
+// set fill pattern offset y
+shape.fillPatternOffsetY(10);
+ + + +
+ + + +
+
+

fillPatternRepeat(repeat)

+ + +
+
+ + +
+

get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
repeat + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill pattern repeat
+var repeat = shape.fillPatternRepeat();
+
+// repeat pattern in x direction only
+shape.fillPatternRepeat('repeat-x');
+
+// do not repeat the pattern
+shape.fillPatternRepeat('no-repeat');
+ + + +
+ + + +
+
+

fillPatternRotation(rotation)

+ + +
+
+ + +
+

get/set fill pattern rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill pattern rotation
+var patternRotation = shape.fillPatternRotation();
+
+// set fill pattern rotation
+shape.fillPatternRotation(20);
+ + + +
+ + + +
+
+

fillPatternScale(scale)

+ + +
+
+ + +
+

get/set fill pattern scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale
+var patternScale = shape.fillPatternScale();
+
+// set fill pattern scale
+shape.fillPatternScale({
+  x: 2,
+  y: 2
+});
+ + + +
+ + + +
+
+

fillPatternScaleX(x)

+ + +
+
+ + +
+

get/set fill pattern scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale x
+var patternScaleX = shape.fillPatternScaleX();
+
+// set fill pattern scale x
+shape.fillPatternScaleX(2);
+ + + +
+ + + +
+
+

fillPatternScaleY(y)

+ + +
+
+ + +
+

get/set fill pattern scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale y
+var patternScaleY = shape.fillPatternScaleY();
+
+// set fill pattern scale y
+shape.fillPatternScaleY(2);
+ + + +
+ + + +
+
+

fillPatternX(x)

+ + +
+
+ + +
+

get/set fill pattern x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern x
+var fillPatternX = shape.fillPatternX();
+// set fill pattern x
+shape.fillPatternX(20);
+ + + +
+ + + +
+
+

fillPatternY(y)

+ + +
+
+ + +
+

get/set fill pattern y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern y
+var fillPatternY = shape.fillPatternY();
+// set fill pattern y
+shape.fillPatternY(20);
+ + + +
+ + + +
+
+

fillPriority(priority)

+ + +
+
+ + +
+

get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
+This is handy if you want to toggle between different fill types.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
priority + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill priority
+var fillPriority = shape.fillPriority();
+
+// set fill priority
+shape.fillPriority('linear-gradient');
+ + + +
+ + + +
+
+

fillRadialGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill radial gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient color stops
+var colorStops = shape.fillRadialGradientColorStops();
+
+// create a radial gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillRadialGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill radial gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point
+var endPoint = shape.fillRadialGradientEndPoint();
+
+// set fill radial gradient end point
+shape.fillRadialGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point x
+var endPointX = shape.fillRadialGradientEndPointX();
+
+// set fill radial gradient end point x
+shape.fillRadialGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point y
+var endPointY = shape.fillRadialGradientEndPointY();
+
+// set fill radial gradient end point y
+shape.fillRadialGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient end radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient end radius
+var endRadius = shape.fillRadialGradientEndRadius();
+
+// set radial gradient end radius
+shape.fillRadialGradientEndRadius(100);
+ + + +
+ + + +
+
+

fillRadialGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill radial gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point
+var startPoint = shape.fillRadialGradientStartPoint();
+
+// set fill radial gradient start point
+shape.fillRadialGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point x
+var startPointX = shape.fillRadialGradientStartPointX();
+
+// set fill radial gradient start point x
+shape.fillRadialGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point y
+var startPointY = shape.fillRadialGradientStartPointY();
+
+// set fill radial gradient start point y
+shape.fillRadialGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient start radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient start radius
+var startRadius = shape.fillRadialGradientStartRadius();
+
+// set radial gradient start radius
+shape.fillRadialGradientStartRadius(0);
+ + + +
+ + + +
+
+

fillRule(rotation)

+ + +
+
+ + +
+

get/set fill rule

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +CanvasFillRule + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill rule
+var fillRule = shape.fillRule();
+
+// set fill rule
+shape.fillRule('evenodd');
+ + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getLength()

+ + +
+
+ + +
+

Return length of the path.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

length

+
+ + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
var length = path.getLength();
+ + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getPointAtLength(length)

+ + +
+
+ + +
+

Get point on path at specific length of the path

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
length + + +Number + + + + +

length

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

point {x,y} point

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var point = path.getPointAtLength(10);
+ + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getSelfRect()

+ + +
+
+ + +
+

return self rectangle (x, y, width, height) of shape.
+This method are not taken into account transformation and styles.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
rect.getSelfRect();  // return {x:0, y:0, width:rect.width(), height:rect.height()}
+circle.getSelfRect();  // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasFill()

+ + +
+
+ + +
+

returns whether or not the shape will be filled

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

hasShadow()

+ + +
+
+ + +
+

returns whether or not a shadow will be rendered

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasStroke()

+ + +
+
+ + +
+

returns whether or not the shape will be stroked

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitFunc(drawFunc)

+ + +
+
+ + +
+

get/set hit draw function. That function is used to draw custom hit area of a shape.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get hit draw function
+var hitFunc = shape.hitFunc();
+
+// set hit draw function
+shape.hitFunc(function(context) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

hitStrokeWidth(hitStrokeWidth)

+ + +
+
+ + +
+

get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var hitStrokeWidth = shape.hitStrokeWidth();
+
+// set hit stroke width
+shape.hitStrokeWidth(20);
+// set hit stroke width always equals to scene stroke width
+shape.hitStrokeWidth('auto');
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

intersects(point)

+ + +
+
+ + +
+

determines if point is in the shape, regardless if other shapes are on top of it. Note: because
+this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
+consecutively. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

linearLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set stroke linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point x
+var startPointX = shape.strokeLinearGradientStartPointX();
+
+// set stroke linear gradient start point x
+shape.strokeLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

lineCap(lineCap)

+ + +
+
+ + +
+

get/set line cap. Can be butt, round, or square

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineCap + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line cap
+var lineCap = shape.lineCap();
+
+// set line cap
+shape.lineCap('round');
+ + + +
+ + + +
+
+

lineJoin(lineJoin)

+ + +
+
+ + +
+

get/set line join. Can be miter, round, or bevel. The
+default is miter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineJoin + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line join
+var lineJoin = shape.lineJoin();
+
+// set line join
+shape.lineJoin('round');
+ + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

perfectDrawEnabled(perfectDrawEnabled)

+ + +
+
+ + +
+

get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set perfectDrawEnabled to false to improve performance.
+See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
perfectDrawEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get perfectDrawEnabled
+var perfectDrawEnabled = shape.perfectDrawEnabled();
+
+// set perfectDrawEnabled
+shape.perfectDrawEnabled();
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

sceneFunc(drawFunc)

+ + +
+
+ + +
+

get/set scene draw function. That function is used to draw the shape on a canvas.
+Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get scene draw function
+var sceneFunc = shape.sceneFunc();
+
+// set scene draw function
+shape.sceneFunc(function(context, shape) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  // like stroke and fill
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

shadowBlur(blur)

+ + +
+
+ + +
+

get/set shadow blur

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blur + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow blur
+var shadowBlur = shape.shadowBlur();
+
+// set shadow blur
+shape.shadowBlur(10);
+ + + +
+ + + +
+
+

shadowColor(color)

+ + +
+
+ + +
+

get/set shadow color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get shadow color
+var shadow = shape.shadowColor();
+
+// set shadow color with color string
+shape.shadowColor('green');
+
+// set shadow color with hex
+shape.shadowColor('#00ff00');
+
+// set shadow color with rgb
+shape.shadowColor('rgb(0,255,0)');
+
+// set shadow color with rgba and make it 50% opaque
+shape.shadowColor('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

shadowEnabled(enabled)

+ + +
+
+ + +
+

get/set shadow enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadow enabled flag
+var shadowEnabled = shape.shadowEnabled();
+
+// disable shadow
+shape.shadowEnabled(false);
+
+// enable shadow
+shape.shadowEnabled(true);
+ + + +
+ + + +
+
+

shadowForStrokeEnabled(shadowForStrokeEnabled)

+ + +
+
+ + +
+

get/set shadowForStrokeEnabled. Useful for performance optimization.
+You may set shape.shadowForStrokeEnabled(false). In this case stroke will no effect shadow.
+Remember if you set shadowForStrokeEnabled = false for non closed line - that line will have no shadow!.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shadowForStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadowForStrokeEnabled
+var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
+
+// set shadowForStrokeEnabled
+shape.shadowForStrokeEnabled();
+ + + +
+ + + +
+
+

shadowOffset(offset)

+ + +
+
+ + +
+

get/set shadow offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get shadow offset
+var shadowOffset = shape.shadowOffset();
+
+// set shadow offset
+shape.shadowOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

shadowOffsetX(x)

+ + +
+
+ + +
+

get/set shadow offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset x
+var shadowOffsetX = shape.shadowOffsetX();
+
+// set shadow offset x
+shape.shadowOffsetX(5);
+ + + +
+ + + +
+
+

shadowOffsetY(y)

+ + +
+
+ + +
+

get/set shadow offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset y
+var shadowOffsetY = shape.shadowOffsetY();
+
+// set shadow offset y
+shape.shadowOffsetY(5);
+ + + +
+ + + +
+
+

shadowOpacity(opacity)

+ + +
+
+ + +
+

get/set shadow opacity. must be a value between 0 and 1

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow opacity
+var shadowOpacity = shape.shadowOpacity();
+
+// set shadow opacity
+shape.shadowOpacity(0.5);
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke(color)

+ + +
+
+ + +
+

get/set stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get stroke color
+var stroke = shape.stroke();
+
+// set stroke color with color string
+shape.stroke('green');
+
+// set stroke color with hex
+shape.stroke('#00ff00');
+
+// set stroke color with rgb
+shape.stroke('rgb(0,255,0)');
+
+// set stroke color with rgba and make it 50% opaque
+shape.stroke('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

strokeEnabled(enabled)

+ + +
+
+ + +
+

get/set stroke enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke enabled flag
+var strokeEnabled = shape.strokeEnabled();
+
+// disable stroke
+shape.strokeEnabled(false);
+
+// enable stroke
+shape.strokeEnabled(true);
+ + + +
+ + + +
+
+

strokeHitEnabled(strokeHitEnabled)

+ + +
+
+ + +
+

deprecated, use hitStrokeWidth instead! get/set strokeHitEnabled property. Useful for performance optimization.
+You may set shape.strokeHitEnabled(false). In this case stroke will be no draw on hit canvas, so hit area
+of shape will be decreased (by lineWidth / 2). Remember that non closed line with strokeHitEnabled = false
+will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
+Default value is true.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeHitEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get strokeHitEnabled
+var strokeHitEnabled = shape.strokeHitEnabled();
+
+// set strokeHitEnabled
+shape.strokeHitEnabled();
+ + + +
+ + + +
+
+

strokeLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set stroke linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient color stops
+var colorStops = shape.strokeLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point
+var endPoint = shape.strokeLinearGradientEndPoint();
+
+// set stroke linear gradient end point
+shape.strokeLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point x
+var endPointX = shape.strokeLinearGradientEndPointX();
+
+// set stroke linear gradient end point x
+shape.strokeLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point y
+var endPointY = shape.strokeLinearGradientEndPointY();
+
+// set stroke linear gradient end point y
+shape.strokeLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

strokeLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point
+var startPoint = shape.strokeLinearGradientStartPoint();
+
+// set stroke linear gradient start point
+shape.strokeLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point y
+var startPointY = shape.strokeLinearGradientStartPointY();
+
+// set stroke linear gradient start point y
+shape.strokeLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

strokeScaleEnabled(enabled)

+ + +
+
+ + +
+

get/set strokeScale enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke scale enabled flag
+var strokeScaleEnabled = shape.strokeScaleEnabled();
+
+// disable stroke scale
+shape.strokeScaleEnabled(false);
+
+// enable stroke scale
+shape.strokeScaleEnabled(true);
+ + + +
+ + + +
+
+

strokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var strokeWidth = shape.strokeWidth();
+
+// set stroke width
+shape.strokeWidth(10);
+ + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Rect.html b/api/Konva.Rect.html new file mode 100644 index 000000000..f19ef204b --- /dev/null +++ b/api/Konva.Rect.html @@ -0,0 +1,34038 @@ + + + + + + + Konva Class: Rect + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Rect

+
+ +
+ +

+ Konva. + + Rect +

+ +

Rect constructor

+ + +
+ + +
+
+ + +
+
+

new Rect(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
cornerRadius + + +Number + + + + + + + <optional>
+ + + + + +
fill + + +String + + + + + + + <optional>
+ + + + + +

fill color

fillPatternImage + + +Image + + + + + + + <optional>
+ + + + + +

fill pattern image

fillPatternX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScale + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternScaleX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScaleY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRotation + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRepeat + + +String + + + + + + + <optional>
+ + + + + +

can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"

fillLinearGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillRadialGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the fill. The default value is true

fillPriority + + +String + + + + + + + <optional>
+ + + + + +

can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration

stroke + + +String + + + + + + + <optional>
+ + + + + +

stroke color

strokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

stroke width

fillAfterStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw fill AFTER stroke? Default is false.

hitStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth

strokeHitEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke hit region. The default is true

perfectDrawEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables using buffer canvas. The default is true

shadowForStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables shadow for stroke. The default is true

strokeScaleEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke scale. The default is true

strokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the stroke. The default value is true

lineJoin + + +String + + + + + + + <optional>
+ + + + + +

can be miter, round, or bevel. The default
+is miter

lineCap + + +String + + + + + + + <optional>
+ + + + + +

can be butt, round, or square. The default
+is butt

shadowColor + + +String + + + + + + + <optional>
+ + + + + +
shadowBlur + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

shadowOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
shadowOpacity + + +Number + + + + + + + <optional>
+ + + + + +

shadow opacity. Can be any real number
+between 0 and 1

shadowEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the shadow. The default value is true

dash + + +Array + + + + + + + <optional>
+ + + + + +
dashEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the dashArray. The default value is true

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var rect = new Konva.Rect({
+  width: 100,
+  height: 50,
+  fill: 'red',
+  stroke: 'black',
+  strokeWidth: 5
+});
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cornerRadius(cornerRadius)

+ + +
+
+ + +
+

get/set corner radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
cornerRadius + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get corner radius
+var cornerRadius = rect.cornerRadius();
+
+// set corner radius
+rect.cornerRadius(10);
+
+// set different corner radius values
+// top-left, top-right, bottom-right, bottom-left
+rect.cornerRadius([0, 10, 20, 30]);
+ + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash array for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart
+ line.dash([10, 5]);
+ // apply dashed stroke that is made up of alternating dashed
+ // lines that are 10px long and 20px apart, and dots that have
+ // a radius of 5px and are 20px apart
+ line.dash([10, 20, 0.001, 20]);
+ + + +
+ + + +
+
+

dashEnabled(enabled)

+ + +
+
+ + +
+

get/set dash enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get dash enabled flag
+var dashEnabled = shape.dashEnabled();
+
+// disable dash
+shape.dashEnabled(false);
+
+// enable dash
+shape.dashEnabled(true);
+ + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

drawHitFromCache(alphaThreshold)

+ + +
+
+ + +
+

draw hit graph using the cached scene canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alphaThreshold + + +Integer + + + + +

alpha channel threshold that determines whether or not
+a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
+The default is 0

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
shape.cache();
+shape.drawHitFromCache();
+ + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

fill(color)

+ + +
+
+ + +
+

get/set fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill color
+var fill = shape.fill();
+
+// set fill color with color string
+shape.fill('green');
+
+// set fill color with hex
+shape.fill('#00ff00');
+
+// set fill color with rgb
+shape.fill('rgb(0,255,0)');
+
+// set fill color with rgba and make it 50% opaque
+shape.fill('rgba(0,255,0,0.5');
+
+// shape without fill
+shape.fill(null);
+ + + +
+ + + +
+
+

fillAfterStrokeEnabled(fillAfterStrokeEnabled)

+ + +
+
+ + +
+

get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
+In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
+Especially useful for Text objects.
+Default is false.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fillAfterStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
+
+// set stroke width
+shape.fillAfterStrokeEnabled(true);
+ + + +
+ + + +
+
+

fillEnabled(enabled)

+ + +
+
+ + +
+

get/set fill enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get fill enabled flag
+var fillEnabled = shape.fillEnabled();
+
+// disable fill
+shape.fillEnabled(false);
+
+// enable fill
+shape.fillEnabled(true);
+ + + +
+ + + +
+
+

fillLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient color stops
+var colorStops = shape.fillLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point
+var endPoint = shape.fillLinearGradientEndPoint();
+
+// set fill linear gradient end point
+shape.fillLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point x
+var endPointX = shape.fillLinearGradientEndPointX();
+
+// set fill linear gradient end point x
+shape.fillLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point y
+var endPointY = shape.fillLinearGradientEndPointY();
+
+// set fill linear gradient end point y
+shape.fillLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point
+var startPoint = shape.fillLinearGradientStartPoint();
+
+// set fill linear gradient start point
+shape.fillLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point x
+var startPointX = shape.fillLinearGradientStartPointX();
+
+// set fill linear gradient start point x
+shape.fillLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point y
+var startPointY = shape.fillLinearGradientStartPointY();
+
+// set fill linear gradient start point y
+shape.fillLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillPatternImage(image)

+ + +
+
+ + +
+

get/set fill pattern image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +

object

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get fill pattern image
+var fillPatternImage = shape.fillPatternImage();
+
+// set fill pattern image
+var imageObj = new Image();
+imageObj.onload = function() {
+  shape.fillPatternImage(imageObj);
+};
+imageObj.src = 'path/to/image/jpg';
+ + + +
+ + + +
+
+

fillPatternOffset(offset)

+ + +
+
+ + +
+

get/set fill pattern offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset
+var patternOffset = shape.fillPatternOffset();
+
+// set fill pattern offset
+shape.fillPatternOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillPatternOffsetX(x)

+ + +
+
+ + +
+

get/set fill pattern offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset x
+var patternOffsetX = shape.fillPatternOffsetX();
+
+// set fill pattern offset x
+shape.fillPatternOffsetX(20);
+ + + +
+ + + +
+
+

fillPatternOffsetY(y)

+ + +
+
+ + +
+

get/set fill pattern offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset y
+var patternOffsetY = shape.fillPatternOffsetY();
+
+// set fill pattern offset y
+shape.fillPatternOffsetY(10);
+ + + +
+ + + +
+
+

fillPatternRepeat(repeat)

+ + +
+
+ + +
+

get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
repeat + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill pattern repeat
+var repeat = shape.fillPatternRepeat();
+
+// repeat pattern in x direction only
+shape.fillPatternRepeat('repeat-x');
+
+// do not repeat the pattern
+shape.fillPatternRepeat('no-repeat');
+ + + +
+ + + +
+
+

fillPatternRotation(rotation)

+ + +
+
+ + +
+

get/set fill pattern rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill pattern rotation
+var patternRotation = shape.fillPatternRotation();
+
+// set fill pattern rotation
+shape.fillPatternRotation(20);
+ + + +
+ + + +
+
+

fillPatternScale(scale)

+ + +
+
+ + +
+

get/set fill pattern scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale
+var patternScale = shape.fillPatternScale();
+
+// set fill pattern scale
+shape.fillPatternScale({
+  x: 2,
+  y: 2
+});
+ + + +
+ + + +
+
+

fillPatternScaleX(x)

+ + +
+
+ + +
+

get/set fill pattern scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale x
+var patternScaleX = shape.fillPatternScaleX();
+
+// set fill pattern scale x
+shape.fillPatternScaleX(2);
+ + + +
+ + + +
+
+

fillPatternScaleY(y)

+ + +
+
+ + +
+

get/set fill pattern scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale y
+var patternScaleY = shape.fillPatternScaleY();
+
+// set fill pattern scale y
+shape.fillPatternScaleY(2);
+ + + +
+ + + +
+
+

fillPatternX(x)

+ + +
+
+ + +
+

get/set fill pattern x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern x
+var fillPatternX = shape.fillPatternX();
+// set fill pattern x
+shape.fillPatternX(20);
+ + + +
+ + + +
+
+

fillPatternY(y)

+ + +
+
+ + +
+

get/set fill pattern y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern y
+var fillPatternY = shape.fillPatternY();
+// set fill pattern y
+shape.fillPatternY(20);
+ + + +
+ + + +
+
+

fillPriority(priority)

+ + +
+
+ + +
+

get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
+This is handy if you want to toggle between different fill types.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
priority + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill priority
+var fillPriority = shape.fillPriority();
+
+// set fill priority
+shape.fillPriority('linear-gradient');
+ + + +
+ + + +
+
+

fillRadialGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill radial gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient color stops
+var colorStops = shape.fillRadialGradientColorStops();
+
+// create a radial gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillRadialGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill radial gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point
+var endPoint = shape.fillRadialGradientEndPoint();
+
+// set fill radial gradient end point
+shape.fillRadialGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point x
+var endPointX = shape.fillRadialGradientEndPointX();
+
+// set fill radial gradient end point x
+shape.fillRadialGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point y
+var endPointY = shape.fillRadialGradientEndPointY();
+
+// set fill radial gradient end point y
+shape.fillRadialGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient end radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient end radius
+var endRadius = shape.fillRadialGradientEndRadius();
+
+// set radial gradient end radius
+shape.fillRadialGradientEndRadius(100);
+ + + +
+ + + +
+
+

fillRadialGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill radial gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point
+var startPoint = shape.fillRadialGradientStartPoint();
+
+// set fill radial gradient start point
+shape.fillRadialGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point x
+var startPointX = shape.fillRadialGradientStartPointX();
+
+// set fill radial gradient start point x
+shape.fillRadialGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point y
+var startPointY = shape.fillRadialGradientStartPointY();
+
+// set fill radial gradient start point y
+shape.fillRadialGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient start radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient start radius
+var startRadius = shape.fillRadialGradientStartRadius();
+
+// set radial gradient start radius
+shape.fillRadialGradientStartRadius(0);
+ + + +
+ + + +
+
+

fillRule(rotation)

+ + +
+
+ + +
+

get/set fill rule

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +CanvasFillRule + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill rule
+var fillRule = shape.fillRule();
+
+// set fill rule
+shape.fillRule('evenodd');
+ + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getSelfRect()

+ + +
+
+ + +
+

return self rectangle (x, y, width, height) of shape.
+This method are not taken into account transformation and styles.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
rect.getSelfRect();  // return {x:0, y:0, width:rect.width(), height:rect.height()}
+circle.getSelfRect();  // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasFill()

+ + +
+
+ + +
+

returns whether or not the shape will be filled

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

hasShadow()

+ + +
+
+ + +
+

returns whether or not a shadow will be rendered

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasStroke()

+ + +
+
+ + +
+

returns whether or not the shape will be stroked

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitFunc(drawFunc)

+ + +
+
+ + +
+

get/set hit draw function. That function is used to draw custom hit area of a shape.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get hit draw function
+var hitFunc = shape.hitFunc();
+
+// set hit draw function
+shape.hitFunc(function(context) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

hitStrokeWidth(hitStrokeWidth)

+ + +
+
+ + +
+

get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var hitStrokeWidth = shape.hitStrokeWidth();
+
+// set hit stroke width
+shape.hitStrokeWidth(20);
+// set hit stroke width always equals to scene stroke width
+shape.hitStrokeWidth('auto');
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

intersects(point)

+ + +
+
+ + +
+

determines if point is in the shape, regardless if other shapes are on top of it. Note: because
+this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
+consecutively. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

linearLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set stroke linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point x
+var startPointX = shape.strokeLinearGradientStartPointX();
+
+// set stroke linear gradient start point x
+shape.strokeLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

lineCap(lineCap)

+ + +
+
+ + +
+

get/set line cap. Can be butt, round, or square

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineCap + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line cap
+var lineCap = shape.lineCap();
+
+// set line cap
+shape.lineCap('round');
+ + + +
+ + + +
+
+

lineJoin(lineJoin)

+ + +
+
+ + +
+

get/set line join. Can be miter, round, or bevel. The
+default is miter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineJoin + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line join
+var lineJoin = shape.lineJoin();
+
+// set line join
+shape.lineJoin('round');
+ + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

perfectDrawEnabled(perfectDrawEnabled)

+ + +
+
+ + +
+

get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set perfectDrawEnabled to false to improve performance.
+See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
perfectDrawEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get perfectDrawEnabled
+var perfectDrawEnabled = shape.perfectDrawEnabled();
+
+// set perfectDrawEnabled
+shape.perfectDrawEnabled();
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

sceneFunc(drawFunc)

+ + +
+
+ + +
+

get/set scene draw function. That function is used to draw the shape on a canvas.
+Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get scene draw function
+var sceneFunc = shape.sceneFunc();
+
+// set scene draw function
+shape.sceneFunc(function(context, shape) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  // like stroke and fill
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

shadowBlur(blur)

+ + +
+
+ + +
+

get/set shadow blur

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blur + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow blur
+var shadowBlur = shape.shadowBlur();
+
+// set shadow blur
+shape.shadowBlur(10);
+ + + +
+ + + +
+
+

shadowColor(color)

+ + +
+
+ + +
+

get/set shadow color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get shadow color
+var shadow = shape.shadowColor();
+
+// set shadow color with color string
+shape.shadowColor('green');
+
+// set shadow color with hex
+shape.shadowColor('#00ff00');
+
+// set shadow color with rgb
+shape.shadowColor('rgb(0,255,0)');
+
+// set shadow color with rgba and make it 50% opaque
+shape.shadowColor('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

shadowEnabled(enabled)

+ + +
+
+ + +
+

get/set shadow enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadow enabled flag
+var shadowEnabled = shape.shadowEnabled();
+
+// disable shadow
+shape.shadowEnabled(false);
+
+// enable shadow
+shape.shadowEnabled(true);
+ + + +
+ + + +
+
+

shadowForStrokeEnabled(shadowForStrokeEnabled)

+ + +
+
+ + +
+

get/set shadowForStrokeEnabled. Useful for performance optimization.
+You may set shape.shadowForStrokeEnabled(false). In this case stroke will no effect shadow.
+Remember if you set shadowForStrokeEnabled = false for non closed line - that line will have no shadow!.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shadowForStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadowForStrokeEnabled
+var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
+
+// set shadowForStrokeEnabled
+shape.shadowForStrokeEnabled();
+ + + +
+ + + +
+
+

shadowOffset(offset)

+ + +
+
+ + +
+

get/set shadow offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get shadow offset
+var shadowOffset = shape.shadowOffset();
+
+// set shadow offset
+shape.shadowOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

shadowOffsetX(x)

+ + +
+
+ + +
+

get/set shadow offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset x
+var shadowOffsetX = shape.shadowOffsetX();
+
+// set shadow offset x
+shape.shadowOffsetX(5);
+ + + +
+ + + +
+
+

shadowOffsetY(y)

+ + +
+
+ + +
+

get/set shadow offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset y
+var shadowOffsetY = shape.shadowOffsetY();
+
+// set shadow offset y
+shape.shadowOffsetY(5);
+ + + +
+ + + +
+
+

shadowOpacity(opacity)

+ + +
+
+ + +
+

get/set shadow opacity. must be a value between 0 and 1

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow opacity
+var shadowOpacity = shape.shadowOpacity();
+
+// set shadow opacity
+shape.shadowOpacity(0.5);
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke(color)

+ + +
+
+ + +
+

get/set stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get stroke color
+var stroke = shape.stroke();
+
+// set stroke color with color string
+shape.stroke('green');
+
+// set stroke color with hex
+shape.stroke('#00ff00');
+
+// set stroke color with rgb
+shape.stroke('rgb(0,255,0)');
+
+// set stroke color with rgba and make it 50% opaque
+shape.stroke('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

strokeEnabled(enabled)

+ + +
+
+ + +
+

get/set stroke enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke enabled flag
+var strokeEnabled = shape.strokeEnabled();
+
+// disable stroke
+shape.strokeEnabled(false);
+
+// enable stroke
+shape.strokeEnabled(true);
+ + + +
+ + + +
+
+

strokeHitEnabled(strokeHitEnabled)

+ + +
+
+ + +
+

deprecated, use hitStrokeWidth instead! get/set strokeHitEnabled property. Useful for performance optimization.
+You may set shape.strokeHitEnabled(false). In this case stroke will be no draw on hit canvas, so hit area
+of shape will be decreased (by lineWidth / 2). Remember that non closed line with strokeHitEnabled = false
+will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
+Default value is true.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeHitEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get strokeHitEnabled
+var strokeHitEnabled = shape.strokeHitEnabled();
+
+// set strokeHitEnabled
+shape.strokeHitEnabled();
+ + + +
+ + + +
+
+

strokeLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set stroke linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient color stops
+var colorStops = shape.strokeLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point
+var endPoint = shape.strokeLinearGradientEndPoint();
+
+// set stroke linear gradient end point
+shape.strokeLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point x
+var endPointX = shape.strokeLinearGradientEndPointX();
+
+// set stroke linear gradient end point x
+shape.strokeLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point y
+var endPointY = shape.strokeLinearGradientEndPointY();
+
+// set stroke linear gradient end point y
+shape.strokeLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

strokeLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point
+var startPoint = shape.strokeLinearGradientStartPoint();
+
+// set stroke linear gradient start point
+shape.strokeLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point y
+var startPointY = shape.strokeLinearGradientStartPointY();
+
+// set stroke linear gradient start point y
+shape.strokeLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

strokeScaleEnabled(enabled)

+ + +
+
+ + +
+

get/set strokeScale enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke scale enabled flag
+var strokeScaleEnabled = shape.strokeScaleEnabled();
+
+// disable stroke scale
+shape.strokeScaleEnabled(false);
+
+// enable stroke scale
+shape.strokeScaleEnabled(true);
+ + + +
+ + + +
+
+

strokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var strokeWidth = shape.strokeWidth();
+
+// set stroke width
+shape.strokeWidth(10);
+ + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.RegularPolygon.html b/api/Konva.RegularPolygon.html new file mode 100644 index 000000000..785952584 --- /dev/null +++ b/api/Konva.RegularPolygon.html @@ -0,0 +1,34234 @@ + + + + + + + Konva Class: RegularPolygon + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: RegularPolygon

+
+ +
+ +

+ Konva. + + RegularPolygon +

+ +

RegularPolygon constructor. Examples include triangles, squares, pentagons, hexagons, etc.

+ + +
+ + +
+
+ + +
+
+

new RegularPolygon(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
sides + + +Number + + + + + + + + + + +
radius + + +Number + + + + + + + + + + +
fill + + +String + + + + + + + <optional>
+ + + + + +

fill color

fillPatternImage + + +Image + + + + + + + <optional>
+ + + + + +

fill pattern image

fillPatternX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScale + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternScaleX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScaleY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRotation + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRepeat + + +String + + + + + + + <optional>
+ + + + + +

can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"

fillLinearGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillRadialGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the fill. The default value is true

fillPriority + + +String + + + + + + + <optional>
+ + + + + +

can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration

stroke + + +String + + + + + + + <optional>
+ + + + + +

stroke color

strokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

stroke width

fillAfterStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw fill AFTER stroke? Default is false.

hitStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth

strokeHitEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke hit region. The default is true

perfectDrawEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables using buffer canvas. The default is true

shadowForStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables shadow for stroke. The default is true

strokeScaleEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke scale. The default is true

strokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the stroke. The default value is true

lineJoin + + +String + + + + + + + <optional>
+ + + + + +

can be miter, round, or bevel. The default
+is miter

lineCap + + +String + + + + + + + <optional>
+ + + + + +

can be butt, round, or square. The default
+is butt

shadowColor + + +String + + + + + + + <optional>
+ + + + + +
shadowBlur + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

shadowOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
shadowOpacity + + +Number + + + + + + + <optional>
+ + + + + +

shadow opacity. Can be any real number
+between 0 and 1

shadowEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the shadow. The default value is true

dash + + +Array + + + + + + + <optional>
+ + + + + +
dashEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the dashArray. The default value is true

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var hexagon = new Konva.RegularPolygon({
+  x: 100,
+  y: 200,
+  sides: 6,
+  radius: 70,
+  fill: 'red',
+  stroke: 'black',
+  strokeWidth: 4
+});
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash array for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart
+ line.dash([10, 5]);
+ // apply dashed stroke that is made up of alternating dashed
+ // lines that are 10px long and 20px apart, and dots that have
+ // a radius of 5px and are 20px apart
+ line.dash([10, 20, 0.001, 20]);
+ + + +
+ + + +
+
+

dashEnabled(enabled)

+ + +
+
+ + +
+

get/set dash enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get dash enabled flag
+var dashEnabled = shape.dashEnabled();
+
+// disable dash
+shape.dashEnabled(false);
+
+// enable dash
+shape.dashEnabled(true);
+ + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

drawHitFromCache(alphaThreshold)

+ + +
+
+ + +
+

draw hit graph using the cached scene canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alphaThreshold + + +Integer + + + + +

alpha channel threshold that determines whether or not
+a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
+The default is 0

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
shape.cache();
+shape.drawHitFromCache();
+ + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

fill(color)

+ + +
+
+ + +
+

get/set fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill color
+var fill = shape.fill();
+
+// set fill color with color string
+shape.fill('green');
+
+// set fill color with hex
+shape.fill('#00ff00');
+
+// set fill color with rgb
+shape.fill('rgb(0,255,0)');
+
+// set fill color with rgba and make it 50% opaque
+shape.fill('rgba(0,255,0,0.5');
+
+// shape without fill
+shape.fill(null);
+ + + +
+ + + +
+
+

fillAfterStrokeEnabled(fillAfterStrokeEnabled)

+ + +
+
+ + +
+

get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
+In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
+Especially useful for Text objects.
+Default is false.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fillAfterStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
+
+// set stroke width
+shape.fillAfterStrokeEnabled(true);
+ + + +
+ + + +
+
+

fillEnabled(enabled)

+ + +
+
+ + +
+

get/set fill enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get fill enabled flag
+var fillEnabled = shape.fillEnabled();
+
+// disable fill
+shape.fillEnabled(false);
+
+// enable fill
+shape.fillEnabled(true);
+ + + +
+ + + +
+
+

fillLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient color stops
+var colorStops = shape.fillLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point
+var endPoint = shape.fillLinearGradientEndPoint();
+
+// set fill linear gradient end point
+shape.fillLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point x
+var endPointX = shape.fillLinearGradientEndPointX();
+
+// set fill linear gradient end point x
+shape.fillLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point y
+var endPointY = shape.fillLinearGradientEndPointY();
+
+// set fill linear gradient end point y
+shape.fillLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point
+var startPoint = shape.fillLinearGradientStartPoint();
+
+// set fill linear gradient start point
+shape.fillLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point x
+var startPointX = shape.fillLinearGradientStartPointX();
+
+// set fill linear gradient start point x
+shape.fillLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point y
+var startPointY = shape.fillLinearGradientStartPointY();
+
+// set fill linear gradient start point y
+shape.fillLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillPatternImage(image)

+ + +
+
+ + +
+

get/set fill pattern image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +

object

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get fill pattern image
+var fillPatternImage = shape.fillPatternImage();
+
+// set fill pattern image
+var imageObj = new Image();
+imageObj.onload = function() {
+  shape.fillPatternImage(imageObj);
+};
+imageObj.src = 'path/to/image/jpg';
+ + + +
+ + + +
+
+

fillPatternOffset(offset)

+ + +
+
+ + +
+

get/set fill pattern offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset
+var patternOffset = shape.fillPatternOffset();
+
+// set fill pattern offset
+shape.fillPatternOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillPatternOffsetX(x)

+ + +
+
+ + +
+

get/set fill pattern offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset x
+var patternOffsetX = shape.fillPatternOffsetX();
+
+// set fill pattern offset x
+shape.fillPatternOffsetX(20);
+ + + +
+ + + +
+
+

fillPatternOffsetY(y)

+ + +
+
+ + +
+

get/set fill pattern offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset y
+var patternOffsetY = shape.fillPatternOffsetY();
+
+// set fill pattern offset y
+shape.fillPatternOffsetY(10);
+ + + +
+ + + +
+
+

fillPatternRepeat(repeat)

+ + +
+
+ + +
+

get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
repeat + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill pattern repeat
+var repeat = shape.fillPatternRepeat();
+
+// repeat pattern in x direction only
+shape.fillPatternRepeat('repeat-x');
+
+// do not repeat the pattern
+shape.fillPatternRepeat('no-repeat');
+ + + +
+ + + +
+
+

fillPatternRotation(rotation)

+ + +
+
+ + +
+

get/set fill pattern rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill pattern rotation
+var patternRotation = shape.fillPatternRotation();
+
+// set fill pattern rotation
+shape.fillPatternRotation(20);
+ + + +
+ + + +
+
+

fillPatternScale(scale)

+ + +
+
+ + +
+

get/set fill pattern scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale
+var patternScale = shape.fillPatternScale();
+
+// set fill pattern scale
+shape.fillPatternScale({
+  x: 2,
+  y: 2
+});
+ + + +
+ + + +
+
+

fillPatternScaleX(x)

+ + +
+
+ + +
+

get/set fill pattern scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale x
+var patternScaleX = shape.fillPatternScaleX();
+
+// set fill pattern scale x
+shape.fillPatternScaleX(2);
+ + + +
+ + + +
+
+

fillPatternScaleY(y)

+ + +
+
+ + +
+

get/set fill pattern scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale y
+var patternScaleY = shape.fillPatternScaleY();
+
+// set fill pattern scale y
+shape.fillPatternScaleY(2);
+ + + +
+ + + +
+
+

fillPatternX(x)

+ + +
+
+ + +
+

get/set fill pattern x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern x
+var fillPatternX = shape.fillPatternX();
+// set fill pattern x
+shape.fillPatternX(20);
+ + + +
+ + + +
+
+

fillPatternY(y)

+ + +
+
+ + +
+

get/set fill pattern y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern y
+var fillPatternY = shape.fillPatternY();
+// set fill pattern y
+shape.fillPatternY(20);
+ + + +
+ + + +
+
+

fillPriority(priority)

+ + +
+
+ + +
+

get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
+This is handy if you want to toggle between different fill types.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
priority + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill priority
+var fillPriority = shape.fillPriority();
+
+// set fill priority
+shape.fillPriority('linear-gradient');
+ + + +
+ + + +
+
+

fillRadialGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill radial gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient color stops
+var colorStops = shape.fillRadialGradientColorStops();
+
+// create a radial gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillRadialGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill radial gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point
+var endPoint = shape.fillRadialGradientEndPoint();
+
+// set fill radial gradient end point
+shape.fillRadialGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point x
+var endPointX = shape.fillRadialGradientEndPointX();
+
+// set fill radial gradient end point x
+shape.fillRadialGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point y
+var endPointY = shape.fillRadialGradientEndPointY();
+
+// set fill radial gradient end point y
+shape.fillRadialGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient end radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient end radius
+var endRadius = shape.fillRadialGradientEndRadius();
+
+// set radial gradient end radius
+shape.fillRadialGradientEndRadius(100);
+ + + +
+ + + +
+
+

fillRadialGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill radial gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point
+var startPoint = shape.fillRadialGradientStartPoint();
+
+// set fill radial gradient start point
+shape.fillRadialGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point x
+var startPointX = shape.fillRadialGradientStartPointX();
+
+// set fill radial gradient start point x
+shape.fillRadialGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point y
+var startPointY = shape.fillRadialGradientStartPointY();
+
+// set fill radial gradient start point y
+shape.fillRadialGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient start radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient start radius
+var startRadius = shape.fillRadialGradientStartRadius();
+
+// set radial gradient start radius
+shape.fillRadialGradientStartRadius(0);
+ + + +
+ + + +
+
+

fillRule(rotation)

+ + +
+
+ + +
+

get/set fill rule

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +CanvasFillRule + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill rule
+var fillRule = shape.fillRule();
+
+// set fill rule
+shape.fillRule('evenodd');
+ + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getSelfRect()

+ + +
+
+ + +
+

return self rectangle (x, y, width, height) of shape.
+This method are not taken into account transformation and styles.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
rect.getSelfRect();  // return {x:0, y:0, width:rect.width(), height:rect.height()}
+circle.getSelfRect();  // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasFill()

+ + +
+
+ + +
+

returns whether or not the shape will be filled

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

hasShadow()

+ + +
+
+ + +
+

returns whether or not a shadow will be rendered

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasStroke()

+ + +
+
+ + +
+

returns whether or not the shape will be stroked

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitFunc(drawFunc)

+ + +
+
+ + +
+

get/set hit draw function. That function is used to draw custom hit area of a shape.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get hit draw function
+var hitFunc = shape.hitFunc();
+
+// set hit draw function
+shape.hitFunc(function(context) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

hitStrokeWidth(hitStrokeWidth)

+ + +
+
+ + +
+

get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var hitStrokeWidth = shape.hitStrokeWidth();
+
+// set hit stroke width
+shape.hitStrokeWidth(20);
+// set hit stroke width always equals to scene stroke width
+shape.hitStrokeWidth('auto');
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

intersects(point)

+ + +
+
+ + +
+

determines if point is in the shape, regardless if other shapes are on top of it. Note: because
+this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
+consecutively. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

linearLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set stroke linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point x
+var startPointX = shape.strokeLinearGradientStartPointX();
+
+// set stroke linear gradient start point x
+shape.strokeLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

lineCap(lineCap)

+ + +
+
+ + +
+

get/set line cap. Can be butt, round, or square

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineCap + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line cap
+var lineCap = shape.lineCap();
+
+// set line cap
+shape.lineCap('round');
+ + + +
+ + + +
+
+

lineJoin(lineJoin)

+ + +
+
+ + +
+

get/set line join. Can be miter, round, or bevel. The
+default is miter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineJoin + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line join
+var lineJoin = shape.lineJoin();
+
+// set line join
+shape.lineJoin('round');
+ + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

perfectDrawEnabled(perfectDrawEnabled)

+ + +
+
+ + +
+

get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set perfectDrawEnabled to false to improve performance.
+See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
perfectDrawEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get perfectDrawEnabled
+var perfectDrawEnabled = shape.perfectDrawEnabled();
+
+// set perfectDrawEnabled
+shape.perfectDrawEnabled();
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

radius(radius)

+ + +
+
+ + +
+

get/set radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radius
+var radius = shape.radius();
+
+// set radius
+shape.radius(10);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

sceneFunc(drawFunc)

+ + +
+
+ + +
+

get/set scene draw function. That function is used to draw the shape on a canvas.
+Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get scene draw function
+var sceneFunc = shape.sceneFunc();
+
+// set scene draw function
+shape.sceneFunc(function(context, shape) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  // like stroke and fill
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

shadowBlur(blur)

+ + +
+
+ + +
+

get/set shadow blur

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blur + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow blur
+var shadowBlur = shape.shadowBlur();
+
+// set shadow blur
+shape.shadowBlur(10);
+ + + +
+ + + +
+
+

shadowColor(color)

+ + +
+
+ + +
+

get/set shadow color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get shadow color
+var shadow = shape.shadowColor();
+
+// set shadow color with color string
+shape.shadowColor('green');
+
+// set shadow color with hex
+shape.shadowColor('#00ff00');
+
+// set shadow color with rgb
+shape.shadowColor('rgb(0,255,0)');
+
+// set shadow color with rgba and make it 50% opaque
+shape.shadowColor('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

shadowEnabled(enabled)

+ + +
+
+ + +
+

get/set shadow enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadow enabled flag
+var shadowEnabled = shape.shadowEnabled();
+
+// disable shadow
+shape.shadowEnabled(false);
+
+// enable shadow
+shape.shadowEnabled(true);
+ + + +
+ + + +
+
+

shadowForStrokeEnabled(shadowForStrokeEnabled)

+ + +
+
+ + +
+

get/set shadowForStrokeEnabled. Useful for performance optimization.
+You may set shape.shadowForStrokeEnabled(false). In this case stroke will no effect shadow.
+Remember if you set shadowForStrokeEnabled = false for non closed line - that line will have no shadow!.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shadowForStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadowForStrokeEnabled
+var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
+
+// set shadowForStrokeEnabled
+shape.shadowForStrokeEnabled();
+ + + +
+ + + +
+
+

shadowOffset(offset)

+ + +
+
+ + +
+

get/set shadow offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get shadow offset
+var shadowOffset = shape.shadowOffset();
+
+// set shadow offset
+shape.shadowOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

shadowOffsetX(x)

+ + +
+
+ + +
+

get/set shadow offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset x
+var shadowOffsetX = shape.shadowOffsetX();
+
+// set shadow offset x
+shape.shadowOffsetX(5);
+ + + +
+ + + +
+
+

shadowOffsetY(y)

+ + +
+
+ + +
+

get/set shadow offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset y
+var shadowOffsetY = shape.shadowOffsetY();
+
+// set shadow offset y
+shape.shadowOffsetY(5);
+ + + +
+ + + +
+
+

shadowOpacity(opacity)

+ + +
+
+ + +
+

get/set shadow opacity. must be a value between 0 and 1

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow opacity
+var shadowOpacity = shape.shadowOpacity();
+
+// set shadow opacity
+shape.shadowOpacity(0.5);
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

sides(sides)

+ + +
+
+ + +
+

get/set sides

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
sides + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get sides
+var sides = shape.sides();
+
+// set sides
+shape.sides(10);
+ + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke(color)

+ + +
+
+ + +
+

get/set stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get stroke color
+var stroke = shape.stroke();
+
+// set stroke color with color string
+shape.stroke('green');
+
+// set stroke color with hex
+shape.stroke('#00ff00');
+
+// set stroke color with rgb
+shape.stroke('rgb(0,255,0)');
+
+// set stroke color with rgba and make it 50% opaque
+shape.stroke('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

strokeEnabled(enabled)

+ + +
+
+ + +
+

get/set stroke enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke enabled flag
+var strokeEnabled = shape.strokeEnabled();
+
+// disable stroke
+shape.strokeEnabled(false);
+
+// enable stroke
+shape.strokeEnabled(true);
+ + + +
+ + + +
+
+

strokeHitEnabled(strokeHitEnabled)

+ + +
+
+ + +
+

deprecated, use hitStrokeWidth instead! get/set strokeHitEnabled property. Useful for performance optimization.
+You may set shape.strokeHitEnabled(false). In this case stroke will be no draw on hit canvas, so hit area
+of shape will be decreased (by lineWidth / 2). Remember that non closed line with strokeHitEnabled = false
+will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
+Default value is true.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeHitEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get strokeHitEnabled
+var strokeHitEnabled = shape.strokeHitEnabled();
+
+// set strokeHitEnabled
+shape.strokeHitEnabled();
+ + + +
+ + + +
+
+

strokeLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set stroke linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient color stops
+var colorStops = shape.strokeLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point
+var endPoint = shape.strokeLinearGradientEndPoint();
+
+// set stroke linear gradient end point
+shape.strokeLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point x
+var endPointX = shape.strokeLinearGradientEndPointX();
+
+// set stroke linear gradient end point x
+shape.strokeLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point y
+var endPointY = shape.strokeLinearGradientEndPointY();
+
+// set stroke linear gradient end point y
+shape.strokeLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

strokeLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point
+var startPoint = shape.strokeLinearGradientStartPoint();
+
+// set stroke linear gradient start point
+shape.strokeLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point y
+var startPointY = shape.strokeLinearGradientStartPointY();
+
+// set stroke linear gradient start point y
+shape.strokeLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

strokeScaleEnabled(enabled)

+ + +
+
+ + +
+

get/set strokeScale enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke scale enabled flag
+var strokeScaleEnabled = shape.strokeScaleEnabled();
+
+// disable stroke scale
+shape.strokeScaleEnabled(false);
+
+// enable stroke scale
+shape.strokeScaleEnabled(true);
+ + + +
+ + + +
+
+

strokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var strokeWidth = shape.strokeWidth();
+
+// set stroke width
+shape.strokeWidth(10);
+ + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Ring.html b/api/Konva.Ring.html new file mode 100644 index 000000000..a57a3ee3d --- /dev/null +++ b/api/Konva.Ring.html @@ -0,0 +1,34227 @@ + + + + + + + Konva Class: Ring + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Ring

+
+ +
+ +

+ Konva. + + Ring +

+ +

Ring constructor

+ + +
+ + +
+
+ + +
+
+

new Ring(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
innerRadius + + +Number + + + + + + + + + + +
outerRadius + + +Number + + + + + + + + + + +
fill + + +String + + + + + + + <optional>
+ + + + + +

fill color

fillPatternImage + + +Image + + + + + + + <optional>
+ + + + + +

fill pattern image

fillPatternX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScale + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternScaleX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScaleY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRotation + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRepeat + + +String + + + + + + + <optional>
+ + + + + +

can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"

fillLinearGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillRadialGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the fill. The default value is true

fillPriority + + +String + + + + + + + <optional>
+ + + + + +

can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration

stroke + + +String + + + + + + + <optional>
+ + + + + +

stroke color

strokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

stroke width

fillAfterStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw fill AFTER stroke? Default is false.

hitStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth

strokeHitEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke hit region. The default is true

perfectDrawEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables using buffer canvas. The default is true

shadowForStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables shadow for stroke. The default is true

strokeScaleEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke scale. The default is true

strokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the stroke. The default value is true

lineJoin + + +String + + + + + + + <optional>
+ + + + + +

can be miter, round, or bevel. The default
+is miter

lineCap + + +String + + + + + + + <optional>
+ + + + + +

can be butt, round, or square. The default
+is butt

shadowColor + + +String + + + + + + + <optional>
+ + + + + +
shadowBlur + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

shadowOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
shadowOpacity + + +Number + + + + + + + <optional>
+ + + + + +

shadow opacity. Can be any real number
+between 0 and 1

shadowEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the shadow. The default value is true

dash + + +Array + + + + + + + <optional>
+ + + + + +
dashEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the dashArray. The default value is true

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var ring = new Konva.Ring({
+  innerRadius: 40,
+  outerRadius: 80,
+  fill: 'red',
+  stroke: 'black',
+  strokeWidth: 5
+});
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash array for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart
+ line.dash([10, 5]);
+ // apply dashed stroke that is made up of alternating dashed
+ // lines that are 10px long and 20px apart, and dots that have
+ // a radius of 5px and are 20px apart
+ line.dash([10, 20, 0.001, 20]);
+ + + +
+ + + +
+
+

dashEnabled(enabled)

+ + +
+
+ + +
+

get/set dash enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get dash enabled flag
+var dashEnabled = shape.dashEnabled();
+
+// disable dash
+shape.dashEnabled(false);
+
+// enable dash
+shape.dashEnabled(true);
+ + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

drawHitFromCache(alphaThreshold)

+ + +
+
+ + +
+

draw hit graph using the cached scene canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alphaThreshold + + +Integer + + + + +

alpha channel threshold that determines whether or not
+a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
+The default is 0

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
shape.cache();
+shape.drawHitFromCache();
+ + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

fill(color)

+ + +
+
+ + +
+

get/set fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill color
+var fill = shape.fill();
+
+// set fill color with color string
+shape.fill('green');
+
+// set fill color with hex
+shape.fill('#00ff00');
+
+// set fill color with rgb
+shape.fill('rgb(0,255,0)');
+
+// set fill color with rgba and make it 50% opaque
+shape.fill('rgba(0,255,0,0.5');
+
+// shape without fill
+shape.fill(null);
+ + + +
+ + + +
+
+

fillAfterStrokeEnabled(fillAfterStrokeEnabled)

+ + +
+
+ + +
+

get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
+In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
+Especially useful for Text objects.
+Default is false.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fillAfterStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
+
+// set stroke width
+shape.fillAfterStrokeEnabled(true);
+ + + +
+ + + +
+
+

fillEnabled(enabled)

+ + +
+
+ + +
+

get/set fill enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get fill enabled flag
+var fillEnabled = shape.fillEnabled();
+
+// disable fill
+shape.fillEnabled(false);
+
+// enable fill
+shape.fillEnabled(true);
+ + + +
+ + + +
+
+

fillLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient color stops
+var colorStops = shape.fillLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point
+var endPoint = shape.fillLinearGradientEndPoint();
+
+// set fill linear gradient end point
+shape.fillLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point x
+var endPointX = shape.fillLinearGradientEndPointX();
+
+// set fill linear gradient end point x
+shape.fillLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point y
+var endPointY = shape.fillLinearGradientEndPointY();
+
+// set fill linear gradient end point y
+shape.fillLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point
+var startPoint = shape.fillLinearGradientStartPoint();
+
+// set fill linear gradient start point
+shape.fillLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point x
+var startPointX = shape.fillLinearGradientStartPointX();
+
+// set fill linear gradient start point x
+shape.fillLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point y
+var startPointY = shape.fillLinearGradientStartPointY();
+
+// set fill linear gradient start point y
+shape.fillLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillPatternImage(image)

+ + +
+
+ + +
+

get/set fill pattern image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +

object

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get fill pattern image
+var fillPatternImage = shape.fillPatternImage();
+
+// set fill pattern image
+var imageObj = new Image();
+imageObj.onload = function() {
+  shape.fillPatternImage(imageObj);
+};
+imageObj.src = 'path/to/image/jpg';
+ + + +
+ + + +
+
+

fillPatternOffset(offset)

+ + +
+
+ + +
+

get/set fill pattern offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset
+var patternOffset = shape.fillPatternOffset();
+
+// set fill pattern offset
+shape.fillPatternOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillPatternOffsetX(x)

+ + +
+
+ + +
+

get/set fill pattern offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset x
+var patternOffsetX = shape.fillPatternOffsetX();
+
+// set fill pattern offset x
+shape.fillPatternOffsetX(20);
+ + + +
+ + + +
+
+

fillPatternOffsetY(y)

+ + +
+
+ + +
+

get/set fill pattern offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset y
+var patternOffsetY = shape.fillPatternOffsetY();
+
+// set fill pattern offset y
+shape.fillPatternOffsetY(10);
+ + + +
+ + + +
+
+

fillPatternRepeat(repeat)

+ + +
+
+ + +
+

get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
repeat + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill pattern repeat
+var repeat = shape.fillPatternRepeat();
+
+// repeat pattern in x direction only
+shape.fillPatternRepeat('repeat-x');
+
+// do not repeat the pattern
+shape.fillPatternRepeat('no-repeat');
+ + + +
+ + + +
+
+

fillPatternRotation(rotation)

+ + +
+
+ + +
+

get/set fill pattern rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill pattern rotation
+var patternRotation = shape.fillPatternRotation();
+
+// set fill pattern rotation
+shape.fillPatternRotation(20);
+ + + +
+ + + +
+
+

fillPatternScale(scale)

+ + +
+
+ + +
+

get/set fill pattern scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale
+var patternScale = shape.fillPatternScale();
+
+// set fill pattern scale
+shape.fillPatternScale({
+  x: 2,
+  y: 2
+});
+ + + +
+ + + +
+
+

fillPatternScaleX(x)

+ + +
+
+ + +
+

get/set fill pattern scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale x
+var patternScaleX = shape.fillPatternScaleX();
+
+// set fill pattern scale x
+shape.fillPatternScaleX(2);
+ + + +
+ + + +
+
+

fillPatternScaleY(y)

+ + +
+
+ + +
+

get/set fill pattern scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale y
+var patternScaleY = shape.fillPatternScaleY();
+
+// set fill pattern scale y
+shape.fillPatternScaleY(2);
+ + + +
+ + + +
+
+

fillPatternX(x)

+ + +
+
+ + +
+

get/set fill pattern x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern x
+var fillPatternX = shape.fillPatternX();
+// set fill pattern x
+shape.fillPatternX(20);
+ + + +
+ + + +
+
+

fillPatternY(y)

+ + +
+
+ + +
+

get/set fill pattern y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern y
+var fillPatternY = shape.fillPatternY();
+// set fill pattern y
+shape.fillPatternY(20);
+ + + +
+ + + +
+
+

fillPriority(priority)

+ + +
+
+ + +
+

get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
+This is handy if you want to toggle between different fill types.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
priority + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill priority
+var fillPriority = shape.fillPriority();
+
+// set fill priority
+shape.fillPriority('linear-gradient');
+ + + +
+ + + +
+
+

fillRadialGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill radial gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient color stops
+var colorStops = shape.fillRadialGradientColorStops();
+
+// create a radial gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillRadialGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill radial gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point
+var endPoint = shape.fillRadialGradientEndPoint();
+
+// set fill radial gradient end point
+shape.fillRadialGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point x
+var endPointX = shape.fillRadialGradientEndPointX();
+
+// set fill radial gradient end point x
+shape.fillRadialGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point y
+var endPointY = shape.fillRadialGradientEndPointY();
+
+// set fill radial gradient end point y
+shape.fillRadialGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient end radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient end radius
+var endRadius = shape.fillRadialGradientEndRadius();
+
+// set radial gradient end radius
+shape.fillRadialGradientEndRadius(100);
+ + + +
+ + + +
+
+

fillRadialGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill radial gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point
+var startPoint = shape.fillRadialGradientStartPoint();
+
+// set fill radial gradient start point
+shape.fillRadialGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point x
+var startPointX = shape.fillRadialGradientStartPointX();
+
+// set fill radial gradient start point x
+shape.fillRadialGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point y
+var startPointY = shape.fillRadialGradientStartPointY();
+
+// set fill radial gradient start point y
+shape.fillRadialGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient start radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient start radius
+var startRadius = shape.fillRadialGradientStartRadius();
+
+// set radial gradient start radius
+shape.fillRadialGradientStartRadius(0);
+ + + +
+ + + +
+
+

fillRule(rotation)

+ + +
+
+ + +
+

get/set fill rule

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +CanvasFillRule + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill rule
+var fillRule = shape.fillRule();
+
+// set fill rule
+shape.fillRule('evenodd');
+ + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getSelfRect()

+ + +
+
+ + +
+

return self rectangle (x, y, width, height) of shape.
+This method are not taken into account transformation and styles.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
rect.getSelfRect();  // return {x:0, y:0, width:rect.width(), height:rect.height()}
+circle.getSelfRect();  // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasFill()

+ + +
+
+ + +
+

returns whether or not the shape will be filled

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

hasShadow()

+ + +
+
+ + +
+

returns whether or not a shadow will be rendered

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasStroke()

+ + +
+
+ + +
+

returns whether or not the shape will be stroked

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitFunc(drawFunc)

+ + +
+
+ + +
+

get/set hit draw function. That function is used to draw custom hit area of a shape.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get hit draw function
+var hitFunc = shape.hitFunc();
+
+// set hit draw function
+shape.hitFunc(function(context) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

hitStrokeWidth(hitStrokeWidth)

+ + +
+
+ + +
+

get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var hitStrokeWidth = shape.hitStrokeWidth();
+
+// set hit stroke width
+shape.hitStrokeWidth(20);
+// set hit stroke width always equals to scene stroke width
+shape.hitStrokeWidth('auto');
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

innerRadius(innerRadius)

+ + +
+
+ + +
+

get/set innerRadius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
innerRadius + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get inner radius
+var innerRadius = ring.innerRadius();
+
+// set inner radius
+ring.innerRadius(20);
+ + + +
+ + + +
+
+

intersects(point)

+ + +
+
+ + +
+

determines if point is in the shape, regardless if other shapes are on top of it. Note: because
+this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
+consecutively. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

linearLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set stroke linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point x
+var startPointX = shape.strokeLinearGradientStartPointX();
+
+// set stroke linear gradient start point x
+shape.strokeLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

lineCap(lineCap)

+ + +
+
+ + +
+

get/set line cap. Can be butt, round, or square

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineCap + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line cap
+var lineCap = shape.lineCap();
+
+// set line cap
+shape.lineCap('round');
+ + + +
+ + + +
+
+

lineJoin(lineJoin)

+ + +
+
+ + +
+

get/set line join. Can be miter, round, or bevel. The
+default is miter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineJoin + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line join
+var lineJoin = shape.lineJoin();
+
+// set line join
+shape.lineJoin('round');
+ + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

outerRadius(outerRadius)

+ + +
+
+ + +
+

get/set outerRadius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
outerRadius + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get outer radius
+var outerRadius = ring.outerRadius();
+
+// set outer radius
+ring.outerRadius(20);
+ + + +
+ + + +
+
+

perfectDrawEnabled(perfectDrawEnabled)

+ + +
+
+ + +
+

get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set perfectDrawEnabled to false to improve performance.
+See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
perfectDrawEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get perfectDrawEnabled
+var perfectDrawEnabled = shape.perfectDrawEnabled();
+
+// set perfectDrawEnabled
+shape.perfectDrawEnabled();
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

sceneFunc(drawFunc)

+ + +
+
+ + +
+

get/set scene draw function. That function is used to draw the shape on a canvas.
+Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get scene draw function
+var sceneFunc = shape.sceneFunc();
+
+// set scene draw function
+shape.sceneFunc(function(context, shape) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  // like stroke and fill
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

shadowBlur(blur)

+ + +
+
+ + +
+

get/set shadow blur

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blur + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow blur
+var shadowBlur = shape.shadowBlur();
+
+// set shadow blur
+shape.shadowBlur(10);
+ + + +
+ + + +
+
+

shadowColor(color)

+ + +
+
+ + +
+

get/set shadow color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get shadow color
+var shadow = shape.shadowColor();
+
+// set shadow color with color string
+shape.shadowColor('green');
+
+// set shadow color with hex
+shape.shadowColor('#00ff00');
+
+// set shadow color with rgb
+shape.shadowColor('rgb(0,255,0)');
+
+// set shadow color with rgba and make it 50% opaque
+shape.shadowColor('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

shadowEnabled(enabled)

+ + +
+
+ + +
+

get/set shadow enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadow enabled flag
+var shadowEnabled = shape.shadowEnabled();
+
+// disable shadow
+shape.shadowEnabled(false);
+
+// enable shadow
+shape.shadowEnabled(true);
+ + + +
+ + + +
+
+

shadowForStrokeEnabled(shadowForStrokeEnabled)

+ + +
+
+ + +
+

get/set shadowForStrokeEnabled. Useful for performance optimization.
+You may set shape.shadowForStrokeEnabled(false). In this case stroke will no effect shadow.
+Remember if you set shadowForStrokeEnabled = false for non closed line - that line will have no shadow!.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shadowForStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadowForStrokeEnabled
+var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
+
+// set shadowForStrokeEnabled
+shape.shadowForStrokeEnabled();
+ + + +
+ + + +
+
+

shadowOffset(offset)

+ + +
+
+ + +
+

get/set shadow offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get shadow offset
+var shadowOffset = shape.shadowOffset();
+
+// set shadow offset
+shape.shadowOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

shadowOffsetX(x)

+ + +
+
+ + +
+

get/set shadow offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset x
+var shadowOffsetX = shape.shadowOffsetX();
+
+// set shadow offset x
+shape.shadowOffsetX(5);
+ + + +
+ + + +
+
+

shadowOffsetY(y)

+ + +
+
+ + +
+

get/set shadow offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset y
+var shadowOffsetY = shape.shadowOffsetY();
+
+// set shadow offset y
+shape.shadowOffsetY(5);
+ + + +
+ + + +
+
+

shadowOpacity(opacity)

+ + +
+
+ + +
+

get/set shadow opacity. must be a value between 0 and 1

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow opacity
+var shadowOpacity = shape.shadowOpacity();
+
+// set shadow opacity
+shape.shadowOpacity(0.5);
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke(color)

+ + +
+
+ + +
+

get/set stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get stroke color
+var stroke = shape.stroke();
+
+// set stroke color with color string
+shape.stroke('green');
+
+// set stroke color with hex
+shape.stroke('#00ff00');
+
+// set stroke color with rgb
+shape.stroke('rgb(0,255,0)');
+
+// set stroke color with rgba and make it 50% opaque
+shape.stroke('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

strokeEnabled(enabled)

+ + +
+
+ + +
+

get/set stroke enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke enabled flag
+var strokeEnabled = shape.strokeEnabled();
+
+// disable stroke
+shape.strokeEnabled(false);
+
+// enable stroke
+shape.strokeEnabled(true);
+ + + +
+ + + +
+
+

strokeHitEnabled(strokeHitEnabled)

+ + +
+
+ + +
+

deprecated, use hitStrokeWidth instead! get/set strokeHitEnabled property. Useful for performance optimization.
+You may set shape.strokeHitEnabled(false). In this case stroke will be no draw on hit canvas, so hit area
+of shape will be decreased (by lineWidth / 2). Remember that non closed line with strokeHitEnabled = false
+will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
+Default value is true.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeHitEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get strokeHitEnabled
+var strokeHitEnabled = shape.strokeHitEnabled();
+
+// set strokeHitEnabled
+shape.strokeHitEnabled();
+ + + +
+ + + +
+
+

strokeLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set stroke linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient color stops
+var colorStops = shape.strokeLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point
+var endPoint = shape.strokeLinearGradientEndPoint();
+
+// set stroke linear gradient end point
+shape.strokeLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point x
+var endPointX = shape.strokeLinearGradientEndPointX();
+
+// set stroke linear gradient end point x
+shape.strokeLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point y
+var endPointY = shape.strokeLinearGradientEndPointY();
+
+// set stroke linear gradient end point y
+shape.strokeLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

strokeLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point
+var startPoint = shape.strokeLinearGradientStartPoint();
+
+// set stroke linear gradient start point
+shape.strokeLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point y
+var startPointY = shape.strokeLinearGradientStartPointY();
+
+// set stroke linear gradient start point y
+shape.strokeLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

strokeScaleEnabled(enabled)

+ + +
+
+ + +
+

get/set strokeScale enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke scale enabled flag
+var strokeScaleEnabled = shape.strokeScaleEnabled();
+
+// disable stroke scale
+shape.strokeScaleEnabled(false);
+
+// enable stroke scale
+shape.strokeScaleEnabled(true);
+ + + +
+ + + +
+
+

strokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var strokeWidth = shape.strokeWidth();
+
+// set stroke width
+shape.strokeWidth(10);
+ + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Shape.html b/api/Konva.Shape.html new file mode 100644 index 000000000..ba4c9ba6e --- /dev/null +++ b/api/Konva.Shape.html @@ -0,0 +1,33948 @@ + + + + + + + Konva Class: Shape + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Shape

+
+ +
+ +

+ Konva~ + + Shape +

+ +

Shape constructor. Shapes are primitive objects such as rectangles,
+circles, text, lines, etc.

+ + +
+ + +
+
+ + +
+
+

new Shape(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
fill + + +String + + + + + + + <optional>
+ + + + + +

fill color

fillPatternImage + + +Image + + + + + + + <optional>
+ + + + + +

fill pattern image

fillPatternX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScale + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternScaleX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScaleY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRotation + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRepeat + + +String + + + + + + + <optional>
+ + + + + +

can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"

fillLinearGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillRadialGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the fill. The default value is true

fillPriority + + +String + + + + + + + <optional>
+ + + + + +

can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration

stroke + + +String + + + + + + + <optional>
+ + + + + +

stroke color

strokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

stroke width

fillAfterStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw fill AFTER stroke? Default is false.

hitStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth

strokeHitEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke hit region. The default is true

perfectDrawEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables using buffer canvas. The default is true

shadowForStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables shadow for stroke. The default is true

strokeScaleEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke scale. The default is true

strokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the stroke. The default value is true

lineJoin + + +String + + + + + + + <optional>
+ + + + + +

can be miter, round, or bevel. The default
+is miter

lineCap + + +String + + + + + + + <optional>
+ + + + + +

can be butt, round, or square. The default
+is butt

shadowColor + + +String + + + + + + + <optional>
+ + + + + +
shadowBlur + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

shadowOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
shadowOpacity + + +Number + + + + + + + <optional>
+ + + + + +

shadow opacity. Can be any real number
+between 0 and 1

shadowEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the shadow. The default value is true

dash + + +Array + + + + + + + <optional>
+ + + + + +
dashEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the dashArray. The default value is true

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var customShape = new Konva.Shape({
+  x: 5,
+  y: 10,
+  fill: 'red',
+  // a Konva.Canvas renderer is passed into the sceneFunc function
+  sceneFunc (context, shape) {
+    context.beginPath();
+    context.moveTo(200, 50);
+    context.lineTo(420, 80);
+    context.quadraticCurveTo(300, 100, 260, 170);
+    context.closePath();
+    // Konva specific method
+    context.fillStrokeShape(shape);
+  }
+});
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash array for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart
+ line.dash([10, 5]);
+ // apply dashed stroke that is made up of alternating dashed
+ // lines that are 10px long and 20px apart, and dots that have
+ // a radius of 5px and are 20px apart
+ line.dash([10, 20, 0.001, 20]);
+ + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash offset for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Number + + + + +

offset

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart with an offset of 5px
+ line.dash([10, 5]);
+ line.dashOffset(5);
+ + + +
+ + + +
+
+

dashEnabled(enabled)

+ + +
+
+ + +
+

get/set dash enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get dash enabled flag
+var dashEnabled = shape.dashEnabled();
+
+// disable dash
+shape.dashEnabled(false);
+
+// enable dash
+shape.dashEnabled(true);
+ + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

drawHitFromCache(alphaThreshold)

+ + +
+
+ + +
+

draw hit graph using the cached scene canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alphaThreshold + + +Integer + + + + +

alpha channel threshold that determines whether or not
+a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
+The default is 0

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
shape.cache();
+shape.drawHitFromCache();
+ + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

fill(color)

+ + +
+
+ + +
+

get/set fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill color
+var fill = shape.fill();
+
+// set fill color with color string
+shape.fill('green');
+
+// set fill color with hex
+shape.fill('#00ff00');
+
+// set fill color with rgb
+shape.fill('rgb(0,255,0)');
+
+// set fill color with rgba and make it 50% opaque
+shape.fill('rgba(0,255,0,0.5');
+
+// shape without fill
+shape.fill(null);
+ + + +
+ + + +
+
+

fillAfterStrokeEnabled(fillAfterStrokeEnabled)

+ + +
+
+ + +
+

get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
+In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
+Especially useful for Text objects.
+Default is false.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fillAfterStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
+
+// set stroke width
+shape.fillAfterStrokeEnabled(true);
+ + + +
+ + + +
+
+

fillEnabled(enabled)

+ + +
+
+ + +
+

get/set fill enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get fill enabled flag
+var fillEnabled = shape.fillEnabled();
+
+// disable fill
+shape.fillEnabled(false);
+
+// enable fill
+shape.fillEnabled(true);
+ + + +
+ + + +
+
+

fillLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient color stops
+var colorStops = shape.fillLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point
+var endPoint = shape.fillLinearGradientEndPoint();
+
+// set fill linear gradient end point
+shape.fillLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point x
+var endPointX = shape.fillLinearGradientEndPointX();
+
+// set fill linear gradient end point x
+shape.fillLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point y
+var endPointY = shape.fillLinearGradientEndPointY();
+
+// set fill linear gradient end point y
+shape.fillLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point
+var startPoint = shape.fillLinearGradientStartPoint();
+
+// set fill linear gradient start point
+shape.fillLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point x
+var startPointX = shape.fillLinearGradientStartPointX();
+
+// set fill linear gradient start point x
+shape.fillLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point y
+var startPointY = shape.fillLinearGradientStartPointY();
+
+// set fill linear gradient start point y
+shape.fillLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillPatternImage(image)

+ + +
+
+ + +
+

get/set fill pattern image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +

object

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get fill pattern image
+var fillPatternImage = shape.fillPatternImage();
+
+// set fill pattern image
+var imageObj = new Image();
+imageObj.onload = function() {
+  shape.fillPatternImage(imageObj);
+};
+imageObj.src = 'path/to/image/jpg';
+ + + +
+ + + +
+
+

fillPatternOffset(offset)

+ + +
+
+ + +
+

get/set fill pattern offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset
+var patternOffset = shape.fillPatternOffset();
+
+// set fill pattern offset
+shape.fillPatternOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillPatternOffsetX(x)

+ + +
+
+ + +
+

get/set fill pattern offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset x
+var patternOffsetX = shape.fillPatternOffsetX();
+
+// set fill pattern offset x
+shape.fillPatternOffsetX(20);
+ + + +
+ + + +
+
+

fillPatternOffsetY(y)

+ + +
+
+ + +
+

get/set fill pattern offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset y
+var patternOffsetY = shape.fillPatternOffsetY();
+
+// set fill pattern offset y
+shape.fillPatternOffsetY(10);
+ + + +
+ + + +
+
+

fillPatternRepeat(repeat)

+ + +
+
+ + +
+

get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
repeat + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill pattern repeat
+var repeat = shape.fillPatternRepeat();
+
+// repeat pattern in x direction only
+shape.fillPatternRepeat('repeat-x');
+
+// do not repeat the pattern
+shape.fillPatternRepeat('no-repeat');
+ + + +
+ + + +
+
+

fillPatternRotation(rotation)

+ + +
+
+ + +
+

get/set fill pattern rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill pattern rotation
+var patternRotation = shape.fillPatternRotation();
+
+// set fill pattern rotation
+shape.fillPatternRotation(20);
+ + + +
+ + + +
+
+

fillPatternScale(scale)

+ + +
+
+ + +
+

get/set fill pattern scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale
+var patternScale = shape.fillPatternScale();
+
+// set fill pattern scale
+shape.fillPatternScale({
+  x: 2,
+  y: 2
+});
+ + + +
+ + + +
+
+

fillPatternScaleX(x)

+ + +
+
+ + +
+

get/set fill pattern scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale x
+var patternScaleX = shape.fillPatternScaleX();
+
+// set fill pattern scale x
+shape.fillPatternScaleX(2);
+ + + +
+ + + +
+
+

fillPatternScaleY(y)

+ + +
+
+ + +
+

get/set fill pattern scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale y
+var patternScaleY = shape.fillPatternScaleY();
+
+// set fill pattern scale y
+shape.fillPatternScaleY(2);
+ + + +
+ + + +
+
+

fillPatternX(x)

+ + +
+
+ + +
+

get/set fill pattern x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern x
+var fillPatternX = shape.fillPatternX();
+// set fill pattern x
+shape.fillPatternX(20);
+ + + +
+ + + +
+
+

fillPatternY(y)

+ + +
+
+ + +
+

get/set fill pattern y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern y
+var fillPatternY = shape.fillPatternY();
+// set fill pattern y
+shape.fillPatternY(20);
+ + + +
+ + + +
+
+

fillPriority(priority)

+ + +
+
+ + +
+

get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
+This is handy if you want to toggle between different fill types.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
priority + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill priority
+var fillPriority = shape.fillPriority();
+
+// set fill priority
+shape.fillPriority('linear-gradient');
+ + + +
+ + + +
+
+

fillRadialGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill radial gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient color stops
+var colorStops = shape.fillRadialGradientColorStops();
+
+// create a radial gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillRadialGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill radial gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point
+var endPoint = shape.fillRadialGradientEndPoint();
+
+// set fill radial gradient end point
+shape.fillRadialGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point x
+var endPointX = shape.fillRadialGradientEndPointX();
+
+// set fill radial gradient end point x
+shape.fillRadialGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point y
+var endPointY = shape.fillRadialGradientEndPointY();
+
+// set fill radial gradient end point y
+shape.fillRadialGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient end radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient end radius
+var endRadius = shape.fillRadialGradientEndRadius();
+
+// set radial gradient end radius
+shape.fillRadialGradientEndRadius(100);
+ + + +
+ + + +
+
+

fillRadialGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill radial gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point
+var startPoint = shape.fillRadialGradientStartPoint();
+
+// set fill radial gradient start point
+shape.fillRadialGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point x
+var startPointX = shape.fillRadialGradientStartPointX();
+
+// set fill radial gradient start point x
+shape.fillRadialGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point y
+var startPointY = shape.fillRadialGradientStartPointY();
+
+// set fill radial gradient start point y
+shape.fillRadialGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient start radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient start radius
+var startRadius = shape.fillRadialGradientStartRadius();
+
+// set radial gradient start radius
+shape.fillRadialGradientStartRadius(0);
+ + + +
+ + + +
+
+

fillRule(rotation)

+ + +
+
+ + +
+

get/set fill rule

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +CanvasFillRule + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill rule
+var fillRule = shape.fillRule();
+
+// set fill rule
+shape.fillRule('evenodd');
+ + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getSelfRect()

+ + +
+
+ + +
+

return self rectangle (x, y, width, height) of shape.
+This method are not taken into account transformation and styles.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
rect.getSelfRect();  // return {x:0, y:0, width:rect.width(), height:rect.height()}
+circle.getSelfRect();  // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasFill()

+ + +
+
+ + +
+

returns whether or not the shape will be filled

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

hasShadow()

+ + +
+
+ + +
+

returns whether or not a shadow will be rendered

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasStroke()

+ + +
+
+ + +
+

returns whether or not the shape will be stroked

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitFunc(drawFunc)

+ + +
+
+ + +
+

get/set hit draw function. That function is used to draw custom hit area of a shape.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get hit draw function
+var hitFunc = shape.hitFunc();
+
+// set hit draw function
+shape.hitFunc(function(context) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

hitStrokeWidth(hitStrokeWidth)

+ + +
+
+ + +
+

get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var hitStrokeWidth = shape.hitStrokeWidth();
+
+// set hit stroke width
+shape.hitStrokeWidth(20);
+// set hit stroke width always equals to scene stroke width
+shape.hitStrokeWidth('auto');
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

intersects(point)

+ + +
+
+ + +
+

determines if point is in the shape, regardless if other shapes are on top of it. Note: because
+this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
+consecutively. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

linearLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set stroke linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point x
+var startPointX = shape.strokeLinearGradientStartPointX();
+
+// set stroke linear gradient start point x
+shape.strokeLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

lineCap(lineCap)

+ + +
+
+ + +
+

get/set line cap. Can be butt, round, or square

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineCap + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line cap
+var lineCap = shape.lineCap();
+
+// set line cap
+shape.lineCap('round');
+ + + +
+ + + +
+
+

lineJoin(lineJoin)

+ + +
+
+ + +
+

get/set line join. Can be miter, round, or bevel. The
+default is miter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineJoin + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line join
+var lineJoin = shape.lineJoin();
+
+// set line join
+shape.lineJoin('round');
+ + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

perfectDrawEnabled(perfectDrawEnabled)

+ + +
+
+ + +
+

get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set perfectDrawEnabled to false to improve performance.
+See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
perfectDrawEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get perfectDrawEnabled
+var perfectDrawEnabled = shape.perfectDrawEnabled();
+
+// set perfectDrawEnabled
+shape.perfectDrawEnabled();
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

sceneFunc(drawFunc)

+ + +
+
+ + +
+

get/set scene draw function. That function is used to draw the shape on a canvas.
+Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get scene draw function
+var sceneFunc = shape.sceneFunc();
+
+// set scene draw function
+shape.sceneFunc(function(context, shape) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  // like stroke and fill
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

shadowBlur(blur)

+ + +
+
+ + +
+

get/set shadow blur

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blur + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow blur
+var shadowBlur = shape.shadowBlur();
+
+// set shadow blur
+shape.shadowBlur(10);
+ + + +
+ + + +
+
+

shadowColor(color)

+ + +
+
+ + +
+

get/set shadow color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get shadow color
+var shadow = shape.shadowColor();
+
+// set shadow color with color string
+shape.shadowColor('green');
+
+// set shadow color with hex
+shape.shadowColor('#00ff00');
+
+// set shadow color with rgb
+shape.shadowColor('rgb(0,255,0)');
+
+// set shadow color with rgba and make it 50% opaque
+shape.shadowColor('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

shadowEnabled(enabled)

+ + +
+
+ + +
+

get/set shadow enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadow enabled flag
+var shadowEnabled = shape.shadowEnabled();
+
+// disable shadow
+shape.shadowEnabled(false);
+
+// enable shadow
+shape.shadowEnabled(true);
+ + + +
+ + + +
+
+

shadowForStrokeEnabled(shadowForStrokeEnabled)

+ + +
+
+ + +
+

get/set shadowForStrokeEnabled. Useful for performance optimization.
+You may set shape.shadowForStrokeEnabled(false). In this case stroke will no effect shadow.
+Remember if you set shadowForStrokeEnabled = false for non closed line - that line will have no shadow!.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shadowForStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadowForStrokeEnabled
+var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
+
+// set shadowForStrokeEnabled
+shape.shadowForStrokeEnabled();
+ + + +
+ + + +
+
+

shadowOffset(offset)

+ + +
+
+ + +
+

get/set shadow offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get shadow offset
+var shadowOffset = shape.shadowOffset();
+
+// set shadow offset
+shape.shadowOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

shadowOffsetX(x)

+ + +
+
+ + +
+

get/set shadow offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset x
+var shadowOffsetX = shape.shadowOffsetX();
+
+// set shadow offset x
+shape.shadowOffsetX(5);
+ + + +
+ + + +
+
+

shadowOffsetY(y)

+ + +
+
+ + +
+

get/set shadow offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset y
+var shadowOffsetY = shape.shadowOffsetY();
+
+// set shadow offset y
+shape.shadowOffsetY(5);
+ + + +
+ + + +
+
+

shadowOpacity(opacity)

+ + +
+
+ + +
+

get/set shadow opacity. must be a value between 0 and 1

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow opacity
+var shadowOpacity = shape.shadowOpacity();
+
+// set shadow opacity
+shape.shadowOpacity(0.5);
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke(color)

+ + +
+
+ + +
+

get/set stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get stroke color
+var stroke = shape.stroke();
+
+// set stroke color with color string
+shape.stroke('green');
+
+// set stroke color with hex
+shape.stroke('#00ff00');
+
+// set stroke color with rgb
+shape.stroke('rgb(0,255,0)');
+
+// set stroke color with rgba and make it 50% opaque
+shape.stroke('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

strokeEnabled(enabled)

+ + +
+
+ + +
+

get/set stroke enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke enabled flag
+var strokeEnabled = shape.strokeEnabled();
+
+// disable stroke
+shape.strokeEnabled(false);
+
+// enable stroke
+shape.strokeEnabled(true);
+ + + +
+ + + +
+
+

strokeHitEnabled(strokeHitEnabled)

+ + +
+
+ + +
+

deprecated, use hitStrokeWidth instead! get/set strokeHitEnabled property. Useful for performance optimization.
+You may set shape.strokeHitEnabled(false). In this case stroke will be no draw on hit canvas, so hit area
+of shape will be decreased (by lineWidth / 2). Remember that non closed line with strokeHitEnabled = false
+will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
+Default value is true.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeHitEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get strokeHitEnabled
+var strokeHitEnabled = shape.strokeHitEnabled();
+
+// set strokeHitEnabled
+shape.strokeHitEnabled();
+ + + +
+ + + +
+
+

strokeLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set stroke linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient color stops
+var colorStops = shape.strokeLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point
+var endPoint = shape.strokeLinearGradientEndPoint();
+
+// set stroke linear gradient end point
+shape.strokeLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point x
+var endPointX = shape.strokeLinearGradientEndPointX();
+
+// set stroke linear gradient end point x
+shape.strokeLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point y
+var endPointY = shape.strokeLinearGradientEndPointY();
+
+// set stroke linear gradient end point y
+shape.strokeLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

strokeLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point
+var startPoint = shape.strokeLinearGradientStartPoint();
+
+// set stroke linear gradient start point
+shape.strokeLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point y
+var startPointY = shape.strokeLinearGradientStartPointY();
+
+// set stroke linear gradient start point y
+shape.strokeLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

strokeScaleEnabled(enabled)

+ + +
+
+ + +
+

get/set strokeScale enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke scale enabled flag
+var strokeScaleEnabled = shape.strokeScaleEnabled();
+
+// disable stroke scale
+shape.strokeScaleEnabled(false);
+
+// enable stroke scale
+shape.strokeScaleEnabled(true);
+ + + +
+ + + +
+
+

strokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var strokeWidth = shape.strokeWidth();
+
+// set stroke width
+shape.strokeWidth(10);
+ + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Sprite.html b/api/Konva.Sprite.html new file mode 100644 index 000000000..2aa76aab3 --- /dev/null +++ b/api/Konva.Sprite.html @@ -0,0 +1,36178 @@ + + + + + + + Konva Class: Sprite + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Sprite

+
+ +
+ +

+ Konva~ + + Sprite +

+ +

Sprite constructor

+ + +
+ + +
+
+ + +
+
+

new Sprite(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
animation + + +String + + + + + + + + + + +

animation key

animations + + +Object + + + + + + + + + + +

animation map

frameIndex + + +Integer + + + + + + + <optional>
+ + + + + +

animation frame index

image + + +Image + + + + + + + + + + +

image object

frameRate + + +Integer + + + + + + + <optional>
+ + + + + +

animation frame rate

fill + + +String + + + + + + + <optional>
+ + + + + +

fill color

fillPatternImage + + +Image + + + + + + + <optional>
+ + + + + +

fill pattern image

fillPatternX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScale + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternScaleX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScaleY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRotation + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRepeat + + +String + + + + + + + <optional>
+ + + + + +

can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"

fillLinearGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillRadialGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the fill. The default value is true

fillPriority + + +String + + + + + + + <optional>
+ + + + + +

can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration

stroke + + +String + + + + + + + <optional>
+ + + + + +

stroke color

strokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

stroke width

fillAfterStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw fill AFTER stroke? Default is false.

hitStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth

strokeHitEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke hit region. The default is true

perfectDrawEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables using buffer canvas. The default is true

shadowForStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables shadow for stroke. The default is true

strokeScaleEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke scale. The default is true

strokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the stroke. The default value is true

lineJoin + + +String + + + + + + + <optional>
+ + + + + +

can be miter, round, or bevel. The default
+is miter

lineCap + + +String + + + + + + + <optional>
+ + + + + +

can be butt, round, or square. The default
+is butt

shadowColor + + +String + + + + + + + <optional>
+ + + + + +
shadowBlur + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

shadowOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
shadowOpacity + + +Number + + + + + + + <optional>
+ + + + + +

shadow opacity. Can be any real number
+between 0 and 1

shadowEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the shadow. The default value is true

dash + + +Array + + + + + + + <optional>
+ + + + + +
dashEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the dashArray. The default value is true

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var imageObj = new Image();
+imageObj.onload = function() {
+  var sprite = new Konva.Sprite({
+    x: 200,
+    y: 100,
+    image: imageObj,
+    animation: 'standing',
+    animations: {
+      standing: [
+        // x, y, width, height (6 frames)
+        0, 0, 49, 109,
+        52, 0, 49, 109,
+        105, 0, 49, 109,
+        158, 0, 49, 109,
+        210, 0, 49, 109,
+        262, 0, 49, 109
+      ],
+      kicking: [
+        // x, y, width, height (6 frames)
+        0, 109, 45, 98,
+        45, 109, 45, 98,
+        95, 109, 63, 98,
+        156, 109, 70, 98,
+        229, 109, 60, 98,
+        287, 109, 41, 98
+      ]
+    },
+    frameRate: 7,
+    frameIndex: 0
+  });
+};
+imageObj.src = '/path/to/image.jpg'
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

animation(anim)

+ + +
+
+ + +
+

get/set animation key

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
anim + + +String + + + + +

animation key

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get animation key
+var animation = sprite.animation();
+
+// set animation key
+sprite.animation('kicking');
+ + + +
+ + + +
+
+

animations(animations)

+ + +
+
+ + +
+

get/set animations map

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
animations + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get animations map
+var animations = sprite.animations();
+
+// set animations map
+sprite.animations({
+  standing: [
+    // x, y, width, height (6 frames)
+    0, 0, 49, 109,
+    52, 0, 49, 109,
+    105, 0, 49, 109,
+    158, 0, 49, 109,
+    210, 0, 49, 109,
+    262, 0, 49, 109
+  ],
+  kicking: [
+    // x, y, width, height (6 frames)
+    0, 109, 45, 98,
+    45, 109, 45, 98,
+    95, 109, 63, 98,
+    156, 109, 70, 98,
+    229, 109, 60, 98,
+    287, 109, 41, 98
+  ]
+});
+ + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash array for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart
+ line.dash([10, 5]);
+ // apply dashed stroke that is made up of alternating dashed
+ // lines that are 10px long and 20px apart, and dots that have
+ // a radius of 5px and are 20px apart
+ line.dash([10, 20, 0.001, 20]);
+ + + +
+ + + +
+
+

dashEnabled(enabled)

+ + +
+
+ + +
+

get/set dash enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get dash enabled flag
+var dashEnabled = shape.dashEnabled();
+
+// disable dash
+shape.dashEnabled(false);
+
+// enable dash
+shape.dashEnabled(true);
+ + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

drawHitFromCache(alphaThreshold)

+ + +
+
+ + +
+

draw hit graph using the cached scene canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alphaThreshold + + +Integer + + + + +

alpha channel threshold that determines whether or not
+a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
+The default is 0

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
shape.cache();
+shape.drawHitFromCache();
+ + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

fill(color)

+ + +
+
+ + +
+

get/set fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill color
+var fill = shape.fill();
+
+// set fill color with color string
+shape.fill('green');
+
+// set fill color with hex
+shape.fill('#00ff00');
+
+// set fill color with rgb
+shape.fill('rgb(0,255,0)');
+
+// set fill color with rgba and make it 50% opaque
+shape.fill('rgba(0,255,0,0.5');
+
+// shape without fill
+shape.fill(null);
+ + + +
+ + + +
+
+

fillAfterStrokeEnabled(fillAfterStrokeEnabled)

+ + +
+
+ + +
+

get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
+In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
+Especially useful for Text objects.
+Default is false.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fillAfterStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
+
+// set stroke width
+shape.fillAfterStrokeEnabled(true);
+ + + +
+ + + +
+
+

fillEnabled(enabled)

+ + +
+
+ + +
+

get/set fill enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get fill enabled flag
+var fillEnabled = shape.fillEnabled();
+
+// disable fill
+shape.fillEnabled(false);
+
+// enable fill
+shape.fillEnabled(true);
+ + + +
+ + + +
+
+

fillLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient color stops
+var colorStops = shape.fillLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point
+var endPoint = shape.fillLinearGradientEndPoint();
+
+// set fill linear gradient end point
+shape.fillLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point x
+var endPointX = shape.fillLinearGradientEndPointX();
+
+// set fill linear gradient end point x
+shape.fillLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point y
+var endPointY = shape.fillLinearGradientEndPointY();
+
+// set fill linear gradient end point y
+shape.fillLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point
+var startPoint = shape.fillLinearGradientStartPoint();
+
+// set fill linear gradient start point
+shape.fillLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point x
+var startPointX = shape.fillLinearGradientStartPointX();
+
+// set fill linear gradient start point x
+shape.fillLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point y
+var startPointY = shape.fillLinearGradientStartPointY();
+
+// set fill linear gradient start point y
+shape.fillLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillPatternImage(image)

+ + +
+
+ + +
+

get/set fill pattern image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +

object

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get fill pattern image
+var fillPatternImage = shape.fillPatternImage();
+
+// set fill pattern image
+var imageObj = new Image();
+imageObj.onload = function() {
+  shape.fillPatternImage(imageObj);
+};
+imageObj.src = 'path/to/image/jpg';
+ + + +
+ + + +
+
+

fillPatternOffset(offset)

+ + +
+
+ + +
+

get/set fill pattern offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset
+var patternOffset = shape.fillPatternOffset();
+
+// set fill pattern offset
+shape.fillPatternOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillPatternOffsetX(x)

+ + +
+
+ + +
+

get/set fill pattern offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset x
+var patternOffsetX = shape.fillPatternOffsetX();
+
+// set fill pattern offset x
+shape.fillPatternOffsetX(20);
+ + + +
+ + + +
+
+

fillPatternOffsetY(y)

+ + +
+
+ + +
+

get/set fill pattern offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset y
+var patternOffsetY = shape.fillPatternOffsetY();
+
+// set fill pattern offset y
+shape.fillPatternOffsetY(10);
+ + + +
+ + + +
+
+

fillPatternRepeat(repeat)

+ + +
+
+ + +
+

get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
repeat + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill pattern repeat
+var repeat = shape.fillPatternRepeat();
+
+// repeat pattern in x direction only
+shape.fillPatternRepeat('repeat-x');
+
+// do not repeat the pattern
+shape.fillPatternRepeat('no-repeat');
+ + + +
+ + + +
+
+

fillPatternRotation(rotation)

+ + +
+
+ + +
+

get/set fill pattern rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill pattern rotation
+var patternRotation = shape.fillPatternRotation();
+
+// set fill pattern rotation
+shape.fillPatternRotation(20);
+ + + +
+ + + +
+
+

fillPatternScale(scale)

+ + +
+
+ + +
+

get/set fill pattern scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale
+var patternScale = shape.fillPatternScale();
+
+// set fill pattern scale
+shape.fillPatternScale({
+  x: 2,
+  y: 2
+});
+ + + +
+ + + +
+
+

fillPatternScaleX(x)

+ + +
+
+ + +
+

get/set fill pattern scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale x
+var patternScaleX = shape.fillPatternScaleX();
+
+// set fill pattern scale x
+shape.fillPatternScaleX(2);
+ + + +
+ + + +
+
+

fillPatternScaleY(y)

+ + +
+
+ + +
+

get/set fill pattern scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale y
+var patternScaleY = shape.fillPatternScaleY();
+
+// set fill pattern scale y
+shape.fillPatternScaleY(2);
+ + + +
+ + + +
+
+

fillPatternX(x)

+ + +
+
+ + +
+

get/set fill pattern x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern x
+var fillPatternX = shape.fillPatternX();
+// set fill pattern x
+shape.fillPatternX(20);
+ + + +
+ + + +
+
+

fillPatternY(y)

+ + +
+
+ + +
+

get/set fill pattern y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern y
+var fillPatternY = shape.fillPatternY();
+// set fill pattern y
+shape.fillPatternY(20);
+ + + +
+ + + +
+
+

fillPriority(priority)

+ + +
+
+ + +
+

get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
+This is handy if you want to toggle between different fill types.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
priority + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill priority
+var fillPriority = shape.fillPriority();
+
+// set fill priority
+shape.fillPriority('linear-gradient');
+ + + +
+ + + +
+
+

fillRadialGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill radial gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient color stops
+var colorStops = shape.fillRadialGradientColorStops();
+
+// create a radial gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillRadialGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill radial gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point
+var endPoint = shape.fillRadialGradientEndPoint();
+
+// set fill radial gradient end point
+shape.fillRadialGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point x
+var endPointX = shape.fillRadialGradientEndPointX();
+
+// set fill radial gradient end point x
+shape.fillRadialGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point y
+var endPointY = shape.fillRadialGradientEndPointY();
+
+// set fill radial gradient end point y
+shape.fillRadialGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient end radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient end radius
+var endRadius = shape.fillRadialGradientEndRadius();
+
+// set radial gradient end radius
+shape.fillRadialGradientEndRadius(100);
+ + + +
+ + + +
+
+

fillRadialGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill radial gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point
+var startPoint = shape.fillRadialGradientStartPoint();
+
+// set fill radial gradient start point
+shape.fillRadialGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point x
+var startPointX = shape.fillRadialGradientStartPointX();
+
+// set fill radial gradient start point x
+shape.fillRadialGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point y
+var startPointY = shape.fillRadialGradientStartPointY();
+
+// set fill radial gradient start point y
+shape.fillRadialGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient start radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient start radius
+var startRadius = shape.fillRadialGradientStartRadius();
+
+// set radial gradient start radius
+shape.fillRadialGradientStartRadius(0);
+ + + +
+ + + +
+
+

fillRule(rotation)

+ + +
+
+ + +
+

get/set fill rule

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +CanvasFillRule + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill rule
+var fillRule = shape.fillRule();
+
+// set fill rule
+shape.fillRule('evenodd');
+ + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

frameIndex(frameIndex)

+ + +
+
+ + +
+

set/set animation frame index

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
frameIndex + + +Integer + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get animation frame index
+var frameIndex = sprite.frameIndex();
+
+// set animation frame index
+sprite.frameIndex(3);
+ + + +
+ + + +
+
+

frameRate(frameRate)

+ + +
+
+ + +
+

get/set frame rate in frames per second. Increase this number to make the sprite
+animation run faster, and decrease the number to make the sprite animation run slower
+The default is 17 frames per second

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
frameRate + + +Integer + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get frame rate
+var frameRate = sprite.frameRate();
+
+// set frame rate to 2 frames per second
+sprite.frameRate(2);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getSelfRect()

+ + +
+
+ + +
+

return self rectangle (x, y, width, height) of shape.
+This method are not taken into account transformation and styles.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
rect.getSelfRect();  // return {x:0, y:0, width:rect.width(), height:rect.height()}
+circle.getSelfRect();  // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasFill()

+ + +
+
+ + +
+

returns whether or not the shape will be filled

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

hasShadow()

+ + +
+
+ + +
+

returns whether or not a shadow will be rendered

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasStroke()

+ + +
+
+ + +
+

returns whether or not the shape will be stroked

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitFunc(drawFunc)

+ + +
+
+ + +
+

get/set hit draw function. That function is used to draw custom hit area of a shape.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get hit draw function
+var hitFunc = shape.hitFunc();
+
+// set hit draw function
+shape.hitFunc(function(context) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

hitStrokeWidth(hitStrokeWidth)

+ + +
+
+ + +
+

get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var hitStrokeWidth = shape.hitStrokeWidth();
+
+// set hit stroke width
+shape.hitStrokeWidth(20);
+// set hit stroke width always equals to scene stroke width
+shape.hitStrokeWidth('auto');
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

image(image)

+ + +
+
+ + +
+

get/set image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get image
+var image = sprite.image();
+
+// set image
+sprite.image(imageObj);
+ + + +
+ + + +
+
+

intersects(point)

+ + +
+
+ + +
+

determines if point is in the shape, regardless if other shapes are on top of it. Note: because
+this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
+consecutively. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isRunning()

+ + +
+
+ + +
+

determine if animation of sprite is running or not. returns true or false

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

linearLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set stroke linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point x
+var startPointX = shape.strokeLinearGradientStartPointX();
+
+// set stroke linear gradient start point x
+shape.strokeLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

lineCap(lineCap)

+ + +
+
+ + +
+

get/set line cap. Can be butt, round, or square

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineCap + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line cap
+var lineCap = shape.lineCap();
+
+// set line cap
+shape.lineCap('round');
+ + + +
+ + + +
+
+

lineJoin(lineJoin)

+ + +
+
+ + +
+

get/set line join. Can be miter, round, or bevel. The
+default is miter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineJoin + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line join
+var lineJoin = shape.lineJoin();
+
+// set line join
+shape.lineJoin('round');
+ + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsets(offsets)

+ + +
+
+ + +
+

get/set offsets map

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offsets + + +Object + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get offsets map
+var offsets = sprite.offsets();
+
+// set offsets map
+sprite.offsets({
+  standing: [
+    // x, y (6 frames)
+    0, 0,
+    0, 0,
+    5, 0,
+    0, 0,
+    0, 3,
+    2, 0
+  ],
+  kicking: [
+    // x, y (6 frames)
+    0, 5,
+    5, 0,
+    10, 0,
+    0, 0,
+    2, 1,
+    0, 0
+  ]
+});
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

perfectDrawEnabled(perfectDrawEnabled)

+ + +
+
+ + +
+

get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set perfectDrawEnabled to false to improve performance.
+See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
perfectDrawEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get perfectDrawEnabled
+var perfectDrawEnabled = shape.perfectDrawEnabled();
+
+// set perfectDrawEnabled
+shape.perfectDrawEnabled();
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

sceneFunc(drawFunc)

+ + +
+
+ + +
+

get/set scene draw function. That function is used to draw the shape on a canvas.
+Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get scene draw function
+var sceneFunc = shape.sceneFunc();
+
+// set scene draw function
+shape.sceneFunc(function(context, shape) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  // like stroke and fill
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

shadowBlur(blur)

+ + +
+
+ + +
+

get/set shadow blur

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blur + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow blur
+var shadowBlur = shape.shadowBlur();
+
+// set shadow blur
+shape.shadowBlur(10);
+ + + +
+ + + +
+
+

shadowColor(color)

+ + +
+
+ + +
+

get/set shadow color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get shadow color
+var shadow = shape.shadowColor();
+
+// set shadow color with color string
+shape.shadowColor('green');
+
+// set shadow color with hex
+shape.shadowColor('#00ff00');
+
+// set shadow color with rgb
+shape.shadowColor('rgb(0,255,0)');
+
+// set shadow color with rgba and make it 50% opaque
+shape.shadowColor('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

shadowEnabled(enabled)

+ + +
+
+ + +
+

get/set shadow enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadow enabled flag
+var shadowEnabled = shape.shadowEnabled();
+
+// disable shadow
+shape.shadowEnabled(false);
+
+// enable shadow
+shape.shadowEnabled(true);
+ + + +
+ + + +
+
+

shadowForStrokeEnabled(shadowForStrokeEnabled)

+ + +
+
+ + +
+

get/set shadowForStrokeEnabled. Useful for performance optimization.
+You may set shape.shadowForStrokeEnabled(false). In this case stroke will no effect shadow.
+Remember if you set shadowForStrokeEnabled = false for non closed line - that line will have no shadow!.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shadowForStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadowForStrokeEnabled
+var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
+
+// set shadowForStrokeEnabled
+shape.shadowForStrokeEnabled();
+ + + +
+ + + +
+
+

shadowOffset(offset)

+ + +
+
+ + +
+

get/set shadow offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get shadow offset
+var shadowOffset = shape.shadowOffset();
+
+// set shadow offset
+shape.shadowOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

shadowOffsetX(x)

+ + +
+
+ + +
+

get/set shadow offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset x
+var shadowOffsetX = shape.shadowOffsetX();
+
+// set shadow offset x
+shape.shadowOffsetX(5);
+ + + +
+ + + +
+
+

shadowOffsetY(y)

+ + +
+
+ + +
+

get/set shadow offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset y
+var shadowOffsetY = shape.shadowOffsetY();
+
+// set shadow offset y
+shape.shadowOffsetY(5);
+ + + +
+ + + +
+
+

shadowOpacity(opacity)

+ + +
+
+ + +
+

get/set shadow opacity. must be a value between 0 and 1

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow opacity
+var shadowOpacity = shape.shadowOpacity();
+
+// set shadow opacity
+shape.shadowOpacity(0.5);
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

start()

+ + +
+
+ + +
+

start sprite animation

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stop()

+ + +
+
+ + +
+

stop sprite animation

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke(color)

+ + +
+
+ + +
+

get/set stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get stroke color
+var stroke = shape.stroke();
+
+// set stroke color with color string
+shape.stroke('green');
+
+// set stroke color with hex
+shape.stroke('#00ff00');
+
+// set stroke color with rgb
+shape.stroke('rgb(0,255,0)');
+
+// set stroke color with rgba and make it 50% opaque
+shape.stroke('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

strokeEnabled(enabled)

+ + +
+
+ + +
+

get/set stroke enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke enabled flag
+var strokeEnabled = shape.strokeEnabled();
+
+// disable stroke
+shape.strokeEnabled(false);
+
+// enable stroke
+shape.strokeEnabled(true);
+ + + +
+ + + +
+
+

strokeHitEnabled(strokeHitEnabled)

+ + +
+
+ + +
+

deprecated, use hitStrokeWidth instead! get/set strokeHitEnabled property. Useful for performance optimization.
+You may set shape.strokeHitEnabled(false). In this case stroke will be no draw on hit canvas, so hit area
+of shape will be decreased (by lineWidth / 2). Remember that non closed line with strokeHitEnabled = false
+will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
+Default value is true.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeHitEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get strokeHitEnabled
+var strokeHitEnabled = shape.strokeHitEnabled();
+
+// set strokeHitEnabled
+shape.strokeHitEnabled();
+ + + +
+ + + +
+
+

strokeLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set stroke linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient color stops
+var colorStops = shape.strokeLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point
+var endPoint = shape.strokeLinearGradientEndPoint();
+
+// set stroke linear gradient end point
+shape.strokeLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point x
+var endPointX = shape.strokeLinearGradientEndPointX();
+
+// set stroke linear gradient end point x
+shape.strokeLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point y
+var endPointY = shape.strokeLinearGradientEndPointY();
+
+// set stroke linear gradient end point y
+shape.strokeLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

strokeLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point
+var startPoint = shape.strokeLinearGradientStartPoint();
+
+// set stroke linear gradient start point
+shape.strokeLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point y
+var startPointY = shape.strokeLinearGradientStartPointY();
+
+// set stroke linear gradient start point y
+shape.strokeLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

strokeScaleEnabled(enabled)

+ + +
+
+ + +
+

get/set strokeScale enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke scale enabled flag
+var strokeScaleEnabled = shape.strokeScaleEnabled();
+
+// disable stroke scale
+shape.strokeScaleEnabled(false);
+
+// enable stroke scale
+shape.strokeScaleEnabled(true);
+ + + +
+ + + +
+
+

strokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var strokeWidth = shape.strokeWidth();
+
+// set stroke width
+shape.strokeWidth(10);
+ + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Stage.html b/api/Konva.Stage.html new file mode 100644 index 000000000..b72c364f7 --- /dev/null +++ b/api/Konva.Stage.html @@ -0,0 +1,24418 @@ + + + + + + + Konva Class: Stage + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Stage

+
+ +
+ +

+ Konva~ + + Stage +

+ +

Stage constructor. A stage is used to contain multiple layers

+ + +
+ + +
+
+ + +
+
+

new Stage(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
container + + +String +| + +Element + + + + + + + + + + +

Container selector or DOM element

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var stage = new Konva.Stage({
+  width: 500,
+  height: 800,
+  container: 'containerId' // or "#containerId" or ".containerClass"
+});
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

add(children)

+ + +
+
+ + +
+

add a child and children into container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
children + + +Konva.Node + + + + + + + + + + + <repeatable>
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Container + + + +
+
+ + + + + +
Example
+ +
layer.add(rect);
+layer.add(shape1, shape2, shape3);
+// empty arrays are accepted, though each individual child must be defined
+layer.add(...shapes);
+// remember to redraw layer if you changed something
+layer.draw();
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

batchDraw()

+ + +
+
+ + +
+

batch draw

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

this

+
+ + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clear()

+ + +
+
+ + +
+

clear all layers

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clip(clip)

+ + +
+
+ + +
+

get/set clip

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
clip + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get clip
+var clip = container.clip();
+
+// set clip
+container.clip({
+  x: 20,
+  y: 20,
+  width: 20,
+  height: 20
+});
+ + + +
+ + + +
+
+

clipFunc(function)

+ + +
+
+ + +
+

get/set clip function

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
function + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get clip function
+var clipFunction = container.clipFunc();
+
+// set clip function
+container.clipFunc(function(ctx) {
+  ctx.rect(0, 0, 100, 100);
+});
+
+container.clipFunc(function(ctx) {
+  // optionally return a clip Path2D and clip-rule or just the clip-rule
+  return [new Path2D('M0 0v50h50Z'), 'evenodd']
+});
+ + + +
+ + + +
+
+

clipHeight(height)

+ + +
+
+ + +
+

get/set clip height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clip height
+var clipHeight = container.clipHeight();
+
+// set clip height
+container.clipHeight(100);
+ + + +
+ + + +
+
+

clipWidth(width)

+ + +
+
+ + +
+

get/set clip width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clip width
+var clipWidth = container.clipWidth();
+
+// set clip width
+container.clipWidth(100);
+ + + +
+ + + +
+
+

clipX(x)

+ + +
+
+ + +
+

get/set clip x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clip x
+var clipX = container.clipX();
+
+// set clip x
+container.clipX(10);
+ + + +
+ + + +
+
+

clipY(y)

+ + +
+
+ + +
+

get/set clip y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clip y
+var clipY = container.clipY();
+
+// set clip y
+container.clipY(10);
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

container()

+ + +
+
+ + +
+

get/set container DOM element

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

container

+
+ + + +
+
+ Type +
+
+ +DomElement + + + +
+
+ + + + + +
Example
+ +
// get container
+var container = stage.container();
+// set container
+var container = document.createElement('div');
+body.appendChild(container);
+stage.container(container);
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

destroyChildren()

+ + +
+
+ + +
+

destroy all children nodes.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

find(selector)

+ + +
+
+ + +
+

return an array of nodes that match the selector.
+You can provide a string with '#' for id selections and '.' for name selections.
+Or a function that will return true/false when a node is passed through. See example below.
+With strings you can also select by type or class name. Pass multiple selectors
+separated by a comma.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
selector + + +String +| + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
Passing a string as a selector
+// select node with id foo
+var node = stage.find('#foo');
+
+// select nodes with name bar inside layer
+var nodes = layer.find('.bar');
+
+// select all groups inside layer
+var nodes = layer.find('Group');
+
+// select all rectangles inside layer
+var nodes = layer.find('Rect');
+
+// select node with an id of foo or a name of bar inside layer
+var nodes = layer.find('#foo, .bar');
+
+Passing a function as a selector
+
+// get all groups with a function
+var groups = stage.find(node => {
+ return node.getType() === 'Group';
+});
+
+// get only Nodes with partial opacity
+var alphaNodes = layer.find(node => {
+ return node.getType() === 'Node' && node.getAbsoluteOpacity() < 1;
+});
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

findOne(selector)

+ + +
+
+ + +
+

return a first node from find method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
selector + + +String +| + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node +| + +Undefined + + + +
+
+ + + + + +
Example
+ +
// select node with id foo
+var node = stage.findOne('#foo');
+
+// select node with name bar inside layer
+var nodes = layer.findOne('.bar');
+
+// select the first node to return true in a function
+var node = stage.findOne(node => {
+ return node.getType() === 'Shape'
+})
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAllIntersections(pos)

+ + +
+
+ + +
+

get all shapes that intersect a point. Note: because this method must clear a temporary
+canvas and redraw every shape inside the container, it should only be used for special situations
+because it performs very poorly. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better
+nodes with listening set to false will not be detected

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

array of shapes

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getChildren( [filterFunc])

+ + +
+
+ + +
+

returns an array of direct descendant nodes

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
filterFunc + + +function + + + + + + + <optional>
+ + + + + +

filter function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get all children
+var children = layer.getChildren();
+
+// get only circles
+var circles = layer.getChildren(function(node){
+   return node.getClassName() === 'Circle';
+});
+ + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

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:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
var shape = stage.getIntersection({x: 50, y: 50});
+ + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getLayers()

+ + +
+
+ + +
+

returns an array of layers

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

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

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Vector2d +| + +null + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasChildren()

+ + +
+
+ + +
+

determine if node has children

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

isAncestorOf(node)

+ + +
+
+ + +
+

determine if node is an ancestor
+of descendant

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
node + + +Konva.Node + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeChildren()

+ + +
+
+ + +
+

remove all children. Children will be still in memory.
+If you want to completely destroy all children please use "destroyChildren" method instead

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

setContainer(container)

+ + +
+
+ + +
+

set container dom element which contains the stage wrapper div element

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
container + + +DomElement + + + + +

can pass in a dom element or id string

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

setPointersPositions(event)

+ + +
+
+ + +
+

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:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
event + + +Object + + + + +

Event object

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
window.addEventListener('mousemove', (e) => {
+  stage.setPointersPositions(e);
+});
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Star.html b/api/Konva.Star.html new file mode 100644 index 000000000..43d0ab229 --- /dev/null +++ b/api/Konva.Star.html @@ -0,0 +1,34425 @@ + + + + + + + Konva Class: Star + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Star

+
+ +
+ +

+ Konva. + + Star +

+ +

Star constructor

+ + +
+ + +
+
+ + +
+
+

new Star(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
numPoints + + +Integer + + + + + + + + + + +
innerRadius + + +Number + + + + + + + + + + +
outerRadius + + +Number + + + + + + + + + + +
fill + + +String + + + + + + + <optional>
+ + + + + +

fill color

fillPatternImage + + +Image + + + + + + + <optional>
+ + + + + +

fill pattern image

fillPatternX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScale + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternScaleX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScaleY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRotation + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRepeat + + +String + + + + + + + <optional>
+ + + + + +

can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"

fillLinearGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillRadialGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the fill. The default value is true

fillPriority + + +String + + + + + + + <optional>
+ + + + + +

can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration

stroke + + +String + + + + + + + <optional>
+ + + + + +

stroke color

strokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

stroke width

fillAfterStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw fill AFTER stroke? Default is false.

hitStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth

strokeHitEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke hit region. The default is true

perfectDrawEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables using buffer canvas. The default is true

shadowForStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables shadow for stroke. The default is true

strokeScaleEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke scale. The default is true

strokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the stroke. The default value is true

lineJoin + + +String + + + + + + + <optional>
+ + + + + +

can be miter, round, or bevel. The default
+is miter

lineCap + + +String + + + + + + + <optional>
+ + + + + +

can be butt, round, or square. The default
+is butt

shadowColor + + +String + + + + + + + <optional>
+ + + + + +
shadowBlur + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

shadowOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
shadowOpacity + + +Number + + + + + + + <optional>
+ + + + + +

shadow opacity. Can be any real number
+between 0 and 1

shadowEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the shadow. The default value is true

dash + + +Array + + + + + + + <optional>
+ + + + + +
dashEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the dashArray. The default value is true

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var star = new Konva.Star({
+  x: 100,
+  y: 200,
+  numPoints: 5,
+  innerRadius: 70,
+  outerRadius: 70,
+  fill: 'red',
+  stroke: 'black',
+  strokeWidth: 4
+});
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash array for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart
+ line.dash([10, 5]);
+ // apply dashed stroke that is made up of alternating dashed
+ // lines that are 10px long and 20px apart, and dots that have
+ // a radius of 5px and are 20px apart
+ line.dash([10, 20, 0.001, 20]);
+ + + +
+ + + +
+
+

dashEnabled(enabled)

+ + +
+
+ + +
+

get/set dash enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get dash enabled flag
+var dashEnabled = shape.dashEnabled();
+
+// disable dash
+shape.dashEnabled(false);
+
+// enable dash
+shape.dashEnabled(true);
+ + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

drawHitFromCache(alphaThreshold)

+ + +
+
+ + +
+

draw hit graph using the cached scene canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alphaThreshold + + +Integer + + + + +

alpha channel threshold that determines whether or not
+a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
+The default is 0

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
shape.cache();
+shape.drawHitFromCache();
+ + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

fill(color)

+ + +
+
+ + +
+

get/set fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill color
+var fill = shape.fill();
+
+// set fill color with color string
+shape.fill('green');
+
+// set fill color with hex
+shape.fill('#00ff00');
+
+// set fill color with rgb
+shape.fill('rgb(0,255,0)');
+
+// set fill color with rgba and make it 50% opaque
+shape.fill('rgba(0,255,0,0.5');
+
+// shape without fill
+shape.fill(null);
+ + + +
+ + + +
+
+

fillAfterStrokeEnabled(fillAfterStrokeEnabled)

+ + +
+
+ + +
+

get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
+In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
+Especially useful for Text objects.
+Default is false.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fillAfterStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
+
+// set stroke width
+shape.fillAfterStrokeEnabled(true);
+ + + +
+ + + +
+
+

fillEnabled(enabled)

+ + +
+
+ + +
+

get/set fill enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get fill enabled flag
+var fillEnabled = shape.fillEnabled();
+
+// disable fill
+shape.fillEnabled(false);
+
+// enable fill
+shape.fillEnabled(true);
+ + + +
+ + + +
+
+

fillLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient color stops
+var colorStops = shape.fillLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point
+var endPoint = shape.fillLinearGradientEndPoint();
+
+// set fill linear gradient end point
+shape.fillLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point x
+var endPointX = shape.fillLinearGradientEndPointX();
+
+// set fill linear gradient end point x
+shape.fillLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point y
+var endPointY = shape.fillLinearGradientEndPointY();
+
+// set fill linear gradient end point y
+shape.fillLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point
+var startPoint = shape.fillLinearGradientStartPoint();
+
+// set fill linear gradient start point
+shape.fillLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point x
+var startPointX = shape.fillLinearGradientStartPointX();
+
+// set fill linear gradient start point x
+shape.fillLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point y
+var startPointY = shape.fillLinearGradientStartPointY();
+
+// set fill linear gradient start point y
+shape.fillLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillPatternImage(image)

+ + +
+
+ + +
+

get/set fill pattern image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +

object

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get fill pattern image
+var fillPatternImage = shape.fillPatternImage();
+
+// set fill pattern image
+var imageObj = new Image();
+imageObj.onload = function() {
+  shape.fillPatternImage(imageObj);
+};
+imageObj.src = 'path/to/image/jpg';
+ + + +
+ + + +
+
+

fillPatternOffset(offset)

+ + +
+
+ + +
+

get/set fill pattern offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset
+var patternOffset = shape.fillPatternOffset();
+
+// set fill pattern offset
+shape.fillPatternOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillPatternOffsetX(x)

+ + +
+
+ + +
+

get/set fill pattern offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset x
+var patternOffsetX = shape.fillPatternOffsetX();
+
+// set fill pattern offset x
+shape.fillPatternOffsetX(20);
+ + + +
+ + + +
+
+

fillPatternOffsetY(y)

+ + +
+
+ + +
+

get/set fill pattern offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset y
+var patternOffsetY = shape.fillPatternOffsetY();
+
+// set fill pattern offset y
+shape.fillPatternOffsetY(10);
+ + + +
+ + + +
+
+

fillPatternRepeat(repeat)

+ + +
+
+ + +
+

get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
repeat + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill pattern repeat
+var repeat = shape.fillPatternRepeat();
+
+// repeat pattern in x direction only
+shape.fillPatternRepeat('repeat-x');
+
+// do not repeat the pattern
+shape.fillPatternRepeat('no-repeat');
+ + + +
+ + + +
+
+

fillPatternRotation(rotation)

+ + +
+
+ + +
+

get/set fill pattern rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill pattern rotation
+var patternRotation = shape.fillPatternRotation();
+
+// set fill pattern rotation
+shape.fillPatternRotation(20);
+ + + +
+ + + +
+
+

fillPatternScale(scale)

+ + +
+
+ + +
+

get/set fill pattern scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale
+var patternScale = shape.fillPatternScale();
+
+// set fill pattern scale
+shape.fillPatternScale({
+  x: 2,
+  y: 2
+});
+ + + +
+ + + +
+
+

fillPatternScaleX(x)

+ + +
+
+ + +
+

get/set fill pattern scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale x
+var patternScaleX = shape.fillPatternScaleX();
+
+// set fill pattern scale x
+shape.fillPatternScaleX(2);
+ + + +
+ + + +
+
+

fillPatternScaleY(y)

+ + +
+
+ + +
+

get/set fill pattern scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale y
+var patternScaleY = shape.fillPatternScaleY();
+
+// set fill pattern scale y
+shape.fillPatternScaleY(2);
+ + + +
+ + + +
+
+

fillPatternX(x)

+ + +
+
+ + +
+

get/set fill pattern x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern x
+var fillPatternX = shape.fillPatternX();
+// set fill pattern x
+shape.fillPatternX(20);
+ + + +
+ + + +
+
+

fillPatternY(y)

+ + +
+
+ + +
+

get/set fill pattern y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern y
+var fillPatternY = shape.fillPatternY();
+// set fill pattern y
+shape.fillPatternY(20);
+ + + +
+ + + +
+
+

fillPriority(priority)

+ + +
+
+ + +
+

get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
+This is handy if you want to toggle between different fill types.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
priority + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill priority
+var fillPriority = shape.fillPriority();
+
+// set fill priority
+shape.fillPriority('linear-gradient');
+ + + +
+ + + +
+
+

fillRadialGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill radial gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient color stops
+var colorStops = shape.fillRadialGradientColorStops();
+
+// create a radial gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillRadialGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill radial gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point
+var endPoint = shape.fillRadialGradientEndPoint();
+
+// set fill radial gradient end point
+shape.fillRadialGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point x
+var endPointX = shape.fillRadialGradientEndPointX();
+
+// set fill radial gradient end point x
+shape.fillRadialGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point y
+var endPointY = shape.fillRadialGradientEndPointY();
+
+// set fill radial gradient end point y
+shape.fillRadialGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient end radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient end radius
+var endRadius = shape.fillRadialGradientEndRadius();
+
+// set radial gradient end radius
+shape.fillRadialGradientEndRadius(100);
+ + + +
+ + + +
+
+

fillRadialGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill radial gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point
+var startPoint = shape.fillRadialGradientStartPoint();
+
+// set fill radial gradient start point
+shape.fillRadialGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point x
+var startPointX = shape.fillRadialGradientStartPointX();
+
+// set fill radial gradient start point x
+shape.fillRadialGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point y
+var startPointY = shape.fillRadialGradientStartPointY();
+
+// set fill radial gradient start point y
+shape.fillRadialGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient start radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient start radius
+var startRadius = shape.fillRadialGradientStartRadius();
+
+// set radial gradient start radius
+shape.fillRadialGradientStartRadius(0);
+ + + +
+ + + +
+
+

fillRule(rotation)

+ + +
+
+ + +
+

get/set fill rule

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +CanvasFillRule + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill rule
+var fillRule = shape.fillRule();
+
+// set fill rule
+shape.fillRule('evenodd');
+ + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getSelfRect()

+ + +
+
+ + +
+

return self rectangle (x, y, width, height) of shape.
+This method are not taken into account transformation and styles.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
rect.getSelfRect();  // return {x:0, y:0, width:rect.width(), height:rect.height()}
+circle.getSelfRect();  // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasFill()

+ + +
+
+ + +
+

returns whether or not the shape will be filled

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

hasShadow()

+ + +
+
+ + +
+

returns whether or not a shadow will be rendered

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasStroke()

+ + +
+
+ + +
+

returns whether or not the shape will be stroked

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitFunc(drawFunc)

+ + +
+
+ + +
+

get/set hit draw function. That function is used to draw custom hit area of a shape.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get hit draw function
+var hitFunc = shape.hitFunc();
+
+// set hit draw function
+shape.hitFunc(function(context) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

hitStrokeWidth(hitStrokeWidth)

+ + +
+
+ + +
+

get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var hitStrokeWidth = shape.hitStrokeWidth();
+
+// set hit stroke width
+shape.hitStrokeWidth(20);
+// set hit stroke width always equals to scene stroke width
+shape.hitStrokeWidth('auto');
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

innerRadius(innerRadius)

+ + +
+
+ + +
+

get/set innerRadius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
innerRadius + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get inner radius
+var innerRadius = star.innerRadius();
+
+// set inner radius
+star.innerRadius(20);
+ + + +
+ + + +
+
+

intersects(point)

+ + +
+
+ + +
+

determines if point is in the shape, regardless if other shapes are on top of it. Note: because
+this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
+consecutively. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

linearLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set stroke linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point x
+var startPointX = shape.strokeLinearGradientStartPointX();
+
+// set stroke linear gradient start point x
+shape.strokeLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

lineCap(lineCap)

+ + +
+
+ + +
+

get/set line cap. Can be butt, round, or square

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineCap + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line cap
+var lineCap = shape.lineCap();
+
+// set line cap
+shape.lineCap('round');
+ + + +
+ + + +
+
+

lineJoin(lineJoin)

+ + +
+
+ + +
+

get/set line join. Can be miter, round, or bevel. The
+default is miter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineJoin + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line join
+var lineJoin = shape.lineJoin();
+
+// set line join
+shape.lineJoin('round');
+ + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

numPoints(numPoints)

+ + +
+
+ + +
+

get/set number of points

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
numPoints + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get inner radius
+var numPoints = star.numPoints();
+
+// set inner radius
+star.numPoints(20);
+ + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

outerRadius(outerRadius)

+ + +
+
+ + +
+

get/set outerRadius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
outerRadius + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get inner radius
+var outerRadius = star.outerRadius();
+
+// set inner radius
+star.outerRadius(20);
+ + + +
+ + + +
+
+

perfectDrawEnabled(perfectDrawEnabled)

+ + +
+
+ + +
+

get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set perfectDrawEnabled to false to improve performance.
+See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
perfectDrawEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get perfectDrawEnabled
+var perfectDrawEnabled = shape.perfectDrawEnabled();
+
+// set perfectDrawEnabled
+shape.perfectDrawEnabled();
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

sceneFunc(drawFunc)

+ + +
+
+ + +
+

get/set scene draw function. That function is used to draw the shape on a canvas.
+Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get scene draw function
+var sceneFunc = shape.sceneFunc();
+
+// set scene draw function
+shape.sceneFunc(function(context, shape) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  // like stroke and fill
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

shadowBlur(blur)

+ + +
+
+ + +
+

get/set shadow blur

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blur + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow blur
+var shadowBlur = shape.shadowBlur();
+
+// set shadow blur
+shape.shadowBlur(10);
+ + + +
+ + + +
+
+

shadowColor(color)

+ + +
+
+ + +
+

get/set shadow color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get shadow color
+var shadow = shape.shadowColor();
+
+// set shadow color with color string
+shape.shadowColor('green');
+
+// set shadow color with hex
+shape.shadowColor('#00ff00');
+
+// set shadow color with rgb
+shape.shadowColor('rgb(0,255,0)');
+
+// set shadow color with rgba and make it 50% opaque
+shape.shadowColor('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

shadowEnabled(enabled)

+ + +
+
+ + +
+

get/set shadow enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadow enabled flag
+var shadowEnabled = shape.shadowEnabled();
+
+// disable shadow
+shape.shadowEnabled(false);
+
+// enable shadow
+shape.shadowEnabled(true);
+ + + +
+ + + +
+
+

shadowForStrokeEnabled(shadowForStrokeEnabled)

+ + +
+
+ + +
+

get/set shadowForStrokeEnabled. Useful for performance optimization.
+You may set shape.shadowForStrokeEnabled(false). In this case stroke will no effect shadow.
+Remember if you set shadowForStrokeEnabled = false for non closed line - that line will have no shadow!.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shadowForStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadowForStrokeEnabled
+var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
+
+// set shadowForStrokeEnabled
+shape.shadowForStrokeEnabled();
+ + + +
+ + + +
+
+

shadowOffset(offset)

+ + +
+
+ + +
+

get/set shadow offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get shadow offset
+var shadowOffset = shape.shadowOffset();
+
+// set shadow offset
+shape.shadowOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

shadowOffsetX(x)

+ + +
+
+ + +
+

get/set shadow offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset x
+var shadowOffsetX = shape.shadowOffsetX();
+
+// set shadow offset x
+shape.shadowOffsetX(5);
+ + + +
+ + + +
+
+

shadowOffsetY(y)

+ + +
+
+ + +
+

get/set shadow offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset y
+var shadowOffsetY = shape.shadowOffsetY();
+
+// set shadow offset y
+shape.shadowOffsetY(5);
+ + + +
+ + + +
+
+

shadowOpacity(opacity)

+ + +
+
+ + +
+

get/set shadow opacity. must be a value between 0 and 1

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow opacity
+var shadowOpacity = shape.shadowOpacity();
+
+// set shadow opacity
+shape.shadowOpacity(0.5);
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke(color)

+ + +
+
+ + +
+

get/set stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get stroke color
+var stroke = shape.stroke();
+
+// set stroke color with color string
+shape.stroke('green');
+
+// set stroke color with hex
+shape.stroke('#00ff00');
+
+// set stroke color with rgb
+shape.stroke('rgb(0,255,0)');
+
+// set stroke color with rgba and make it 50% opaque
+shape.stroke('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

strokeEnabled(enabled)

+ + +
+
+ + +
+

get/set stroke enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke enabled flag
+var strokeEnabled = shape.strokeEnabled();
+
+// disable stroke
+shape.strokeEnabled(false);
+
+// enable stroke
+shape.strokeEnabled(true);
+ + + +
+ + + +
+
+

strokeHitEnabled(strokeHitEnabled)

+ + +
+
+ + +
+

deprecated, use hitStrokeWidth instead! get/set strokeHitEnabled property. Useful for performance optimization.
+You may set shape.strokeHitEnabled(false). In this case stroke will be no draw on hit canvas, so hit area
+of shape will be decreased (by lineWidth / 2). Remember that non closed line with strokeHitEnabled = false
+will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
+Default value is true.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeHitEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get strokeHitEnabled
+var strokeHitEnabled = shape.strokeHitEnabled();
+
+// set strokeHitEnabled
+shape.strokeHitEnabled();
+ + + +
+ + + +
+
+

strokeLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set stroke linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient color stops
+var colorStops = shape.strokeLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point
+var endPoint = shape.strokeLinearGradientEndPoint();
+
+// set stroke linear gradient end point
+shape.strokeLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point x
+var endPointX = shape.strokeLinearGradientEndPointX();
+
+// set stroke linear gradient end point x
+shape.strokeLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point y
+var endPointY = shape.strokeLinearGradientEndPointY();
+
+// set stroke linear gradient end point y
+shape.strokeLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

strokeLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point
+var startPoint = shape.strokeLinearGradientStartPoint();
+
+// set stroke linear gradient start point
+shape.strokeLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point y
+var startPointY = shape.strokeLinearGradientStartPointY();
+
+// set stroke linear gradient start point y
+shape.strokeLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

strokeScaleEnabled(enabled)

+ + +
+
+ + +
+

get/set strokeScale enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke scale enabled flag
+var strokeScaleEnabled = shape.strokeScaleEnabled();
+
+// disable stroke scale
+shape.strokeScaleEnabled(false);
+
+// enable stroke scale
+shape.strokeScaleEnabled(true);
+ + + +
+ + + +
+
+

strokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var strokeWidth = shape.strokeWidth();
+
+// set stroke width
+shape.strokeWidth(10);
+ + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Tag.html b/api/Konva.Tag.html new file mode 100644 index 000000000..2f80cdfc6 --- /dev/null +++ b/api/Konva.Tag.html @@ -0,0 +1,1270 @@ + + + + + + + Konva Class: Tag + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Tag

+
+ +
+ +

+ Konva. + + Tag +

+ +

Tag constructor.  A Tag can be configured
+to have a pointer element that points up, right, down, or left

+ + +
+ + +
+
+ + +
+
+

new Tag(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
pointerDirection + + +String + + + + + + + <optional>
+ + + + + +

can be up, right, down, left, or none; the default
+is none. When a pointer is present, the positioning of the label is relative to the tip of the pointer.

pointerWidth + + +Number + + + + + + + <optional>
+ + + + + +
pointerHeight + + +Number + + + + + + + <optional>
+ + + + + +
cornerRadius + + +Number + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + +
+ + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

cornerRadius(cornerRadius)

+ + +
+
+ + +
+

get/set cornerRadius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
cornerRadius + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
tag.cornerRadius(20);
+
+// set different corner radius values
+// top-left, top-right, bottom-right, bottom-left
+tag.cornerRadius([0, 10, 20, 30]);
+ + + +
+ + + +
+
+

pointerDirection(pointerDirection)

+ + +
+
+ + +
+

get/set pointer direction

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pointerDirection + + +String + + + + +

can be up, right, down, left, or none. The default is none.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
tag.pointerDirection('right');
+ + + +
+ + + +
+
+

pointerHeight(pointerHeight)

+ + +
+
+ + +
+

get/set pointer height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pointerHeight + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
tag.pointerHeight(20);
+ + + +
+ + + +
+
+

pointerWidth(pointerWidth)

+ + +
+
+ + +
+

get/set pointer width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pointerWidth + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
tag.pointerWidth(20);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Text.html b/api/Konva.Text.html new file mode 100644 index 000000000..447ace8ad --- /dev/null +++ b/api/Konva.Text.html @@ -0,0 +1,37803 @@ + + + + + + + Konva Class: Text + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Text

+
+ +
+ +

+ Konva~ + + Text +

+ +

Text constructor

+ + +
+ + +
+
+ + +
+
+

new Text(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
direction + + +String + + + + + + + <optional>
+ + + + + +

default is inherit

fontFamily + + +String + + + + + + + <optional>
+ + + + + +

default is Arial

fontSize + + +Number + + + + + + + <optional>
+ + + + + +

in pixels. Default is 12

fontStyle + + +String + + + + + + + <optional>
+ + + + + +

can be 'normal', 'italic', or 'bold', '500' or even 'italic bold'. 'normal' is the default.

fontVariant + + +String + + + + + + + <optional>
+ + + + + +

can be normal or small-caps. Default is normal

textDecoration + + +String + + + + + + + <optional>
+ + + + + +

can be line-through, underline or empty string. Default is empty string.

text + + +String + + + + + + + + + + +
align + + +String + + + + + + + <optional>
+ + + + + +

can be left, center, or right

verticalAlign + + +String + + + + + + + <optional>
+ + + + + +

can be top, middle or bottom

padding + + +Number + + + + + + + <optional>
+ + + + + +
lineHeight + + +Number + + + + + + + <optional>
+ + + + + +

default is 1

wrap + + +String + + + + + + + <optional>
+ + + + + +

can be "word", "char", or "none". Default is word

ellipsis + + +Boolean + + + + + + + <optional>
+ + + + + +

can be true or false. Default is false. if Konva.Text config is set to wrap="none" and ellipsis=true, then it will add "..." to the end

fill + + +String + + + + + + + <optional>
+ + + + + +

fill color

fillPatternImage + + +Image + + + + + + + <optional>
+ + + + + +

fill pattern image

fillPatternX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScale + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternScaleX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScaleY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRotation + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRepeat + + +String + + + + + + + <optional>
+ + + + + +

can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"

fillLinearGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillRadialGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the fill. The default value is true

fillPriority + + +String + + + + + + + <optional>
+ + + + + +

can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration

stroke + + +String + + + + + + + <optional>
+ + + + + +

stroke color

strokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

stroke width

fillAfterStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw fill AFTER stroke? Default is false.

hitStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth

strokeHitEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke hit region. The default is true

perfectDrawEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables using buffer canvas. The default is true

shadowForStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables shadow for stroke. The default is true

strokeScaleEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke scale. The default is true

strokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the stroke. The default value is true

lineJoin + + +String + + + + + + + <optional>
+ + + + + +

can be miter, round, or bevel. The default
+is miter

lineCap + + +String + + + + + + + <optional>
+ + + + + +

can be butt, round, or square. The default
+is butt

shadowColor + + +String + + + + + + + <optional>
+ + + + + +
shadowBlur + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

shadowOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
shadowOpacity + + +Number + + + + + + + <optional>
+ + + + + +

shadow opacity. Can be any real number
+between 0 and 1

shadowEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the shadow. The default value is true

dash + + +Array + + + + + + + <optional>
+ + + + + +
dashEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the dashArray. The default value is true

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var text = new Konva.Text({
+  x: 10,
+  y: 15,
+  text: 'Simple Text',
+  fontSize: 30,
+  fontFamily: 'Calibri',
+  fill: 'green'
+});
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

_shouldHandleEllipsis(currentHeightPx)

+ + +
+
+ + +
+

whether to handle ellipsis, there are two cases:

+
    +
  1. the current line is the last line
  2. +
  3. wrap is NONE
  4. +
+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
currentHeightPx + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + + + + + +
+ + + +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

align(align)

+ + +
+
+ + +
+

get/set horizontal align of text. Can be 'left', 'center', 'right' or 'justify'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
align + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get text align
+var align = text.align();
+
+// center text
+text.align('center');
+
+// align text to right
+text.align('right');
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash array for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart
+ line.dash([10, 5]);
+ // apply dashed stroke that is made up of alternating dashed
+ // lines that are 10px long and 20px apart, and dots that have
+ // a radius of 5px and are 20px apart
+ line.dash([10, 20, 0.001, 20]);
+ + + +
+ + + +
+
+

dashEnabled(enabled)

+ + +
+
+ + +
+

get/set dash enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get dash enabled flag
+var dashEnabled = shape.dashEnabled();
+
+// disable dash
+shape.dashEnabled(false);
+
+// enable dash
+shape.dashEnabled(true);
+ + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

direction(direction)

+ + +
+
+ + +
+

get/set direction

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
direction + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get direction
+var direction = text.direction();
+
+// set direction
+text.direction('rtl');
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

drawHitFromCache(alphaThreshold)

+ + +
+
+ + +
+

draw hit graph using the cached scene canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alphaThreshold + + +Integer + + + + +

alpha channel threshold that determines whether or not
+a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
+The default is 0

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
shape.cache();
+shape.drawHitFromCache();
+ + + +
+ + + +
+
+

ellipsis(ellipsis)

+ + +
+
+ + +
+

get/set ellipsis. Can be true or false. Default is false. If ellipses is true,
+Konva will add "..." at the end of the text if it doesn't have enough space to write characters.
+That is possible only when you limit both width and height of the text

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ellipsis + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get ellipsis param, returns true or false
+var ellipsis = text.ellipsis();
+
+// set ellipsis
+text.ellipsis(true);
+ + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

fill(color)

+ + +
+
+ + +
+

get/set fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill color
+var fill = shape.fill();
+
+// set fill color with color string
+shape.fill('green');
+
+// set fill color with hex
+shape.fill('#00ff00');
+
+// set fill color with rgb
+shape.fill('rgb(0,255,0)');
+
+// set fill color with rgba and make it 50% opaque
+shape.fill('rgba(0,255,0,0.5');
+
+// shape without fill
+shape.fill(null);
+ + + +
+ + + +
+
+

fillAfterStrokeEnabled(fillAfterStrokeEnabled)

+ + +
+
+ + +
+

get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
+In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
+Especially useful for Text objects.
+Default is false.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fillAfterStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
+
+// set stroke width
+shape.fillAfterStrokeEnabled(true);
+ + + +
+ + + +
+
+

fillEnabled(enabled)

+ + +
+
+ + +
+

get/set fill enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get fill enabled flag
+var fillEnabled = shape.fillEnabled();
+
+// disable fill
+shape.fillEnabled(false);
+
+// enable fill
+shape.fillEnabled(true);
+ + + +
+ + + +
+
+

fillLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient color stops
+var colorStops = shape.fillLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point
+var endPoint = shape.fillLinearGradientEndPoint();
+
+// set fill linear gradient end point
+shape.fillLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point x
+var endPointX = shape.fillLinearGradientEndPointX();
+
+// set fill linear gradient end point x
+shape.fillLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point y
+var endPointY = shape.fillLinearGradientEndPointY();
+
+// set fill linear gradient end point y
+shape.fillLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point
+var startPoint = shape.fillLinearGradientStartPoint();
+
+// set fill linear gradient start point
+shape.fillLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point x
+var startPointX = shape.fillLinearGradientStartPointX();
+
+// set fill linear gradient start point x
+shape.fillLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point y
+var startPointY = shape.fillLinearGradientStartPointY();
+
+// set fill linear gradient start point y
+shape.fillLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillPatternImage(image)

+ + +
+
+ + +
+

get/set fill pattern image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +

object

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get fill pattern image
+var fillPatternImage = shape.fillPatternImage();
+
+// set fill pattern image
+var imageObj = new Image();
+imageObj.onload = function() {
+  shape.fillPatternImage(imageObj);
+};
+imageObj.src = 'path/to/image/jpg';
+ + + +
+ + + +
+
+

fillPatternOffset(offset)

+ + +
+
+ + +
+

get/set fill pattern offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset
+var patternOffset = shape.fillPatternOffset();
+
+// set fill pattern offset
+shape.fillPatternOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillPatternOffsetX(x)

+ + +
+
+ + +
+

get/set fill pattern offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset x
+var patternOffsetX = shape.fillPatternOffsetX();
+
+// set fill pattern offset x
+shape.fillPatternOffsetX(20);
+ + + +
+ + + +
+
+

fillPatternOffsetY(y)

+ + +
+
+ + +
+

get/set fill pattern offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset y
+var patternOffsetY = shape.fillPatternOffsetY();
+
+// set fill pattern offset y
+shape.fillPatternOffsetY(10);
+ + + +
+ + + +
+
+

fillPatternRepeat(repeat)

+ + +
+
+ + +
+

get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
repeat + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill pattern repeat
+var repeat = shape.fillPatternRepeat();
+
+// repeat pattern in x direction only
+shape.fillPatternRepeat('repeat-x');
+
+// do not repeat the pattern
+shape.fillPatternRepeat('no-repeat');
+ + + +
+ + + +
+
+

fillPatternRotation(rotation)

+ + +
+
+ + +
+

get/set fill pattern rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill pattern rotation
+var patternRotation = shape.fillPatternRotation();
+
+// set fill pattern rotation
+shape.fillPatternRotation(20);
+ + + +
+ + + +
+
+

fillPatternScale(scale)

+ + +
+
+ + +
+

get/set fill pattern scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale
+var patternScale = shape.fillPatternScale();
+
+// set fill pattern scale
+shape.fillPatternScale({
+  x: 2,
+  y: 2
+});
+ + + +
+ + + +
+
+

fillPatternScaleX(x)

+ + +
+
+ + +
+

get/set fill pattern scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale x
+var patternScaleX = shape.fillPatternScaleX();
+
+// set fill pattern scale x
+shape.fillPatternScaleX(2);
+ + + +
+ + + +
+
+

fillPatternScaleY(y)

+ + +
+
+ + +
+

get/set fill pattern scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale y
+var patternScaleY = shape.fillPatternScaleY();
+
+// set fill pattern scale y
+shape.fillPatternScaleY(2);
+ + + +
+ + + +
+
+

fillPatternX(x)

+ + +
+
+ + +
+

get/set fill pattern x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern x
+var fillPatternX = shape.fillPatternX();
+// set fill pattern x
+shape.fillPatternX(20);
+ + + +
+ + + +
+
+

fillPatternY(y)

+ + +
+
+ + +
+

get/set fill pattern y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern y
+var fillPatternY = shape.fillPatternY();
+// set fill pattern y
+shape.fillPatternY(20);
+ + + +
+ + + +
+
+

fillPriority(priority)

+ + +
+
+ + +
+

get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
+This is handy if you want to toggle between different fill types.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
priority + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill priority
+var fillPriority = shape.fillPriority();
+
+// set fill priority
+shape.fillPriority('linear-gradient');
+ + + +
+ + + +
+
+

fillRadialGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill radial gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient color stops
+var colorStops = shape.fillRadialGradientColorStops();
+
+// create a radial gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillRadialGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill radial gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point
+var endPoint = shape.fillRadialGradientEndPoint();
+
+// set fill radial gradient end point
+shape.fillRadialGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point x
+var endPointX = shape.fillRadialGradientEndPointX();
+
+// set fill radial gradient end point x
+shape.fillRadialGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point y
+var endPointY = shape.fillRadialGradientEndPointY();
+
+// set fill radial gradient end point y
+shape.fillRadialGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient end radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient end radius
+var endRadius = shape.fillRadialGradientEndRadius();
+
+// set radial gradient end radius
+shape.fillRadialGradientEndRadius(100);
+ + + +
+ + + +
+
+

fillRadialGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill radial gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point
+var startPoint = shape.fillRadialGradientStartPoint();
+
+// set fill radial gradient start point
+shape.fillRadialGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point x
+var startPointX = shape.fillRadialGradientStartPointX();
+
+// set fill radial gradient start point x
+shape.fillRadialGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point y
+var startPointY = shape.fillRadialGradientStartPointY();
+
+// set fill radial gradient start point y
+shape.fillRadialGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient start radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient start radius
+var startRadius = shape.fillRadialGradientStartRadius();
+
+// set radial gradient start radius
+shape.fillRadialGradientStartRadius(0);
+ + + +
+ + + +
+
+

fillRule(rotation)

+ + +
+
+ + +
+

get/set fill rule

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +CanvasFillRule + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill rule
+var fillRule = shape.fillRule();
+
+// set fill rule
+shape.fillRule('evenodd');
+ + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

fontFamily(fontFamily)

+ + +
+
+ + +
+

get/set font family

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fontFamily + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get font family
+var fontFamily = text.fontFamily();
+
+// set font family
+text.fontFamily('Arial');
+ + + +
+ + + +
+
+

fontSize(fontSize)

+ + +
+
+ + +
+

get/set font size in pixels

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fontSize + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get font size
+var fontSize = text.fontSize();
+
+// set font size to 22px
+text.fontSize(22);
+ + + +
+ + + +
+
+

fontStyle(fontStyle)

+ + +
+
+ + +
+

get/set font style. Can be 'normal', 'italic', or 'bold', '500' or even 'italic bold'. 'normal' is the default.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fontStyle + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get font style
+var fontStyle = text.fontStyle();
+
+// set font style
+text.fontStyle('bold');
+ + + +
+ + + +
+
+

fontVariant(fontVariant)

+ + +
+
+ + +
+

get/set font variant. Can be 'normal' or 'small-caps'. 'normal' is the default.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fontVariant + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get font variant
+var fontVariant = text.fontVariant();
+
+// set font variant
+text.fontVariant('small-caps');
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getSelfRect()

+ + +
+
+ + +
+

return self rectangle (x, y, width, height) of shape.
+This method are not taken into account transformation and styles.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
rect.getSelfRect();  // return {x:0, y:0, width:rect.width(), height:rect.height()}
+circle.getSelfRect();  // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTextWidth()

+ + +
+
+ + +
+

get pure text width without padding

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasFill()

+ + +
+
+ + +
+

returns whether or not the shape will be filled

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

hasShadow()

+ + +
+
+ + +
+

returns whether or not a shadow will be rendered

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasStroke()

+ + +
+
+ + +
+

returns whether or not the shape will be stroked

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set the height of the text area, which takes into account multi-line text, line heights, and padding.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = text.height();
+
+// set height
+text.height(20);
+
+// set to auto
+text.height('auto');
+text.height() // will return calculated height, and not "auto"
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitFunc(drawFunc)

+ + +
+
+ + +
+

get/set hit draw function. That function is used to draw custom hit area of a shape.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get hit draw function
+var hitFunc = shape.hitFunc();
+
+// set hit draw function
+shape.hitFunc(function(context) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

hitStrokeWidth(hitStrokeWidth)

+ + +
+
+ + +
+

get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var hitStrokeWidth = shape.hitStrokeWidth();
+
+// set hit stroke width
+shape.hitStrokeWidth(20);
+// set hit stroke width always equals to scene stroke width
+shape.hitStrokeWidth('auto');
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

intersects(point)

+ + +
+
+ + +
+

determines if point is in the shape, regardless if other shapes are on top of it. Note: because
+this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
+consecutively. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

letterSpacing(letterSpacing)

+ + +
+
+ + +
+

set letter spacing property. Default value is 0.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
letterSpacing + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

linearLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set stroke linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point x
+var startPointX = shape.strokeLinearGradientStartPointX();
+
+// set stroke linear gradient start point x
+shape.strokeLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

lineCap(lineCap)

+ + +
+
+ + +
+

get/set line cap. Can be butt, round, or square

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineCap + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line cap
+var lineCap = shape.lineCap();
+
+// set line cap
+shape.lineCap('round');
+ + + +
+ + + +
+
+

lineHeight(lineHeight)

+ + +
+
+ + +
+

get/set line height. The default is 1.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineHeight + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get line height
+var lineHeight = text.lineHeight();
+
+// set the line height
+text.lineHeight(2);
+ + + +
+ + + +
+
+

lineJoin(lineJoin)

+ + +
+
+ + +
+

get/set line join. Can be miter, round, or bevel. The
+default is miter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineJoin + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line join
+var lineJoin = shape.lineJoin();
+
+// set line join
+shape.lineJoin('round');
+ + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

measureSize(text)

+ + +
+
+ + +
+

measure string with the font of current text shape.
+That method can't handle multiline text.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
text + + +String + + + + +

text to measure

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

{ width , height } of measured text

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

padding(padding)

+ + +
+
+ + +
+

get/set padding

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
padding + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get padding
+var padding = text.padding();
+
+// set padding to 10 pixels
+text.padding(10);
+ + + +
+ + + +
+
+

perfectDrawEnabled(perfectDrawEnabled)

+ + +
+
+ + +
+

get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set perfectDrawEnabled to false to improve performance.
+See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
perfectDrawEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get perfectDrawEnabled
+var perfectDrawEnabled = shape.perfectDrawEnabled();
+
+// set perfectDrawEnabled
+shape.perfectDrawEnabled();
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

sceneFunc(drawFunc)

+ + +
+
+ + +
+

get/set scene draw function. That function is used to draw the shape on a canvas.
+Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get scene draw function
+var sceneFunc = shape.sceneFunc();
+
+// set scene draw function
+shape.sceneFunc(function(context, shape) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  // like stroke and fill
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

shadowBlur(blur)

+ + +
+
+ + +
+

get/set shadow blur

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blur + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow blur
+var shadowBlur = shape.shadowBlur();
+
+// set shadow blur
+shape.shadowBlur(10);
+ + + +
+ + + +
+
+

shadowColor(color)

+ + +
+
+ + +
+

get/set shadow color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get shadow color
+var shadow = shape.shadowColor();
+
+// set shadow color with color string
+shape.shadowColor('green');
+
+// set shadow color with hex
+shape.shadowColor('#00ff00');
+
+// set shadow color with rgb
+shape.shadowColor('rgb(0,255,0)');
+
+// set shadow color with rgba and make it 50% opaque
+shape.shadowColor('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

shadowEnabled(enabled)

+ + +
+
+ + +
+

get/set shadow enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadow enabled flag
+var shadowEnabled = shape.shadowEnabled();
+
+// disable shadow
+shape.shadowEnabled(false);
+
+// enable shadow
+shape.shadowEnabled(true);
+ + + +
+ + + +
+
+

shadowForStrokeEnabled(shadowForStrokeEnabled)

+ + +
+
+ + +
+

get/set shadowForStrokeEnabled. Useful for performance optimization.
+You may set shape.shadowForStrokeEnabled(false). In this case stroke will no effect shadow.
+Remember if you set shadowForStrokeEnabled = false for non closed line - that line will have no shadow!.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shadowForStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadowForStrokeEnabled
+var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
+
+// set shadowForStrokeEnabled
+shape.shadowForStrokeEnabled();
+ + + +
+ + + +
+
+

shadowOffset(offset)

+ + +
+
+ + +
+

get/set shadow offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get shadow offset
+var shadowOffset = shape.shadowOffset();
+
+// set shadow offset
+shape.shadowOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

shadowOffsetX(x)

+ + +
+
+ + +
+

get/set shadow offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset x
+var shadowOffsetX = shape.shadowOffsetX();
+
+// set shadow offset x
+shape.shadowOffsetX(5);
+ + + +
+ + + +
+
+

shadowOffsetY(y)

+ + +
+
+ + +
+

get/set shadow offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset y
+var shadowOffsetY = shape.shadowOffsetY();
+
+// set shadow offset y
+shape.shadowOffsetY(5);
+ + + +
+ + + +
+
+

shadowOpacity(opacity)

+ + +
+
+ + +
+

get/set shadow opacity. must be a value between 0 and 1

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow opacity
+var shadowOpacity = shape.shadowOpacity();
+
+// set shadow opacity
+shape.shadowOpacity(0.5);
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke(color)

+ + +
+
+ + +
+

get/set stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get stroke color
+var stroke = shape.stroke();
+
+// set stroke color with color string
+shape.stroke('green');
+
+// set stroke color with hex
+shape.stroke('#00ff00');
+
+// set stroke color with rgb
+shape.stroke('rgb(0,255,0)');
+
+// set stroke color with rgba and make it 50% opaque
+shape.stroke('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

strokeEnabled(enabled)

+ + +
+
+ + +
+

get/set stroke enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke enabled flag
+var strokeEnabled = shape.strokeEnabled();
+
+// disable stroke
+shape.strokeEnabled(false);
+
+// enable stroke
+shape.strokeEnabled(true);
+ + + +
+ + + +
+
+

strokeHitEnabled(strokeHitEnabled)

+ + +
+
+ + +
+

deprecated, use hitStrokeWidth instead! get/set strokeHitEnabled property. Useful for performance optimization.
+You may set shape.strokeHitEnabled(false). In this case stroke will be no draw on hit canvas, so hit area
+of shape will be decreased (by lineWidth / 2). Remember that non closed line with strokeHitEnabled = false
+will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
+Default value is true.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeHitEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get strokeHitEnabled
+var strokeHitEnabled = shape.strokeHitEnabled();
+
+// set strokeHitEnabled
+shape.strokeHitEnabled();
+ + + +
+ + + +
+
+

strokeLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set stroke linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient color stops
+var colorStops = shape.strokeLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point
+var endPoint = shape.strokeLinearGradientEndPoint();
+
+// set stroke linear gradient end point
+shape.strokeLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point x
+var endPointX = shape.strokeLinearGradientEndPointX();
+
+// set stroke linear gradient end point x
+shape.strokeLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point y
+var endPointY = shape.strokeLinearGradientEndPointY();
+
+// set stroke linear gradient end point y
+shape.strokeLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

strokeLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point
+var startPoint = shape.strokeLinearGradientStartPoint();
+
+// set stroke linear gradient start point
+shape.strokeLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point y
+var startPointY = shape.strokeLinearGradientStartPointY();
+
+// set stroke linear gradient start point y
+shape.strokeLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

strokeScaleEnabled(enabled)

+ + +
+
+ + +
+

get/set strokeScale enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke scale enabled flag
+var strokeScaleEnabled = shape.strokeScaleEnabled();
+
+// disable stroke scale
+shape.strokeScaleEnabled(false);
+
+// enable stroke scale
+shape.strokeScaleEnabled(true);
+ + + +
+ + + +
+
+

strokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var strokeWidth = shape.strokeWidth();
+
+// set stroke width
+shape.strokeWidth(10);
+ + + +
+ + + +
+
+

text(text)

+ + +
+
+ + +
+

get/set text

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
text + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get text
+var text = text.text();
+
+// set text
+text.text('Hello world!');
+ + + +
+ + + +
+
+

textDecoration(textDecoration)

+ + +
+
+ + +
+

get/set text decoration of a text. Possible values are 'underline', 'line-through' or combination of these values separated by space

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
textDecoration + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get text decoration
+var textDecoration = text.textDecoration();
+
+// underline text
+text.textDecoration('underline');
+
+// strike text
+text.textDecoration('line-through');
+
+// underline and strike text
+text.textDecoration('underline line-through');
+ + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

verticalAlign(verticalAlign)

+ + +
+
+ + +
+

get/set vertical align of text. Can be 'top', 'middle', 'bottom'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
verticalAlign + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get text vertical align
+var verticalAlign = text.verticalAlign();
+
+// center text
+text.verticalAlign('middle');
+ + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width of text area, which includes padding.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = text.width();
+
+// set width
+text.width(20);
+
+// set to auto
+text.width('auto');
+text.width() // will return calculated width, and not "auto"
+ + + +
+ + + +
+
+

wrap(wrap)

+ + +
+
+ + +
+

get/set wrap. Can be "word", "char", or "none". Default is "word".
+In "word" wrapping any word still can be wrapped if it can't be placed in the required width
+without breaks.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
wrap + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get wrap
+var wrap = text.wrap();
+
+// set wrap
+text.wrap('word');
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.TextPath.html b/api/Konva.TextPath.html new file mode 100644 index 000000000..756b280d8 --- /dev/null +++ b/api/Konva.TextPath.html @@ -0,0 +1,36877 @@ + + + + + + + Konva Class: TextPath + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: TextPath

+
+ +
+ +

+ Konva~ + + TextPath +

+ +

Path constructor.

+ + +
+ + +
+
+ + +
+
+

new TextPath(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
fontFamily + + +String + + + + + + + <optional>
+ + + + + +

default is Arial

fontSize + + +Number + + + + + + + <optional>
+ + + + + +

default is 12

fontStyle + + +String + + + + + + + <optional>
+ + + + + +

Can be 'normal', 'italic', or 'bold', '500' or even 'italic bold'. 'normal' is the default.

fontVariant + + +String + + + + + + + <optional>
+ + + + + +

can be normal or small-caps. Default is normal

textBaseline + + +String + + + + + + + <optional>
+ + + + + +

Can be 'top', 'bottom', 'middle', 'alphabetic', 'hanging'. Default is middle

text + + +String + + + + + + + + + + +
data + + +String + + + + + + + + + + +

SVG data string

kerningFunc + + +function + + + + + + + + + + +

a getter for kerning values for the specified characters

fill + + +String + + + + + + + <optional>
+ + + + + +

fill color

fillPatternImage + + +Image + + + + + + + <optional>
+ + + + + +

fill pattern image

fillPatternX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScale + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternScaleX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScaleY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRotation + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRepeat + + +String + + + + + + + <optional>
+ + + + + +

can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"

fillLinearGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillRadialGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the fill. The default value is true

fillPriority + + +String + + + + + + + <optional>
+ + + + + +

can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration

stroke + + +String + + + + + + + <optional>
+ + + + + +

stroke color

strokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

stroke width

fillAfterStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw fill AFTER stroke? Default is false.

hitStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth

strokeHitEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke hit region. The default is true

perfectDrawEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables using buffer canvas. The default is true

shadowForStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables shadow for stroke. The default is true

strokeScaleEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke scale. The default is true

strokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the stroke. The default value is true

lineJoin + + +String + + + + + + + <optional>
+ + + + + +

can be miter, round, or bevel. The default
+is miter

lineCap + + +String + + + + + + + <optional>
+ + + + + +

can be butt, round, or square. The default
+is butt

shadowColor + + +String + + + + + + + <optional>
+ + + + + +
shadowBlur + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

shadowOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
shadowOpacity + + +Number + + + + + + + <optional>
+ + + + + +

shadow opacity. Can be any real number
+between 0 and 1

shadowEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the shadow. The default value is true

dash + + +Array + + + + + + + <optional>
+ + + + + +
dashEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the dashArray. The default value is true

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + +
Author:
+
+
    +
  • Jason Follas
  • +
+
+ + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var kerningPairs = {
+  'A': {
+    ' ': -0.05517578125,
+    'T': -0.07421875,
+    'V': -0.07421875
+  }
+  'V': {
+    ',': -0.091796875,
+    ":": -0.037109375,
+    ";": -0.037109375,
+    "A": -0.07421875
+  }
+}
+var textpath = new Konva.TextPath({
+  x: 100,
+  y: 50,
+  fill: '#333',
+  fontSize: '24',
+  fontFamily: 'Arial',
+  text: 'All the world\'s a stage, and all the men and women merely players.',
+  data: 'M10,10 C0,0 10,150 100,100 S300,150 400,50',
+  kerningFunc(leftChar, rightChar) {
+    return kerningPairs.hasOwnProperty(leftChar) ? pairs[leftChar][rightChar] || 0 : 0
+  }
+});
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

align(align)

+ + +
+
+ + +
+

get/set horizontal align of text. Can be 'left', 'center', 'right' or 'justify'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
align + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get text align
+var align = text.align();
+
+// center text
+text.align('center');
+
+// align text to right
+text.align('right');
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash array for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart
+ line.dash([10, 5]);
+ // apply dashed stroke that is made up of alternating dashed
+ // lines that are 10px long and 20px apart, and dots that have
+ // a radius of 5px and are 20px apart
+ line.dash([10, 20, 0.001, 20]);
+ + + +
+ + + +
+
+

dashEnabled(enabled)

+ + +
+
+ + +
+

get/set dash enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get dash enabled flag
+var dashEnabled = shape.dashEnabled();
+
+// disable dash
+shape.dashEnabled(false);
+
+// enable dash
+shape.dashEnabled(true);
+ + + +
+ + + +
+
+

data(data)

+ + +
+
+ + +
+

get/set SVG path data string. This method
+also automatically parses the data string
+into a data array. Currently supported SVG data:
+M, m, L, l, H, h, V, v, Q, q, T, t, C, c, S, s, A, a, Z, z

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
data + + +String + + + + +

svg path string

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get data
+var data = shape.data();
+
+// set data
+shape.data('M200,100h100v50z');
+ + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

drawHitFromCache(alphaThreshold)

+ + +
+
+ + +
+

draw hit graph using the cached scene canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alphaThreshold + + +Integer + + + + +

alpha channel threshold that determines whether or not
+a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
+The default is 0

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
shape.cache();
+shape.drawHitFromCache();
+ + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

fill(color)

+ + +
+
+ + +
+

get/set fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill color
+var fill = shape.fill();
+
+// set fill color with color string
+shape.fill('green');
+
+// set fill color with hex
+shape.fill('#00ff00');
+
+// set fill color with rgb
+shape.fill('rgb(0,255,0)');
+
+// set fill color with rgba and make it 50% opaque
+shape.fill('rgba(0,255,0,0.5');
+
+// shape without fill
+shape.fill(null);
+ + + +
+ + + +
+
+

fillAfterStrokeEnabled(fillAfterStrokeEnabled)

+ + +
+
+ + +
+

get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
+In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
+Especially useful for Text objects.
+Default is false.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fillAfterStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
+
+// set stroke width
+shape.fillAfterStrokeEnabled(true);
+ + + +
+ + + +
+
+

fillEnabled(enabled)

+ + +
+
+ + +
+

get/set fill enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get fill enabled flag
+var fillEnabled = shape.fillEnabled();
+
+// disable fill
+shape.fillEnabled(false);
+
+// enable fill
+shape.fillEnabled(true);
+ + + +
+ + + +
+
+

fillLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient color stops
+var colorStops = shape.fillLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point
+var endPoint = shape.fillLinearGradientEndPoint();
+
+// set fill linear gradient end point
+shape.fillLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point x
+var endPointX = shape.fillLinearGradientEndPointX();
+
+// set fill linear gradient end point x
+shape.fillLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point y
+var endPointY = shape.fillLinearGradientEndPointY();
+
+// set fill linear gradient end point y
+shape.fillLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point
+var startPoint = shape.fillLinearGradientStartPoint();
+
+// set fill linear gradient start point
+shape.fillLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point x
+var startPointX = shape.fillLinearGradientStartPointX();
+
+// set fill linear gradient start point x
+shape.fillLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point y
+var startPointY = shape.fillLinearGradientStartPointY();
+
+// set fill linear gradient start point y
+shape.fillLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillPatternImage(image)

+ + +
+
+ + +
+

get/set fill pattern image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +

object

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get fill pattern image
+var fillPatternImage = shape.fillPatternImage();
+
+// set fill pattern image
+var imageObj = new Image();
+imageObj.onload = function() {
+  shape.fillPatternImage(imageObj);
+};
+imageObj.src = 'path/to/image/jpg';
+ + + +
+ + + +
+
+

fillPatternOffset(offset)

+ + +
+
+ + +
+

get/set fill pattern offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset
+var patternOffset = shape.fillPatternOffset();
+
+// set fill pattern offset
+shape.fillPatternOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillPatternOffsetX(x)

+ + +
+
+ + +
+

get/set fill pattern offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset x
+var patternOffsetX = shape.fillPatternOffsetX();
+
+// set fill pattern offset x
+shape.fillPatternOffsetX(20);
+ + + +
+ + + +
+
+

fillPatternOffsetY(y)

+ + +
+
+ + +
+

get/set fill pattern offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset y
+var patternOffsetY = shape.fillPatternOffsetY();
+
+// set fill pattern offset y
+shape.fillPatternOffsetY(10);
+ + + +
+ + + +
+
+

fillPatternRepeat(repeat)

+ + +
+
+ + +
+

get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
repeat + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill pattern repeat
+var repeat = shape.fillPatternRepeat();
+
+// repeat pattern in x direction only
+shape.fillPatternRepeat('repeat-x');
+
+// do not repeat the pattern
+shape.fillPatternRepeat('no-repeat');
+ + + +
+ + + +
+
+

fillPatternRotation(rotation)

+ + +
+
+ + +
+

get/set fill pattern rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill pattern rotation
+var patternRotation = shape.fillPatternRotation();
+
+// set fill pattern rotation
+shape.fillPatternRotation(20);
+ + + +
+ + + +
+
+

fillPatternScale(scale)

+ + +
+
+ + +
+

get/set fill pattern scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale
+var patternScale = shape.fillPatternScale();
+
+// set fill pattern scale
+shape.fillPatternScale({
+  x: 2,
+  y: 2
+});
+ + + +
+ + + +
+
+

fillPatternScaleX(x)

+ + +
+
+ + +
+

get/set fill pattern scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale x
+var patternScaleX = shape.fillPatternScaleX();
+
+// set fill pattern scale x
+shape.fillPatternScaleX(2);
+ + + +
+ + + +
+
+

fillPatternScaleY(y)

+ + +
+
+ + +
+

get/set fill pattern scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale y
+var patternScaleY = shape.fillPatternScaleY();
+
+// set fill pattern scale y
+shape.fillPatternScaleY(2);
+ + + +
+ + + +
+
+

fillPatternX(x)

+ + +
+
+ + +
+

get/set fill pattern x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern x
+var fillPatternX = shape.fillPatternX();
+// set fill pattern x
+shape.fillPatternX(20);
+ + + +
+ + + +
+
+

fillPatternY(y)

+ + +
+
+ + +
+

get/set fill pattern y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern y
+var fillPatternY = shape.fillPatternY();
+// set fill pattern y
+shape.fillPatternY(20);
+ + + +
+ + + +
+
+

fillPriority(priority)

+ + +
+
+ + +
+

get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
+This is handy if you want to toggle between different fill types.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
priority + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill priority
+var fillPriority = shape.fillPriority();
+
+// set fill priority
+shape.fillPriority('linear-gradient');
+ + + +
+ + + +
+
+

fillRadialGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill radial gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient color stops
+var colorStops = shape.fillRadialGradientColorStops();
+
+// create a radial gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillRadialGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill radial gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point
+var endPoint = shape.fillRadialGradientEndPoint();
+
+// set fill radial gradient end point
+shape.fillRadialGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point x
+var endPointX = shape.fillRadialGradientEndPointX();
+
+// set fill radial gradient end point x
+shape.fillRadialGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point y
+var endPointY = shape.fillRadialGradientEndPointY();
+
+// set fill radial gradient end point y
+shape.fillRadialGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient end radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient end radius
+var endRadius = shape.fillRadialGradientEndRadius();
+
+// set radial gradient end radius
+shape.fillRadialGradientEndRadius(100);
+ + + +
+ + + +
+
+

fillRadialGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill radial gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point
+var startPoint = shape.fillRadialGradientStartPoint();
+
+// set fill radial gradient start point
+shape.fillRadialGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point x
+var startPointX = shape.fillRadialGradientStartPointX();
+
+// set fill radial gradient start point x
+shape.fillRadialGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point y
+var startPointY = shape.fillRadialGradientStartPointY();
+
+// set fill radial gradient start point y
+shape.fillRadialGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient start radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient start radius
+var startRadius = shape.fillRadialGradientStartRadius();
+
+// set radial gradient start radius
+shape.fillRadialGradientStartRadius(0);
+ + + +
+ + + +
+
+

fillRule(rotation)

+ + +
+
+ + +
+

get/set fill rule

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +CanvasFillRule + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill rule
+var fillRule = shape.fillRule();
+
+// set fill rule
+shape.fillRule('evenodd');
+ + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

fontFamily(fontFamily)

+ + +
+
+ + +
+

get/set font family

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fontFamily + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get font family
+var fontFamily = shape.fontFamily();
+
+// set font family
+shape.fontFamily('Arial');
+ + + +
+ + + +
+
+

fontSize(fontSize)

+ + +
+
+ + +
+

get/set font size in pixels

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fontSize + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get font size
+var fontSize = shape.fontSize();
+
+// set font size to 22px
+shape.fontSize(22);
+ + + +
+ + + +
+
+

fontStyle(fontStyle)

+ + +
+
+ + +
+

get/set font style. Can be 'normal', 'italic', or 'bold', '500' or even 'italic bold'. 'normal' is the default.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fontStyle + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get font style
+var fontStyle = shape.fontStyle();
+
+// set font style
+shape.fontStyle('bold');
+ + + +
+ + + +
+
+

fontVariant(fontVariant)

+ + +
+
+ + +
+

get/set font variant. Can be 'normal' or 'small-caps'. 'normal' is the default.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fontVariant + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get font variant
+var fontVariant = shape.fontVariant();
+
+// set font variant
+shape.fontVariant('small-caps');
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getSelfRect()

+ + +
+
+ + +
+

return self rectangle (x, y, width, height) of shape.
+This method are not taken into account transformation and styles.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
rect.getSelfRect();  // return {x:0, y:0, width:rect.width(), height:rect.height()}
+circle.getSelfRect();  // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getText(text)

+ + +
+
+ + +
+

get/set text

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
text + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get text
+var text = text.text();
+
+// set text
+text.text('Hello world!');
+ + + +
+ + + +
+
+

getTextWidth()

+ + +
+
+ + +
+

get text width in pixels

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasFill()

+ + +
+
+ + +
+

returns whether or not the shape will be filled

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

hasShadow()

+ + +
+
+ + +
+

returns whether or not a shadow will be rendered

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasStroke()

+ + +
+
+ + +
+

returns whether or not the shape will be stroked

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitFunc(drawFunc)

+ + +
+
+ + +
+

get/set hit draw function. That function is used to draw custom hit area of a shape.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get hit draw function
+var hitFunc = shape.hitFunc();
+
+// set hit draw function
+shape.hitFunc(function(context) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

hitStrokeWidth(hitStrokeWidth)

+ + +
+
+ + +
+

get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var hitStrokeWidth = shape.hitStrokeWidth();
+
+// set hit stroke width
+shape.hitStrokeWidth(20);
+// set hit stroke width always equals to scene stroke width
+shape.hitStrokeWidth('auto');
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

intersects(point)

+ + +
+
+ + +
+

determines if point is in the shape, regardless if other shapes are on top of it. Note: because
+this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
+consecutively. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kerningFunc(kerningFunc)

+ + +
+
+ + +
+

get/set kerning function.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
kerningFunc + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get text decoration
+var kerningFunc = text.kerningFunc();
+
+// center text
+text.kerningFunc(function(leftChar, rightChar) {
+  return 1;
+});
+ + + +
+ + + +
+
+

letterSpacing(letterSpacing)

+ + +
+
+ + +
+

get/set letter spacing. The default is 0.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
letterSpacing + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get letter spacing value
+var letterSpacing = shape.letterSpacing();
+
+// set the letter spacing value
+shape.letterSpacing(2);
+ + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

linearLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set stroke linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point x
+var startPointX = shape.strokeLinearGradientStartPointX();
+
+// set stroke linear gradient start point x
+shape.strokeLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

lineCap(lineCap)

+ + +
+
+ + +
+

get/set line cap. Can be butt, round, or square

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineCap + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line cap
+var lineCap = shape.lineCap();
+
+// set line cap
+shape.lineCap('round');
+ + + +
+ + + +
+
+

lineJoin(lineJoin)

+ + +
+
+ + +
+

get/set line join. Can be miter, round, or bevel. The
+default is miter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineJoin + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line join
+var lineJoin = shape.lineJoin();
+
+// set line join
+shape.lineJoin('round');
+ + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

perfectDrawEnabled(perfectDrawEnabled)

+ + +
+
+ + +
+

get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set perfectDrawEnabled to false to improve performance.
+See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
perfectDrawEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get perfectDrawEnabled
+var perfectDrawEnabled = shape.perfectDrawEnabled();
+
+// set perfectDrawEnabled
+shape.perfectDrawEnabled();
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

sceneFunc(drawFunc)

+ + +
+
+ + +
+

get/set scene draw function. That function is used to draw the shape on a canvas.
+Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get scene draw function
+var sceneFunc = shape.sceneFunc();
+
+// set scene draw function
+shape.sceneFunc(function(context, shape) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  // like stroke and fill
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

shadowBlur(blur)

+ + +
+
+ + +
+

get/set shadow blur

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blur + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow blur
+var shadowBlur = shape.shadowBlur();
+
+// set shadow blur
+shape.shadowBlur(10);
+ + + +
+ + + +
+
+

shadowColor(color)

+ + +
+
+ + +
+

get/set shadow color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get shadow color
+var shadow = shape.shadowColor();
+
+// set shadow color with color string
+shape.shadowColor('green');
+
+// set shadow color with hex
+shape.shadowColor('#00ff00');
+
+// set shadow color with rgb
+shape.shadowColor('rgb(0,255,0)');
+
+// set shadow color with rgba and make it 50% opaque
+shape.shadowColor('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

shadowEnabled(enabled)

+ + +
+
+ + +
+

get/set shadow enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadow enabled flag
+var shadowEnabled = shape.shadowEnabled();
+
+// disable shadow
+shape.shadowEnabled(false);
+
+// enable shadow
+shape.shadowEnabled(true);
+ + + +
+ + + +
+
+

shadowForStrokeEnabled(shadowForStrokeEnabled)

+ + +
+
+ + +
+

get/set shadowForStrokeEnabled. Useful for performance optimization.
+You may set shape.shadowForStrokeEnabled(false). In this case stroke will no effect shadow.
+Remember if you set shadowForStrokeEnabled = false for non closed line - that line will have no shadow!.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shadowForStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadowForStrokeEnabled
+var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
+
+// set shadowForStrokeEnabled
+shape.shadowForStrokeEnabled();
+ + + +
+ + + +
+
+

shadowOffset(offset)

+ + +
+
+ + +
+

get/set shadow offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get shadow offset
+var shadowOffset = shape.shadowOffset();
+
+// set shadow offset
+shape.shadowOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

shadowOffsetX(x)

+ + +
+
+ + +
+

get/set shadow offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset x
+var shadowOffsetX = shape.shadowOffsetX();
+
+// set shadow offset x
+shape.shadowOffsetX(5);
+ + + +
+ + + +
+
+

shadowOffsetY(y)

+ + +
+
+ + +
+

get/set shadow offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset y
+var shadowOffsetY = shape.shadowOffsetY();
+
+// set shadow offset y
+shape.shadowOffsetY(5);
+ + + +
+ + + +
+
+

shadowOpacity(opacity)

+ + +
+
+ + +
+

get/set shadow opacity. must be a value between 0 and 1

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow opacity
+var shadowOpacity = shape.shadowOpacity();
+
+// set shadow opacity
+shape.shadowOpacity(0.5);
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke(color)

+ + +
+
+ + +
+

get/set stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get stroke color
+var stroke = shape.stroke();
+
+// set stroke color with color string
+shape.stroke('green');
+
+// set stroke color with hex
+shape.stroke('#00ff00');
+
+// set stroke color with rgb
+shape.stroke('rgb(0,255,0)');
+
+// set stroke color with rgba and make it 50% opaque
+shape.stroke('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

strokeEnabled(enabled)

+ + +
+
+ + +
+

get/set stroke enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke enabled flag
+var strokeEnabled = shape.strokeEnabled();
+
+// disable stroke
+shape.strokeEnabled(false);
+
+// enable stroke
+shape.strokeEnabled(true);
+ + + +
+ + + +
+
+

strokeHitEnabled(strokeHitEnabled)

+ + +
+
+ + +
+

deprecated, use hitStrokeWidth instead! get/set strokeHitEnabled property. Useful for performance optimization.
+You may set shape.strokeHitEnabled(false). In this case stroke will be no draw on hit canvas, so hit area
+of shape will be decreased (by lineWidth / 2). Remember that non closed line with strokeHitEnabled = false
+will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
+Default value is true.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeHitEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get strokeHitEnabled
+var strokeHitEnabled = shape.strokeHitEnabled();
+
+// set strokeHitEnabled
+shape.strokeHitEnabled();
+ + + +
+ + + +
+
+

strokeLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set stroke linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient color stops
+var colorStops = shape.strokeLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point
+var endPoint = shape.strokeLinearGradientEndPoint();
+
+// set stroke linear gradient end point
+shape.strokeLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point x
+var endPointX = shape.strokeLinearGradientEndPointX();
+
+// set stroke linear gradient end point x
+shape.strokeLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point y
+var endPointY = shape.strokeLinearGradientEndPointY();
+
+// set stroke linear gradient end point y
+shape.strokeLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

strokeLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point
+var startPoint = shape.strokeLinearGradientStartPoint();
+
+// set stroke linear gradient start point
+shape.strokeLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point y
+var startPointY = shape.strokeLinearGradientStartPointY();
+
+// set stroke linear gradient start point y
+shape.strokeLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

strokeScaleEnabled(enabled)

+ + +
+
+ + +
+

get/set strokeScale enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke scale enabled flag
+var strokeScaleEnabled = shape.strokeScaleEnabled();
+
+// disable stroke scale
+shape.strokeScaleEnabled(false);
+
+// enable stroke scale
+shape.strokeScaleEnabled(true);
+ + + +
+ + + +
+
+

strokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var strokeWidth = shape.strokeWidth();
+
+// set stroke width
+shape.strokeWidth(10);
+ + + +
+ + + +
+
+

textBaseline(textBaseline)

+ + +
+
+ + +
+

get/set text baseline. The default is 'middle'. Can be 'top', 'bottom', 'middle', 'alphabetic', 'hanging'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
textBaseline + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get current text baseline
+var textBaseline = shape.textBaseline();
+
+// set new text baseline
+shape.textBaseline('top');
+ + + +
+ + + +
+
+

textDecoration(textDecoration)

+ + +
+
+ + +
+

get/set text decoration of a text. Can be '' or 'underline'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
textDecoration + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get text decoration
+var textDecoration = shape.textDecoration();
+
+// underline text
+shape.textDecoration('underline');
+ + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Transform.html b/api/Konva.Transform.html new file mode 100644 index 000000000..b49a3902d --- /dev/null +++ b/api/Konva.Transform.html @@ -0,0 +1,1978 @@ + + + + + + + Konva Class: Transform + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Transform

+
+ +
+ +

+ Konva~ + + Transform +

+ +

Transform constructor.
+In most of the cases you don't need to use it in your app. Because it is for internal usage in Konva core.
+But there is a documentation for that class in case you still want
+to make some manual calculations.

+ + +
+ + +
+
+ + +
+
+

new Transform( [m])

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
m + + +Array + + + + + + + <optional>
+ + + + + +

Optional six-element matrix

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + +
+ + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

copy()

+ + +
+
+ + +
+

Copy Konva.Transform object

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
Example
+ +
const tr = shape.getTransform().copy()
+ + + +
+ + + +
+
+

decompose()

+ + +
+
+ + +
+

convert transformation matrix back into node's attributes

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getMatrix()

+ + +
+
+ + +
+

return matrix

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

getTranslation()

+ + +
+
+ + +
+

Returns the translation

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

2D point(x, y)

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

invert()

+ + +
+
+ + +
+

Invert the matrix

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

multiply(matrix)

+ + +
+
+ + +
+

Transform multiplication

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
matrix + + +Konva.Transform + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

point(point)

+ + +
+
+ + +
+

Transform point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + +

2D point(x, y)

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

2D point(x, y)

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

rotate(rad)

+ + +
+
+ + +
+

Apply rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rad + + +Number + + + + +

Angle in radians

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

scale(sx, sy)

+ + +
+
+ + +
+

Apply scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
sx + + +Number + + + + +
sy + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

skew(sx, sy)

+ + +
+
+ + +
+

Apply skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
sx + + +Number + + + + +
sy + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

translate(x, y)

+ + +
+
+ + +
+

Apply translation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Transformer.html b/api/Konva.Transformer.html new file mode 100644 index 000000000..703462705 --- /dev/null +++ b/api/Konva.Transformer.html @@ -0,0 +1,6902 @@ + + + + + + + Konva Class: Transformer + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Transformer

+
+ +
+ +

+ Konva~ + + Transformer +

+ +

Transformer constructor. Transformer is a special type of group that allow you transform Konva
+primitives and shapes. Transforming tool is not changing width and height properties of nodes
+when you resize them. Instead it changes scaleX and scaleY properties.

+ + +
+ + +
+
+ + +
+
+

new Transformer(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
resizeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Default is true

rotateEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Default is true

rotateLineVisible + + +Boolean + + + + + + + <optional>
+ + + + + +

Default is true

rotationSnaps + + +Array + + + + + + + <optional>
+ + + + + +

Array of angles for rotation snaps. Default is []

rotationSnapTolerance + + +Number + + + + + + + <optional>
+ + + + + +

Snapping tolerance. If closer than this it will snap. Default is 5

rotateAnchorOffset + + +Number + + + + + + + <optional>
+ + + + + +

Default is 50

rotateAnchorCursor + + +String + + + + + + + <optional>
+ + + + + +

Default is crosshair

padding + + +Number + + + + + + + <optional>
+ + + + + +

Default is 0

borderEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw border? Default is true

borderStroke + + +String + + + + + + + <optional>
+ + + + + +

Border stroke color

borderStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

Border stroke size

borderDash + + +Array + + + + + + + <optional>
+ + + + + +

Array for border dash.

anchorFill + + +String + + + + + + + <optional>
+ + + + + +

Anchor fill color

anchorStroke + + +String + + + + + + + <optional>
+ + + + + +

Anchor stroke color

anchorCornerRadius + + +String + + + + + + + <optional>
+ + + + + +

Anchor corner radius

anchorStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

Anchor stroke size

anchorSize + + +Number + + + + + + + <optional>
+ + + + + +

Default is 10

keepRatio + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we keep ratio when we are moving edges? Default is true

shiftBehavior + + +String + + + + + + + <optional>
+ + + + + +

How does transformer react on shift key press when we are moving edges? Default is 'default'

centeredScaling + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we resize relative to node's center? Default is false

enabledAnchors + + +Array + + + + + + + <optional>
+ + + + + +

Array of names of enabled handles

flipEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Can we flip/mirror shape on transform?. True by default

boundBoxFunc + + +function + + + + + + + <optional>
+ + + + + +

Bounding box function

ignoreStroke + + +function + + + + + + + <optional>
+ + + + + +

Should we ignore stroke size? Default is false

useSingleNodeRotation + + +Boolean + + + + + + + <optional>
+ + + + + +

When just one node attached, should we use its rotation for transformer?

shouldOverdrawWholeArea + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we fill whole transformer area with fake transparent shape to enable dragging from empty spaces?

+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var transformer = new Konva.Transformer({
+  nodes: [rectangle],
+  rotateAnchorOffset: 60,
+  enabledAnchors: ['top-left', 'top-right', 'bottom-left', 'bottom-right']
+});
+layer.add(transformer);
+ + + +
+ + +
+ + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

anchorCornerRadius(radius)

+ + +
+
+ + +
+

get/set anchor corner radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get
+var anchorCornerRadius = transformer.anchorCornerRadius();
+
+// set
+transformer.anchorCornerRadius(3);
+ + + +
+ + + +
+
+

anchorDragBoundFunc(func)

+ + +
+
+ + +
+

get/set dragging func for transformer anchors

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
func + + +function + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get
+var anchorDragBoundFunc = transformer.anchorDragBoundFunc();
+
+// set
+transformer.anchorDragBoundFunc(function(oldAbsPos, newAbsPos, event) {
+ return {
+  x: 0,
+  y: newAbsolutePosition.y
+ }
+});
+ + + +
+ + + +
+
+

anchorFill(anchorFill)

+ + +
+
+ + +
+

get/set anchor fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
anchorFill + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get
+var anchorFill = transformer.anchorFill();
+
+// set
+transformer.anchorFill('red');
+ + + +
+ + + +
+
+

anchorSize(size)

+ + +
+
+ + +
+

get/set anchor size. Default is 10

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get
+var anchorSize = transformer.anchorSize();
+
+// set
+transformer.anchorSize(20)
+ + + +
+ + + +
+
+

anchorStroke(strokeColor)

+ + +
+
+ + +
+

get/set anchor stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeColor + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get
+var anchorStroke = transformer.anchorStroke();
+
+// set
+transformer.anchorStroke('red');
+ + + +
+ + + +
+
+

anchorStrokeWidth(anchorStrokeWidth)

+ + +
+
+ + +
+

get/set anchor stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
anchorStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get
+var anchorStrokeWidth = transformer.anchorStrokeWidth();
+
+// set
+transformer.anchorStrokeWidth(3);
+ + + +
+ + + +
+
+

anchorStyleFunc(func)

+ + +
+
+ + +
+

get/set styling function for transformer anchors to overwrite default styles

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
func + + +function + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get
+var anchorStyleFunc = transformer.anchorStyleFunc();
+
+// set
+transformer.anchorStyleFunc(function(anchor) {
+ // anchor is a simple Konva.Rect instance
+ // it will be executed AFTER all attributes are set, like 'anchorStrokeWidth' or 'anchorFill'
+ if (anchor.hasName('.rotater')) {
+   // make rotater anchor filled black and looks like a circle
+   anchor.fill('black');
+   anchor.cornerRadius(anchor.width() / 2);
+ }
+});
+ + + +
+ + + +
+
+

attachTo()

+ + +
+
+ + +
+

alias to tr.nodes([shape])/ This method is deprecated and will be removed soon.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transformer + + + +
+
+ + + + + +
Example
+ +
transformer.attachTo(shape);
+ + + +
+ + + +
+
+

borderDash(dash)

+ + +
+
+ + +
+

get/set border dash array

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +

array

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get
+var borderDash = transformer.borderDash();
+
+// set
+transformer.borderDash([2, 2]);
+ + + +
+ + + +
+
+

borderEnabled(enabled)

+ + +
+
+ + +
+

get/set visibility of border

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get
+var borderEnabled = transformer.borderEnabled();
+
+// set
+transformer.borderEnabled(false);
+ + + +
+ + + +
+
+

borderStroke(enabled)

+ + +
+
+ + +
+

get/set border stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get
+var borderStroke = transformer.borderStroke();
+
+// set
+transformer.borderStroke('red');
+ + + +
+ + + +
+
+

borderStrokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set border stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get
+var borderStrokeWidth = transformer.borderStrokeWidth();
+
+// set
+transformer.borderStrokeWidth(3);
+ + + +
+ + + +
+
+

boundBoxFunc(func)

+ + +
+
+ + +
+

get/set bounding box function. IMPORTANT! boundBondFunc operates in absolute coordinates.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
func + + +function + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get
+var boundBoxFunc = transformer.boundBoxFunc();
+
+// set
+transformer.boundBoxFunc(function(oldBox, newBox) {
+  // width and height of the boxes are corresponding to total absolute width and height of all nodes combined
+  // so it includes scale of the node.
+  if (newBox.width > 200) {
+    return oldBox;
+  }
+  return newBox;
+});
+ + + +
+ + + +
+
+

centeredScaling(centeredScaling)

+ + +
+
+ + +
+

get/set should we resize relative to node's center?

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
centeredScaling + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get
+var centeredScaling = transformer.centeredScaling();
+
+// set
+transformer.centeredScaling(true);
+ + + +
+ + + +
+
+

detach()

+ + +
+
+ + +
+

detach transformer from an attached node

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transformer + + + +
+
+ + + + + +
Example
+ +
transformer.detach();
+ + + +
+ + + +
+
+

enabledAnchors(array)

+ + +
+
+ + +
+

get/set enabled handlers

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
array + + +Array + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get list of handlers
+var enabledAnchors = transformer.enabledAnchors();
+
+// set handlers
+transformer.enabledAnchors(['top-left', 'top-center', 'top-right', 'middle-right', 'middle-left', 'bottom-left', 'bottom-center', 'bottom-right']);
+ + + +
+ + + +
+
+

flipEnabled(flag)

+ + +
+
+ + +
+

get/set flip enabled

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
flag + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get flip enabled property
+var flipEnabled = transformer.flipEnabled();
+
+// set flip enabled property
+transformer.flipEnabled(false);
+ + + +
+ + + +
+
+

forceUpdate()

+ + +
+
+ + +
+

force update of Konva.Transformer.
+Use it when you updated attached Konva.Group and now you need to reset transformer size

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

getActiveAnchor()

+ + +
+
+ + +
+

return the name of current active anchor

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String +| + +Null + + + +
+
+ + + + + +
Example
+ +
transformer.getActiveAnchor();
+ + + +
+ + + +
+
+

ignoreStroke(ignoreStroke)

+ + +
+
+ + +
+

get/set should we think about stroke while resize? Good to use when a shape has strokeScaleEnabled = false
+default is false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ignoreStroke + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get
+var ignoreStroke = transformer.ignoreStroke();
+
+// set
+transformer.ignoreStroke(true);
+ + + +
+ + + +
+
+

isTransforming()

+ + +
+
+ + +
+

determine if transformer is in active transform

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

keepRatio(keepRatio)

+ + +
+
+ + +
+

get/set should we keep ratio while resize anchors at corners

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
keepRatio + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get
+var keepRatio = transformer.keepRatio();
+
+// set
+transformer.keepRatio(false);
+ + + +
+ + + +
+
+

nodes()

+ + +
+
+ + +
+

get/set attached nodes of the Transformer. Transformer will adapt to their size and listen to their events

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get
+const nodes = transformer.nodes();
+
+// set
+transformer.nodes([rect, circle]);
+
+// push new item:
+const oldNodes = transformer.nodes();
+const newNodes = oldNodes.concat([newShape]);
+// it is important to set new array instance (and concat method above will create it)
+transformer.nodes(newNodes);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the Transformer. You can use events: transform, transformstart, transformend, dragstart, dragmove, dragend

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'transform'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transformer + + + +
+
+ + + + + +
Example
+ +
// add click listener
+tr.on('transformstart', function() {
+  console.log('transform started');
+});
+ + + +
+ + + +
+
+

padding(padding)

+ + +
+
+ + +
+

get/set padding

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
padding + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get
+var padding = transformer.padding();
+
+// set
+transformer.padding(10);
+ + + +
+ + + +
+
+

resizeEnabled(enabled)

+ + +
+
+ + +
+

get/set resize ability. If false it will automatically hide resizing handlers

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get
+var resizeEnabled = transformer.resizeEnabled();
+
+// set
+transformer.resizeEnabled(false);
+ + + +
+ + + +
+
+

rotateAnchorCursor(cursorName)

+ + +
+
+ + +
+

get/set rotation anchor cursor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
cursorName + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get
+var currentRotationAnchorCursor = transformer.rotateAnchorCursor();
+
+// set
+transformer.rotateAnchorCursor('grab');
+ + + +
+ + + +
+
+

rotateAnchorOffset(offset)

+ + +
+
+ + +
+

get/set distance for rotation handler

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get
+var rotateAnchorOffset = transformer.rotateAnchorOffset();
+
+// set
+transformer.rotateAnchorOffset(100);
+ + + +
+ + + +
+
+

rotateEnabled(enabled)

+ + +
+
+ + +
+

get/set ability to rotate.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get
+var rotateEnabled = transformer.rotateEnabled();
+
+// set
+transformer.rotateEnabled(false);
+ + + +
+ + + +
+
+

rotateLineVisible(enabled)

+ + +
+
+ + +
+

get/set visibility of a little line that connects transformer and rotate anchor.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get
+var rotateLineVisible = transformer.rotateLineVisible();
+
+// set
+transformer.rotateLineVisible(false);
+ + + +
+ + + +
+
+

rotationSnaps(array)

+ + +
+
+ + +
+

get/set rotation snaps angles.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
array + + +Array + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get
+var rotationSnaps = transformer.rotationSnaps();
+
+// set
+transformer.rotationSnaps([0, 90, 180, 270]);
+ + + +
+ + + +
+
+

rotationSnapTolerance(tolerance)

+ + +
+
+ + +
+

get/set distance for rotation tolerance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tolerance + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get
+var rotationSnapTolerance = transformer.rotationSnapTolerance();
+
+// set
+transformer.rotationSnapTolerance(100);
+ + + +
+ + + +
+
+

shiftBehavior(shiftBehavior)

+ + +
+
+ + +
+

get/set how to react on skift key while resizing anchors at corners

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shiftBehavior + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get
+var shiftBehavior = transformer.shiftBehavior();
+
+// set
+transformer.shiftBehavior('none');
+ + + +
+ + + +
+
+

shouldOverdrawWholeArea(shouldOverdrawWholeArea)

+ + +
+
+ + +
+

using this setting you can drag transformer group by dragging empty space between attached nodes
+shouldOverdrawWholeArea = true may temporary disable all events on attached nodes

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shouldOverdrawWholeArea + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get
+var shouldOverdrawWholeArea = transformer.shouldOverdrawWholeArea();
+
+// set
+transformer.shouldOverdrawWholeArea(true);
+ + + +
+ + + +
+
+

stopTransform()

+ + +
+
+ + +
+

Stop active transform action

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

useSingleNodeRotation(useSingleNodeRotation)

+ + +
+
+ + +
+

If you have just one attached node to Transformer it will set its initial rotation to the rotation of that node.
+In some cases you may need to set a different rotation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
useSingleNodeRotation + + +Boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// set flag to false
+transformer.useSingleNodeRotation(false);
+// attach a shape
+transformer.nodes([shape]);
+transformer.rotation(45);
+transformer.update();
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Tween.html b/api/Konva.Tween.html new file mode 100644 index 000000000..233840d25 --- /dev/null +++ b/api/Konva.Tween.html @@ -0,0 +1,1190 @@ + + + + + + + Konva Class: Tween + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Tween

+
+ +
+ +

+ Konva~ + + Tween +

+ +

Tween constructor. Tweens enable you to animate a node between the current state and a new state.
+You can play, pause, reverse, seek, reset, and finish tweens. By default, tweens are animated using
+a linear easing. For more tweening options, check out Konva.Easings

+ + +
+ + +
+
+ + +
+
+

new Tween()

+ + +
+
+ + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
// instantiate new tween which fully rotates a node in 1 second
+var tween = new Konva.Tween({
+  // list of tween specific properties
+  node: node,
+  duration: 1,
+  easing: Konva.Easings.EaseInOut,
+  onUpdate: () => console.log('node attrs updated')
+  onFinish: () => console.log('finished'),
+  // set new values for any attributes of a passed node
+  rotation: 360,
+  fill: 'red'
+});
+
+// play tween
+tween.play();
+
+// pause tween
+tween.pause();
+ + + +
+ + +
+ + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

destroy()

+ + +
+
+ + +
+

destroy

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

finish()

+ + +
+
+ + +
+

finish

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Tween + + + +
+
+ + + + + +
+ + + +
+
+

pause()

+ + +
+
+ + +
+

pause

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Tween + + + +
+
+ + + + + +
+ + + +
+
+

play()

+ + +
+
+ + +
+

play

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Tween + + + +
+
+ + + + + +
+ + + +
+
+

reset()

+ + +
+
+ + +
+

reset

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Tween + + + +
+
+ + + + + +
+ + + +
+
+

reverse()

+ + +
+
+ + +
+

reverse

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Tween + + + +
+
+ + + + + +
+ + + +
+
+

seek((t)

+ + +
+
+ + +
+

seek

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
t + + +Integer + + + + +

time in seconds between 0 and the duration

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Tween + + + +
+
+ + + + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Util.html b/api/Konva.Util.html new file mode 100644 index 000000000..4c2b0419f --- /dev/null +++ b/api/Konva.Util.html @@ -0,0 +1,776 @@ + + + + + + + Konva Namespace: Util + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Namespace: Util

+
+ +
+ +

+ Konva. + + Util +

+ + +
+ + +
+
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

<static> getRandomColor()

+ + +
+
+ + +
+

return random hex color

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
shape.fill(Konva.Util.getRandomColor());
+ + + +
+ + + +
+
+

<static> getRGB(color)

+ + +
+
+ + +
+

get RGB components of a color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
// each of the following examples return {r:0, g:0, b:255}
+var rgb = Konva.Util.getRGB('blue');
+var rgb = Konva.Util.getRGB('#0000ff');
+var rgb = Konva.Util.getRGB('rgb(0,0,255)');
+ + + +
+ + + +
+
+

<static> haveIntersection(r1, r2)

+ + +
+
+ + +
+

check intersection of two client rectangles

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
r1 + + +Object + + + + +

{ x, y, width, height } client rectangle

r2 + + +Object + + + + +

{ x, y, width, height } client rectangle

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
const overlapping = Konva.Util.haveIntersection(shape1.getClientRect(), shape2.getClientRect());
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.Wedge.html b/api/Konva.Wedge.html new file mode 100644 index 000000000..b9dd443ec --- /dev/null +++ b/api/Konva.Wedge.html @@ -0,0 +1,34429 @@ + + + + + + + Konva Class: Wedge + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: Wedge

+
+ +
+ +

+ Konva. + + Wedge +

+ +

Wedge constructor

+ + +
+ + +
+
+ + +
+
+

new Wedge(config)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
angle + + +Number + + + + + + + + + + +

in degrees

radius + + +Number + + + + + + + + + + +
clockwise + + +Boolean + + + + + + + <optional>
+ + + + + +
fill + + +String + + + + + + + <optional>
+ + + + + +

fill color

fillPatternImage + + +Image + + + + + + + <optional>
+ + + + + +

fill pattern image

fillPatternX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScale + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillPatternScaleX + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternScaleY + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRotation + + +Number + + + + + + + <optional>
+ + + + + +
fillPatternRepeat + + +String + + + + + + + <optional>
+ + + + + +

can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"

fillLinearGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillLinearGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillLinearGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillRadialGradientStartPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientStartPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPoint + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

fillRadialGradientEndPointX + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndPointY + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientStartRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientEndRadius + + +Number + + + + + + + <optional>
+ + + + + +
fillRadialGradientColorStops + + +Array + + + + + + + <optional>
+ + + + + +

array of color stops

fillEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the fill. The default value is true

fillPriority + + +String + + + + + + + <optional>
+ + + + + +

can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration

stroke + + +String + + + + + + + <optional>
+ + + + + +

stroke color

strokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

stroke width

fillAfterStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

Should we draw fill AFTER stroke? Default is false.

hitStrokeWidth + + +Number + + + + + + + <optional>
+ + + + + +

size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth

strokeHitEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke hit region. The default is true

perfectDrawEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables using buffer canvas. The default is true

shadowForStrokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables shadow for stroke. The default is true

strokeScaleEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables stroke scale. The default is true

strokeEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the stroke. The default value is true

lineJoin + + +String + + + + + + + <optional>
+ + + + + +

can be miter, round, or bevel. The default
+is miter

lineCap + + +String + + + + + + + <optional>
+ + + + + +

can be butt, round, or square. The default
+is butt

shadowColor + + +String + + + + + + + <optional>
+ + + + + +
shadowBlur + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffset + + +Object + + + + + + + <optional>
+ + + + + +

object with x and y component

shadowOffsetX + + +Number + + + + + + + <optional>
+ + + + + +
shadowOffsetY + + +Number + + + + + + + <optional>
+ + + + + +
shadowOpacity + + +Number + + + + + + + <optional>
+ + + + + +

shadow opacity. Can be any real number
+between 0 and 1

shadowEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the shadow. The default value is true

dash + + +Array + + + + + + + <optional>
+ + + + + +
dashEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

flag which enables or disables the dashArray. The default value is true

x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
visible + + +Boolean + + + + + + + <optional>
+ + + + + +
listening + + +Boolean + + + + + + + <optional>
+ + + + + +

whether or not the node is listening for events

id + + +String + + + + + + + <optional>
+ + + + + +

unique id

name + + +String + + + + + + + <optional>
+ + + + + +

non-unique name

opacity + + +Number + + + + + + + <optional>
+ + + + + +

determines node opacity. Can be any number between 0 and 1

scale + + +Object + + + + + + + <optional>
+ + + + + +

set scale

scaleX + + +Number + + + + + + + <optional>
+ + + + + +

set scale x

scaleY + + +Number + + + + + + + <optional>
+ + + + + +

set scale y

rotation + + +Number + + + + + + + <optional>
+ + + + + +

rotation in degrees

offset + + +Object + + + + + + + <optional>
+ + + + + +

offset from center point and rotation point

offsetX + + +Number + + + + + + + <optional>
+ + + + + +

set offset x

offsetY + + +Number + + + + + + + <optional>
+ + + + + +

set offset y

draggable + + +Boolean + + + + + + + <optional>
+ + + + + +

makes the node draggable. When stages are draggable, you can drag and drop
+the entire stage by dragging any portion of the stage

dragDistance + + +Number + + + + + + + <optional>
+ + + + + +
dragBoundFunc + + +function + + + + + + + <optional>
+ + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
// draw a wedge that's pointing downwards
+var wedge = new Konva.Wedge({
+  radius: 40,
+  fill: 'red',
+  stroke: 'black'
+  strokeWidth: 5,
+  angleDeg: 60,
+  rotationDeg: -120
+});
+ + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ +
+ +
+
+

absolutePosition(pos)

+ + +
+
+ + +
+

get/set node absolute position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.absolutePosition();
+
+// set position
+node.absolutePosition({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

addName(name)

+ + +
+
+ + +
+

add name to node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.addName('selected');
+node.name(); // return 'red selected'
+ + + +
+ + + +
+
+

alpha(alpha)

+ + +
+
+ + +
+

get/set filter alpha value. Use with Konva.Filters.RGBA filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alpha + + +Float + + + + +

value between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

angle(angle)

+ + +
+
+ + +
+

get/set angle in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
angle + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get angle
+var angle = wedge.angle();
+
+// set angle
+wedge.angle(20);
+ + + +
+ + + +
+
+

blue(blue)

+ + +
+
+ + +
+

get/set filter blue value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blue + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

blurRadius(radius)

+ + +
+
+ + +
+

get/set blur radius. Use with Konva.Filters.Blur filter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

brightness(brightness)

+ + +
+
+ + +
+

get/set filter brightness. The brightness is a number between -1 and 1.  Positive values
+brighten the pixels and negative values darken them. Use with Konva.Filters.Brighten filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
brightness + + +Number + + + + +

value between -1 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

cache( [config])

+ + +
+
+ + +
+

cache node to improve drawing performance, apply filters, or create more accurate
+hit regions. For all basic shapes size of cache canvas will be automatically detected.
+If you need to cache your custom Konva.Shape instance you have to pass shape's bounding box
+properties. Look at https://konvajs.org/docs/performance/Shape_Caching.html for more information.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
config + + +Object + + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
x + + +Number + + + + + + + <optional>
+ + + + + +
y + + +Number + + + + + + + <optional>
+ + + + + +
width + + +Number + + + + + + + <optional>
+ + + + + +
height + + +Number + + + + + + + <optional>
+ + + + + +
offset + + +Number + + + + + + + <optional>
+ + + + + +

increase canvas size by offset pixel in all directions.

drawBorder + + +Boolean + + + + + + + <optional>
+ + + + + +

when set to true, a red border will be drawn around the cached
+region for debugging purposes

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

control imageSmoothingEnabled property of created canvas for cache

hitCanvasPixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

change quality (or pixel ratio) of cached hit canvas.

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// cache a shape with the x,y position of the bounding box at the center and
+// the width and height of the bounding box equal to the width and height of
+// the shape obtained from shape.width() and shape.height()
+image.cache();
+
+// cache a node and define the bounding box position and size
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200
+});
+
+// cache a node and draw a red border around the bounding box
+// for debugging purposes
+node.cache({
+  x: -30,
+  y: -30,
+  width: 100,
+  height: 200,
+  offset : 10,
+  drawBorder: true
+});
+ + + +
+ + + +
+
+

clearCache()

+ + +
+
+ + +
+

clear cached canvas

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.clearCache();
+ + + +
+ + + +
+
+

clockwise(clockwise)

+ + +
+
+ + +
+

get/set clockwise flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
clockwise + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get clockwise flag
+var clockwise = wedge.clockwise();
+
+// draw wedge counter-clockwise
+wedge.clockwise(false);
+
+// draw wedge clockwise
+wedge.clockwise(true);
+ + + +
+ + + +
+
+

clone(obj)

+ + +
+
+ + +
+

clone node. Returns a new Node instance with identical attributes. You can also override
+the node properties with an object literal, enabling you to use an existing node as a template
+for another node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + +

override attrs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// simple clone
+var clone = node.clone();
+
+// clone a node and override the x position
+var clone = rect.clone({
+  x: 5
+});
+ + + +
+ + + +
+
+

contrast(contrast)

+ + +
+
+ + +
+

get/set filter contrast. The contrast is a number between -100 and 100.
+Use with Konva.Filters.Contrast filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
contrast + + +Number + + + + +

value between -100 and 100

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

dash(dash)

+ + +
+
+ + +
+

get/set dash array for stroke.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dash + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// apply dashed stroke that is 10px long and 5 pixels apart
+ line.dash([10, 5]);
+ // apply dashed stroke that is made up of alternating dashed
+ // lines that are 10px long and 20px apart, and dots that have
+ // a radius of 5px and are 20px apart
+ line.dash([10, 20, 0.001, 20]);
+ + + +
+ + + +
+
+

dashEnabled(enabled)

+ + +
+
+ + +
+

get/set dash enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get dash enabled flag
+var dashEnabled = shape.dashEnabled();
+
+// disable dash
+shape.dashEnabled(false);
+
+// enable dash
+shape.dashEnabled(true);
+ + + +
+ + + +
+
+

destroy()

+ + +
+
+ + +
+

remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
+If the node is a container (Group, Stage or Layer) it will destroy all children too.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
node.destroy();
+ + + +
+ + + +
+
+

dragBoundFunc(dragBoundFunc)

+ + +
+
+ + +
+

get/set drag bound function. This is used to override the default
+drag and drop position.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragBoundFunc + + +function + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get drag bound function
+var dragBoundFunc = node.dragBoundFunc();
+
+// create vertical drag and drop
+node.dragBoundFunc(function(pos){
+  // important pos - is absolute position of the node
+  // you should return absolute position too
+  return {
+    x: this.absolutePosition().x,
+    y: pos.y
+  };
+});
+ + + +
+ + + +
+
+

dragDistance(distance)

+ + +
+
+ + +
+

get/set drag distance

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get drag distance
+var dragDistance = node.dragDistance();
+
+// set distance
+// node starts dragging only if pointer moved more then 3 pixels
+node.dragDistance(3);
+// or set globally
+Konva.dragDistance = 3;
+ + + +
+ + + +
+
+

draggable(draggable)

+ + +
+
+ + +
+

get/set draggable flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
draggable + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get draggable flag
+var draggable = node.draggable();
+
+// enable drag and drop
+node.draggable(true);
+
+// disable drag and drop
+node.draggable(false);
+ + + +
+ + + +
+
+

draw()

+ + +
+
+ + +
+

draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

drawHitFromCache(alphaThreshold)

+ + +
+
+ + +
+

draw hit graph using the cached scene canvas

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
alphaThreshold + + +Integer + + + + +

alpha channel threshold that determines whether or not
+a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
+The default is 0

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
shape.cache();
+shape.drawHitFromCache();
+ + + +
+ + + +
+
+

embossBlend(embossBlend)

+ + +
+
+ + +
+

get/set emboss blend. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossBlend + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

embossDirection(embossDirection)

+ + +
+
+ + +
+

get/set emboss direction. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossDirection + + +String + + + + +

can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
+The default is top-left

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

embossStrength(level)

+ + +
+
+ + +
+

get/set emboss strength. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

embossWhiteLevel(embossWhiteLevel)

+ + +
+
+ + +
+

get/set emboss white level. Use with Konva.Filters.Emboss filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
embossWhiteLevel + + +Number + + + + +

between 0 and 1. Default is 0.5

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

enhance(amount)

+ + +
+
+ + +
+

get/set enhance. Use with Konva.Filters.Enhance filter. -1 to 1 values

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amount + + +Float + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Float + + + +
+
+ + + + + +
+ + + +
+
+

fill(color)

+ + +
+
+ + +
+

get/set fill color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill color
+var fill = shape.fill();
+
+// set fill color with color string
+shape.fill('green');
+
+// set fill color with hex
+shape.fill('#00ff00');
+
+// set fill color with rgb
+shape.fill('rgb(0,255,0)');
+
+// set fill color with rgba and make it 50% opaque
+shape.fill('rgba(0,255,0,0.5');
+
+// shape without fill
+shape.fill(null);
+ + + +
+ + + +
+
+

fillAfterStrokeEnabled(fillAfterStrokeEnabled)

+ + +
+
+ + +
+

get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
+In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
+Especially useful for Text objects.
+Default is false.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fillAfterStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
+
+// set stroke width
+shape.fillAfterStrokeEnabled(true);
+ + + +
+ + + +
+
+

fillEnabled(enabled)

+ + +
+
+ + +
+

get/set fill enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get fill enabled flag
+var fillEnabled = shape.fillEnabled();
+
+// disable fill
+shape.fillEnabled(false);
+
+// enable fill
+shape.fillEnabled(true);
+ + + +
+ + + +
+
+

fillLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient color stops
+var colorStops = shape.fillLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point
+var endPoint = shape.fillLinearGradientEndPoint();
+
+// set fill linear gradient end point
+shape.fillLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point x
+var endPointX = shape.fillLinearGradientEndPointX();
+
+// set fill linear gradient end point x
+shape.fillLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient end point y
+var endPointY = shape.fillLinearGradientEndPointY();
+
+// set fill linear gradient end point y
+shape.fillLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point
+var startPoint = shape.fillLinearGradientStartPoint();
+
+// set fill linear gradient start point
+shape.fillLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point x
+var startPointX = shape.fillLinearGradientStartPointX();
+
+// set fill linear gradient start point x
+shape.fillLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill linear gradient start point y
+var startPointY = shape.fillLinearGradientStartPointY();
+
+// set fill linear gradient start point y
+shape.fillLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillPatternImage(image)

+ + +
+
+ + +
+

get/set fill pattern image

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
image + + +Image + + + + +

object

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Image + + + +
+
+ + + + + +
Example
+ +
// get fill pattern image
+var fillPatternImage = shape.fillPatternImage();
+
+// set fill pattern image
+var imageObj = new Image();
+imageObj.onload = function() {
+  shape.fillPatternImage(imageObj);
+};
+imageObj.src = 'path/to/image/jpg';
+ + + +
+ + + +
+
+

fillPatternOffset(offset)

+ + +
+
+ + +
+

get/set fill pattern offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset
+var patternOffset = shape.fillPatternOffset();
+
+// set fill pattern offset
+shape.fillPatternOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillPatternOffsetX(x)

+ + +
+
+ + +
+

get/set fill pattern offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset x
+var patternOffsetX = shape.fillPatternOffsetX();
+
+// set fill pattern offset x
+shape.fillPatternOffsetX(20);
+ + + +
+ + + +
+
+

fillPatternOffsetY(y)

+ + +
+
+ + +
+

get/set fill pattern offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern offset y
+var patternOffsetY = shape.fillPatternOffsetY();
+
+// set fill pattern offset y
+shape.fillPatternOffsetY(10);
+ + + +
+ + + +
+
+

fillPatternRepeat(repeat)

+ + +
+
+ + +
+

get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
repeat + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill pattern repeat
+var repeat = shape.fillPatternRepeat();
+
+// repeat pattern in x direction only
+shape.fillPatternRepeat('repeat-x');
+
+// do not repeat the pattern
+shape.fillPatternRepeat('no-repeat');
+ + + +
+ + + +
+
+

fillPatternRotation(rotation)

+ + +
+
+ + +
+

get/set fill pattern rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill pattern rotation
+var patternRotation = shape.fillPatternRotation();
+
+// set fill pattern rotation
+shape.fillPatternRotation(20);
+ + + +
+ + + +
+
+

fillPatternScale(scale)

+ + +
+
+ + +
+

get/set fill pattern scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale
+var patternScale = shape.fillPatternScale();
+
+// set fill pattern scale
+shape.fillPatternScale({
+  x: 2,
+  y: 2
+});
+ + + +
+ + + +
+
+

fillPatternScaleX(x)

+ + +
+
+ + +
+

get/set fill pattern scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale x
+var patternScaleX = shape.fillPatternScaleX();
+
+// set fill pattern scale x
+shape.fillPatternScaleX(2);
+ + + +
+ + + +
+
+

fillPatternScaleY(y)

+ + +
+
+ + +
+

get/set fill pattern scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern scale y
+var patternScaleY = shape.fillPatternScaleY();
+
+// set fill pattern scale y
+shape.fillPatternScaleY(2);
+ + + +
+ + + +
+
+

fillPatternX(x)

+ + +
+
+ + +
+

get/set fill pattern x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern x
+var fillPatternX = shape.fillPatternX();
+// set fill pattern x
+shape.fillPatternX(20);
+ + + +
+ + + +
+
+

fillPatternY(y)

+ + +
+
+ + +
+

get/set fill pattern y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill pattern y
+var fillPatternY = shape.fillPatternY();
+// set fill pattern y
+shape.fillPatternY(20);
+ + + +
+ + + +
+
+

fillPriority(priority)

+ + +
+
+ + +
+

get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
+This is handy if you want to toggle between different fill types.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
priority + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get fill priority
+var fillPriority = shape.fillPriority();
+
+// set fill priority
+shape.fillPriority('linear-gradient');
+ + + +
+ + + +
+
+

fillRadialGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set fill radial gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient color stops
+var colorStops = shape.fillRadialGradientColorStops();
+
+// create a radial gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
+ + + +
+ + + +
+
+

fillRadialGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set fill radial gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point
+var endPoint = shape.fillRadialGradientEndPoint();
+
+// set fill radial gradient end point
+shape.fillRadialGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point x
+var endPointX = shape.fillRadialGradientEndPointX();
+
+// set fill radial gradient end point x
+shape.fillRadialGradientEndPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient end point y
+var endPointY = shape.fillRadialGradientEndPointY();
+
+// set fill radial gradient end point y
+shape.fillRadialGradientEndPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientEndRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient end radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient end radius
+var endRadius = shape.fillRadialGradientEndRadius();
+
+// set radial gradient end radius
+shape.fillRadialGradientEndRadius(100);
+ + + +
+ + + +
+
+

fillRadialGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set fill radial gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point
+var startPoint = shape.fillRadialGradientStartPoint();
+
+// set fill radial gradient start point
+shape.fillRadialGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

fillRadialGradientStartPointX(x)

+ + +
+
+ + +
+

get/set fill radial gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point x
+var startPointX = shape.fillRadialGradientStartPointX();
+
+// set fill radial gradient start point x
+shape.fillRadialGradientStartPointX(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartPointY(y)

+ + +
+
+ + +
+

get/set fill radial gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get fill radial gradient start point y
+var startPointY = shape.fillRadialGradientStartPointY();
+
+// set fill radial gradient start point y
+shape.fillRadialGradientStartPointY(20);
+ + + +
+ + + +
+
+

fillRadialGradientStartRadius(radius)

+ + +
+
+ + +
+

get/set fill radial gradient start radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radial gradient start radius
+var startRadius = shape.fillRadialGradientStartRadius();
+
+// set radial gradient start radius
+shape.fillRadialGradientStartRadius(0);
+ + + +
+ + + +
+
+

fillRule(rotation)

+ + +
+
+ + +
+

get/set fill rule

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +CanvasFillRule + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Shape + + + +
+
+ + + + + +
Example
+ +
// get fill rule
+var fillRule = shape.fillRule();
+
+// set fill rule
+shape.fillRule('evenodd');
+ + + +
+ + + +
+
+

filters(filters)

+ + +
+
+ + +
+

get/set filters. Filters are applied to cached canvases

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
filters + + +Array + + + + +

array of filters

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get filters
+var filters = node.filters();
+
+// set a single filter
+node.cache();
+node.filters([Konva.Filters.Blur]);
+
+// set multiple filters
+node.cache();
+node.filters([
+  Konva.Filters.Blur,
+  Konva.Filters.Sepia,
+  Konva.Filters.Invert
+]);
+ + + +
+ + + +
+
+

findAncestor(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get ancestor (parent or parent of the parent, etc) of the node that match passed selector

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

ancestor

+
+ + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var group = node.findAncestors('.mygroup');
+ + + +
+ + + +
+
+

findAncestors(selector [, includeSelf] [, stopNode])

+ + +
+
+ + +
+

get all ancestors (parent then parent of the parent, etc) of the node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
selector + + +String + + + + + + + + + + +

selector for search

includeSelf + + +Boolean + + + + + + + <optional>
+ + + + + +

show we think that node is ancestro itself?

stopNode + + +Konva.Node + + + + + + + <optional>
+ + + + + +

optional node where we need to stop searching (one of ancestors)

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

[ancestors]

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get one of the parent group
+var parentGroups = node.findAncestors('Group');
+ + + +
+ + + +
+
+

fire(eventType [, evt] [, bubble])

+ + +
+
+ + +
+

fire event

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
eventType + + +String + + + + + + + + + + +

event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent

evt + + +Event + + + + + + + <optional>
+ + + + + +

event object

bubble + + +Boolean + + + + + + + <optional>
+ + + + + +

setting the value to false, or leaving it undefined, will result in the event
+not bubbling. Setting the value to true will result in the event bubbling.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// manually fire click event
+node.fire('click');
+
+// fire custom event
+node.fire('foo');
+
+// fire custom event with custom event object
+node.fire('foo', {
+  bar: 10
+});
+
+// fire click event that bubbles
+node.fire('click', null, true);
+ + + +
+ + + +
+
+

getAbsoluteOpacity()

+ + +
+
+ + +
+

get absolute opacity

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

getAbsolutePosition(Ancestor)

+ + +
+
+ + +
+

get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Ancestor + + +Object + + + + +

optional ancestor node

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// returns absolute position relative to top-left corner of canvas
+node.getAbsolutePosition();
+
+// calculate absolute position of node, inside stage
+// so stage transforms are ignored
+node.getAbsolutePosition(stage)
+ + + +
+ + + +
+
+

getAbsoluteRotation()

+ + +
+
+ + +
+

get absolute rotation of the node which takes into
+account its ancestor rotations

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get absolute rotation
+var rotation = node.getAbsoluteRotation();
+ + + +
+ + + +
+
+

getAbsoluteScale()

+ + +
+
+ + +
+

get absolute scale of the node which takes into
+account its ancestor scales

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get absolute scale x
+var scaleX = node.getAbsoluteScale().x;
+ + + +
+ + + +
+
+

getAbsoluteTransform()

+ + +
+
+ + +
+

get absolute transform of the node which takes into
+account its ancestor transforms

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getAbsoluteZIndex()

+ + +
+
+ + +
+

get absolute z-index which takes into account sibling
+and ancestor indices

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getAncestors()

+ + +
+
+ + +
+

get ancestors

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
shape.getAncestors().forEach(function(node) {
+  console.log(node.getId());
+})
+ + + +
+ + + +
+
+

getAttr(attr)

+ + +
+
+ + +
+

get attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer +| + +String +| + +Object +| + +Array + + + +
+
+ + + + + +
Example
+ +
var x = node.getAttr('x');
+ + + +
+ + + +
+
+

getAttrs()

+ + +
+
+ + +
+

get attrs object literal

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

getClassName()

+ + +
+
+ + +
+

get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

getClientRect(config)

+ + +
+
+ + +
+

Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
+The purpose of the method is similar to getBoundingClientRect API of the DOM.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
skipTransform + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply transform to node for calculating rect?

skipShadow + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply shadow to the node for calculating bound box?

skipStroke + + +Boolean + + + + + + + <optional>
+ + + + + +

should we apply stroke to the node for calculating bound box?

relativeTo + + +Object + + + + + + + <optional>
+ + + + + +

calculate client rect relative to one of the parents

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
var rect = new Konva.Rect({
+     width : 100,
+     height : 100,
+     x : 50,
+     y : 50,
+     strokeWidth : 4,
+     stroke : 'black',
+     offsetX : 50,
+     scaleY : 2
+});
+
+// get client rect without think off transformations (position, rotation, scale, offset, etc)
+rect.getClientRect({ skipTransform: true});
+// returns {
+//     x : -2,   // two pixels for stroke / 2
+//     y : -2,
+//     width : 104, // increased by 4 for stroke
+//     height : 104
+//}
+
+// get client rect with transformation applied
+rect.getClientRect();
+// returns Object {x: -2, y: 46, width: 104, height: 208}
+ + + +
+ + + +
+
+

getDepth()

+ + +
+
+ + +
+

get node depth in node tree. Returns an integer.
+e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
+be >= 2

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

getLayer()

+ + +
+
+ + +
+

get layer ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Layer + + + +
+
+ + + + + +
+ + + +
+
+

getParent()

+ + +
+
+ + +
+

get parent container

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

getRelativePointerPosition()

+ + +
+
+ + +
+

get position of first pointer (like mouse or first touch) relative to local coordinates of current node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// let's think we have a rectangle at position x = 10, y = 10
+// now we clicked at x = 15, y = 15 of the stage
+// if you want to know position of the click, related to the rectangle you can use
+rect.getRelativePointerPosition();
+ + + +
+ + + +
+
+

getSelfRect()

+ + +
+
+ + +
+

return self rectangle (x, y, width, height) of shape.
+This method are not taken into account transformation and styles.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

rect with {x, y, width, height} properties

+
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
rect.getSelfRect();  // return {x:0, y:0, width:rect.width(), height:rect.height()}
+circle.getSelfRect();  // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
+ + + +
+ + + +
+
+

getStage()

+ + +
+
+ + +
+

get stage ancestor

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Stage + + + +
+
+ + + + + +
+ + + +
+
+

getTransform()

+ + +
+
+ + +
+

get transform of the node

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Transform + + + +
+
+ + + + + +
+ + + +
+
+

getType()

+ + +
+
+ + +
+

get the node type, which may return Stage, Layer, Group, or Shape

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

globalCompositeOperation(type)

+ + +
+
+ + +
+

get/set globalCompositeOperation of a node. globalCompositeOperation DOESN'T affect hit graph of nodes. So they are still trigger to events as they have default "source-over" globalCompositeOperation.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get globalCompositeOperation
+var globalCompositeOperation = shape.globalCompositeOperation();
+
+// set globalCompositeOperation
+shape.globalCompositeOperation('source-in');
+ + + +
+ + + +
+
+

green(green)

+ + +
+
+ + +
+

get/set filter green value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
green + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

hasFill()

+ + +
+
+ + +
+

returns whether or not the shape will be filled

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasName(name)

+ + +
+
+ + +
+

check is node has name

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
node.name('red');
+node.hasName('red');   // return true
+node.hasName('selected'); // return false
+node.hasName(''); // return false
+ + + +
+ + + +
+
+

hasShadow()

+ + +
+
+ + +
+

returns whether or not a shadow will be rendered

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

hasStroke()

+ + +
+
+ + +
+

returns whether or not the shape will be stroked

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

height(height)

+ + +
+
+ + +
+

get/set height

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get height
+var height = node.height();
+
+// set height
+node.height(100);
+ + + +
+ + + +
+
+

hide()

+ + +
+
+ + +
+

hide node. Hidden nodes are no longer detectable

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

hitFunc(drawFunc)

+ + +
+
+ + +
+

get/set hit draw function. That function is used to draw custom hit area of a shape.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get hit draw function
+var hitFunc = shape.hitFunc();
+
+// set hit draw function
+shape.hitFunc(function(context) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

hitStrokeWidth(hitStrokeWidth)

+ + +
+
+ + +
+

get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitStrokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var hitStrokeWidth = shape.hitStrokeWidth();
+
+// set hit stroke width
+shape.hitStrokeWidth(20);
+// set hit stroke width always equals to scene stroke width
+shape.hitStrokeWidth('auto');
+ + + +
+ + + +
+
+

hue(hue)

+ + +
+
+ + +
+

get/set hsv hue in degrees. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hue + + +Number + + + + +

value between 0 and 359

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

id(id)

+ + +
+
+ + +
+

get/set id. Id is global for whole page.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get id
+var name = node.id();
+
+// set id
+node.id('foo');
+ + + +
+ + + +
+
+

intersects(point)

+ + +
+
+ + +
+

determines if point is in the shape, regardless if other shapes are on top of it. Note: because
+this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
+consecutively. Please use the Konva.Stage#getIntersection method if at all possible
+because it performs much better

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
point + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isCached()

+ + +
+
+ + +
+

determine if node is currently cached

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isClientRectOnScreen(margin)

+ + +
+
+ + +
+

determine if node (at least partially) is currently in user-visible area

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
margin + + +Number +| + +Object + + + + +

optional margin in pixels

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get index
+// default calculations
+var isOnScreen = node.isClientRectOnScreen()
+// increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
+var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
+ + + +
+ + + +
+
+

isDragging()

+ + +
+
+ + +
+

determine if node is currently in drag and drop mode

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

isListening()

+ + +
+
+ + +
+

determine if node is listening for events by taking into account ancestors.

+

Parent | Self | isListening
+listening | listening |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

isVisible()

+ + +
+
+ + +
+

determine if node is visible by taking into account ancestors.

+

Parent | Self | isVisible
+visible | visible |
+----------+-----------+------------
+T | T | T
+T | F | F
+F | T | F
+F | F | F

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopeAngle(degrees)

+ + +
+
+ + +
+

get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
degrees + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

kaleidoscopePower(power)

+ + +
+
+ + +
+

get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
power + + +Integer + + + + +

of kaleidoscope

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

levels(level)

+ + +
+
+ + +
+

get/set levels. Must be a number between 0 and 1. Use with Konva.Filters.Posterize filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
level + + +Number + + + + +

between 0 and 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

linearLinearGradientStartPointX(x)

+ + +
+
+ + +
+

get/set stroke linear gradient start point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point x
+var startPointX = shape.strokeLinearGradientStartPointX();
+
+// set stroke linear gradient start point x
+shape.strokeLinearGradientStartPointX(20);
+ + + +
+ + + +
+
+

lineCap(lineCap)

+ + +
+
+ + +
+

get/set line cap. Can be butt, round, or square

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineCap + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line cap
+var lineCap = shape.lineCap();
+
+// set line cap
+shape.lineCap('round');
+ + + +
+ + + +
+
+

lineJoin(lineJoin)

+ + +
+
+ + +
+

get/set line join. Can be miter, round, or bevel. The
+default is miter

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lineJoin + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get line join
+var lineJoin = shape.lineJoin();
+
+// set line join
+shape.lineJoin('round');
+ + + +
+ + + +
+
+

listening(listening)

+ + +
+
+ + +
+

get/set listening attr. If you need to determine if a node is listening or not
+by taking into account its parents, use the isListening() method
+nodes with listening set to false will not be detected in hit graph
+so they will be ignored in container.getIntersection() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
listening + + +Boolean + + + + +

Can be true, or false. The default is true.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get listening attr
+var listening = node.listening();
+
+// stop listening for events, remove node and all its children from hit graph
+node.listening(false);
+
+// listen to events according to the parent
+node.listening(true);
+ + + +
+ + + +
+
+

luminance(value)

+ + +
+
+ + +
+

get/set hsl luminance. Use with Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

from -1 to 1

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

move(change)

+ + +
+
+ + +
+

move node by an amount relative to its current position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
change + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node in x direction by 1px and y direction by 2px
+node.move({
+  x: 1,
+  y: 2
+});
+ + + +
+ + + +
+
+

moveDown()

+ + +
+
+ + +
+

move node down

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveTo(newContainer)

+ + +
+
+ + +
+

move node to another container

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
newContainer + + +Container + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// move node from current layer into layer2
+node.moveTo(layer2);
+ + + +
+ + + +
+
+

moveToBottom()

+ + +
+
+ + +
+

move node to the bottom of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveToTop()

+ + +
+
+ + +
+

move node to the top of its siblings

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

moveUp()

+ + +
+
+ + +
+

move node up

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

flag is moved or not

+
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
+ + + +
+
+

name(name)

+ + +
+
+ + +
+

get/set name.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get name
+var name = node.name();
+
+// set name
+node.name('foo');
+
+// also node may have multiple names (as css classes)
+node.name('foo bar');
+ + + +
+ + + +
+
+

noise(noise)

+ + +
+
+ + +
+

get/set noise amount. Must be a value between 0 and 1. Use with Konva.Filters.Noise filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noise + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

off(evtStr)

+ + +
+
+ + +
+

remove event bindings from the node. Pass in a string of
+event types delimmited by a space to remove multiple event
+bindings at once such as 'mousedown mouseup mousemove'.
+include a namespace to remove an event binding by name
+such as 'click.foobar'. If you only give a name like '.foobar',
+all events in that namespace will be removed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', '.foobar'

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// remove listener
+node.off('click');
+
+// remove multiple listeners
+node.off('click touchstart');
+
+// remove listener by name
+node.off('click.foo');
+ + + +
+ + + +
+
+

offsetX(x)

+ + +
+
+ + +
+

get/set offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset x
+var offsetX = node.offsetX();
+
+// set offset x
+node.offsetX(3);
+ + + +
+ + + +
+
+

offsetY(y)

+ + +
+
+ + +
+

get/set offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get offset y
+var offsetY = node.offsetY();
+
+// set offset y
+node.offsetY(3);
+ + + +
+ + + +
+
+

on(evtStr, handler)

+ + +
+
+ + +
+

bind events to the node. KonvaJS supports mouseover, mousemove,
+mouseout, mouseenter, mouseleave, mousedown, mouseup, wheel, contextmenu, click, dblclick, touchstart, touchmove,
+touchend, tap, dbltap, dragstart, dragmove, and dragend events.
+Pass in a string of events delimited by a space to bind multiple events at once
+such as 'mousedown mouseup mousemove'. Include a namespace to bind an
+event by name such as 'click.foobar'.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
evtStr + + +String + + + + +

e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo'

handler + + +function + + + + +

The handler function. The first argument of that function is event object. Event object has target as main target of the event, currentTarget as current node listener and evt as native browser event.

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
// add click listener
+node.on('click', function() {
+  console.log('you clicked me!');
+});
+
+// get the target node
+node.on('click', function(evt) {
+  console.log(evt.target);
+});
+
+// stop event propagation
+node.on('click', function(evt) {
+  evt.cancelBubble = true;
+});
+
+// bind multiple listeners
+node.on('click touchstart', function() {
+  console.log('you clicked/touched me!');
+});
+
+// namespace listener
+node.on('click.foo', function() {
+  console.log('you clicked/touched me!');
+});
+
+// get the event type
+node.on('click tap', function(evt) {
+  var eventType = evt.type;
+});
+
+// get native event object
+node.on('click tap', function(evt) {
+  var nativeEvent = evt.evt;
+});
+
+// for change events, get the old and new val
+node.on('xChange', function(evt) {
+  var oldVal = evt.oldVal;
+  var newVal = evt.newVal;
+});
+
+// get event targets
+// with event delegations
+layer.on('click', 'Group', function(evt) {
+  var shape = evt.target;
+  var group = evt.currentTarget;
+});
+ + + +
+ + + +
+
+

opacity(opacity)

+ + +
+
+ + +
+

get/set opacity. Opacity values range from 0 to 1.
+A node with an opacity of 0 is fully transparent, and a node
+with an opacity of 1 is fully opaque

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Object + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get opacity
+var opacity = node.opacity();
+
+// set opacity
+node.opacity(0.5);
+ + + +
+ + + +
+
+

perfectDrawEnabled(perfectDrawEnabled)

+ + +
+
+ + +
+

get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set perfectDrawEnabled to false to improve performance.
+See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
perfectDrawEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get perfectDrawEnabled
+var perfectDrawEnabled = shape.perfectDrawEnabled();
+
+// set perfectDrawEnabled
+shape.perfectDrawEnabled();
+ + + +
+ + + +
+
+

pixelSize(pixelSize)

+ + +
+
+ + +
+

get/set pixel size. Use with Konva.Filters.Pixelate filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelSize + + +Integer + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

position(pos)

+ + +
+
+ + +
+

get/set node position relative to parent

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pos + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get position
+var position = node.position();
+
+// set position
+node.position({
+  x: 5,
+  y: 10
+});
+ + + +
+ + + +
+
+

preventDefault(preventDefault)

+ + +
+
+ + +
+

get/set preventDefault
+By default all shapes will prevent default behavior
+of a browser on a pointer move or tap.
+that will prevent native scrolling when you are trying to drag&drop a node
+but sometimes you may need to enable default actions
+in that case you can set the property to false

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preventDefault + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get preventDefault
+var shouldPrevent = shape.preventDefault();
+
+// set preventDefault
+shape.preventDefault(false);
+ + + +
+ + + +
+
+

radius(radius)

+ + +
+
+ + +
+

get/set radius

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
radius + + +Number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get radius
+var radius = wedge.radius();
+
+// set radius
+wedge.radius(10);
+ + + +
+ + + +
+
+

red(red)

+ + +
+
+ + +
+

get/set filter red value. Use with Konva.Filters.RGB filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
red + + +Integer + + + + +

value between 0 and 255

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
+ + + +
+
+

remove()

+ + +
+
+ + +
+

remove a node from parent, but don't destroy. You can reuse the node later.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.remove();
+ + + +
+ + + +
+
+

removeName(name)

+ + +
+
+ + +
+

remove name from node

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.name('red selected');
+node.removeName('selected');
+node.hasName('selected'); // return false
+node.name(); // return 'red'
+ + + +
+ + + +
+
+

rotate(theta)

+ + +
+
+ + +
+

rotate node by an amount in degrees relative to its current rotation

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
theta + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

rotation(rotation)

+ + +
+
+ + +
+

get/set rotation in degrees

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get rotation in degrees
+var rotation = node.rotation();
+
+// set rotation in degrees
+node.rotation(45);
+ + + +
+ + + +
+
+

saturation(saturation)

+ + +
+
+ + +
+

get/set hsv saturation. Use with Konva.Filters.HSV or Konva.Filters.HSL filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
saturation + + +Number + + + + +

0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

scale(scale)

+ + +
+
+ + +
+

get/set scale

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
scale + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get scale
+var scale = node.scale();
+
+// set scale
+shape.scale({
+  x: 2,
+  y: 3
+});
+ + + +
+ + + +
+
+

scaleX(x)

+ + +
+
+ + +
+

get/set scale x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale x
+var scaleX = node.scaleX();
+
+// set scale x
+node.scaleX(2);
+ + + +
+ + + +
+
+

scaleY(y)

+ + +
+
+ + +
+

get/set scale y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get scale y
+var scaleY = node.scaleY();
+
+// set scale y
+node.scaleY(2);
+ + + +
+ + + +
+
+

sceneFunc(drawFunc)

+ + +
+
+ + +
+

get/set scene draw function. That function is used to draw the shape on a canvas.
+Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
drawFunc + + +function + + + + +

drawing function

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +function + + + +
+
+ + + + + +
Example
+ +
// get scene draw function
+var sceneFunc = shape.sceneFunc();
+
+// set scene draw function
+shape.sceneFunc(function(context, shape) {
+  context.beginPath();
+  context.rect(0, 0, shape.width(), shape.height());
+  context.closePath();
+  // important Konva method that fill and stroke shape from its properties
+  // like stroke and fill
+  context.fillStrokeShape(shape);
+});
+ + + +
+ + + +
+
+

setAttr(attr, val)

+ + +
+
+ + +
+

set attr

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attr + + +String + + + + +
val + + +* + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttr('x', 5);
+ + + +
+ + + +
+
+

setAttrs(config)

+ + +
+
+ + +
+

set multiple attrs at once using an object literal

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + +

object containing key value pairs

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
Example
+ +
node.setAttrs({
+  x: 5,
+  fill: 'red'
+});
+ + + +
+ + + +
+
+

shadowBlur(blur)

+ + +
+
+ + +
+

get/set shadow blur

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blur + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow blur
+var shadowBlur = shape.shadowBlur();
+
+// set shadow blur
+shape.shadowBlur(10);
+ + + +
+ + + +
+
+

shadowColor(color)

+ + +
+
+ + +
+

get/set shadow color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get shadow color
+var shadow = shape.shadowColor();
+
+// set shadow color with color string
+shape.shadowColor('green');
+
+// set shadow color with hex
+shape.shadowColor('#00ff00');
+
+// set shadow color with rgb
+shape.shadowColor('rgb(0,255,0)');
+
+// set shadow color with rgba and make it 50% opaque
+shape.shadowColor('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

shadowEnabled(enabled)

+ + +
+
+ + +
+

get/set shadow enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadow enabled flag
+var shadowEnabled = shape.shadowEnabled();
+
+// disable shadow
+shape.shadowEnabled(false);
+
+// enable shadow
+shape.shadowEnabled(true);
+ + + +
+ + + +
+
+

shadowForStrokeEnabled(shadowForStrokeEnabled)

+ + +
+
+ + +
+

get/set shadowForStrokeEnabled. Useful for performance optimization.
+You may set shape.shadowForStrokeEnabled(false). In this case stroke will no effect shadow.
+Remember if you set shadowForStrokeEnabled = false for non closed line - that line will have no shadow!.
+Default value is true

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shadowForStrokeEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get shadowForStrokeEnabled
+var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
+
+// set shadowForStrokeEnabled
+shape.shadowForStrokeEnabled();
+ + + +
+ + + +
+
+

shadowOffset(offset)

+ + +
+
+ + +
+

get/set shadow offset

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
offset + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get shadow offset
+var shadowOffset = shape.shadowOffset();
+
+// set shadow offset
+shape.shadowOffset({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

shadowOffsetX(x)

+ + +
+
+ + +
+

get/set shadow offset x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset x
+var shadowOffsetX = shape.shadowOffsetX();
+
+// set shadow offset x
+shape.shadowOffsetX(5);
+ + + +
+ + + +
+
+

shadowOffsetY(y)

+ + +
+
+ + +
+

get/set shadow offset y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow offset y
+var shadowOffsetY = shape.shadowOffsetY();
+
+// set shadow offset y
+shape.shadowOffsetY(5);
+ + + +
+ + + +
+
+

shadowOpacity(opacity)

+ + +
+
+ + +
+

get/set shadow opacity. must be a value between 0 and 1

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opacity + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get shadow opacity
+var shadowOpacity = shape.shadowOpacity();
+
+// set shadow opacity
+shape.shadowOpacity(0.5);
+ + + +
+ + + +
+
+

show()

+ + +
+
+ + +
+

show node. set visible = true

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Konva.Node + + + +
+
+ + + + + +
+ + + +
+
+

size(size)

+ + +
+
+ + +
+

get/set node size

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
size + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
height + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get node size
+var size = node.size();
+var width = size.width;
+var height = size.height;
+
+// set size
+node.size({
+  width: 100,
+  height: 200
+});
+ + + +
+ + + +
+
+

skew(skew)

+ + +
+
+ + +
+

get/set skew

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
skew + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get skew
+var skew = node.skew();
+
+// set skew
+node.skew({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

skewX(x)

+ + +
+
+ + +
+

get/set skew x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew x
+var skewX = node.skewX();
+
+// set skew x
+node.skewX(3);
+ + + +
+ + + +
+
+

skewY(y)

+ + +
+
+ + +
+

get/set skew y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get skew y
+var skewY = node.skewY();
+
+// set skew y
+node.skewY(3);
+ + + +
+ + + +
+
+

startDrag()

+ + +
+
+ + +
+

initiate drag and drop.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stopDrag()

+ + +
+
+ + +
+

stop drag and drop

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

stroke(color)

+ + +
+
+ + +
+

get/set stroke color

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// get stroke color
+var stroke = shape.stroke();
+
+// set stroke color with color string
+shape.stroke('green');
+
+// set stroke color with hex
+shape.stroke('#00ff00');
+
+// set stroke color with rgb
+shape.stroke('rgb(0,255,0)');
+
+// set stroke color with rgba and make it 50% opaque
+shape.stroke('rgba(0,255,0,0.5');
+ + + +
+ + + +
+
+

strokeEnabled(enabled)

+ + +
+
+ + +
+

get/set stroke enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke enabled flag
+var strokeEnabled = shape.strokeEnabled();
+
+// disable stroke
+shape.strokeEnabled(false);
+
+// enable stroke
+shape.strokeEnabled(true);
+ + + +
+ + + +
+
+

strokeHitEnabled(strokeHitEnabled)

+ + +
+
+ + +
+

deprecated, use hitStrokeWidth instead! get/set strokeHitEnabled property. Useful for performance optimization.
+You may set shape.strokeHitEnabled(false). In this case stroke will be no draw on hit canvas, so hit area
+of shape will be decreased (by lineWidth / 2). Remember that non closed line with strokeHitEnabled = false
+will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
+Default value is true.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeHitEnabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get strokeHitEnabled
+var strokeHitEnabled = shape.strokeHitEnabled();
+
+// set strokeHitEnabled
+shape.strokeHitEnabled();
+ + + +
+ + + +
+
+

strokeLinearGradientColorStops(colorStops)

+ + +
+
+ + +
+

get/set stroke linear gradient color stops

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
colorStops + + +Array + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

colorStops

+
+ + + +
+
+ Type +
+
+ +Array + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient color stops
+var colorStops = shape.strokeLinearGradientColorStops();
+
+// create a linear gradient that starts with red, changes to blue
+// halfway through, and then changes to green
+shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPoint(endPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient end point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
endPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point
+var endPoint = shape.strokeLinearGradientEndPoint();
+
+// set stroke linear gradient end point
+shape.strokeLinearGradientEndPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointX(x)

+ + +
+
+ + +
+

get/set fill linear gradient end point x

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point x
+var endPointX = shape.strokeLinearGradientEndPointX();
+
+// set stroke linear gradient end point x
+shape.strokeLinearGradientEndPointX(20);
+ + + +
+ + + +
+
+

strokeLinearGradientEndPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient end point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient end point y
+var endPointY = shape.strokeLinearGradientEndPointY();
+
+// set stroke linear gradient end point y
+shape.strokeLinearGradientEndPointY(20);
+ + + +
+ + + +
+
+

strokeLinearGradientStartPoint(startPoint)

+ + +
+
+ + +
+

get/set stroke linear gradient start point

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
startPoint + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
y + + +Number + + + + +
+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point
+var startPoint = shape.strokeLinearGradientStartPoint();
+
+// set stroke linear gradient start point
+shape.strokeLinearGradientStartPoint({
+  x: 20,
+  y: 10
+});
+ + + +
+ + + +
+
+

strokeLinearGradientStartPointY(y)

+ + +
+
+ + +
+

get/set stroke linear gradient start point y

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke linear gradient start point y
+var startPointY = shape.strokeLinearGradientStartPointY();
+
+// set stroke linear gradient start point y
+shape.strokeLinearGradientStartPointY(20);
+ + + +
+ + + +
+
+

strokeScaleEnabled(enabled)

+ + +
+
+ + +
+

get/set strokeScale enabled flag

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get stroke scale enabled flag
+var strokeScaleEnabled = shape.strokeScaleEnabled();
+
+// disable stroke scale
+shape.strokeScaleEnabled(false);
+
+// enable stroke scale
+shape.strokeScaleEnabled(true);
+ + + +
+ + + +
+
+

strokeWidth(strokeWidth)

+ + +
+
+ + +
+

get/set stroke width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
strokeWidth + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get stroke width
+var strokeWidth = shape.strokeWidth();
+
+// set stroke width
+shape.strokeWidth(10);
+ + + +
+ + + +
+
+

threshold(threshold)

+ + +
+
+ + +
+

get/set threshold. Must be a value between 0 and 1. Use with Konva.Filters.Threshold or Konva.Filters.Mask filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
threshold + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

to( [params])

+ + +
+
+ + +
+

Tween node properties. Shorter usage of Konva.Tween object.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
params + + +Object + + + + + + + <optional>
+ + + + + +

tween params

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
circle.to({
+  x : 50,
+  duration : 0.5,
+  onUpdate: () => console.log('props updated'),
+  onFinish: () => console.log('finished'),
+});
+ + + +
+ + + +
+
+

toBlob(config)

+ + +
+
+ + +
+

Converts node into a blob. Since the toBlob method is asynchronous,
+the resulting blob can only be retrieved from the config callback
+or the returned Promise.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Blob> + + + +
+
+ + + + + +
Example
+ +
var blob = await node.toBlob({});
+ + + +
+ + + +
+
+

toCanvas(config)

+ + +
+
+ + +
+

converts node into an canvas element.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + + + + +

function executed when the composite has completed

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output canvas. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Example
+ +
var canvas = node.toCanvas();
+ + + +
+ + + +
+
+

toDataURL(config)

+ + +
+
+ + +
+

Creates a composite data URL (base64 string). If MIME type is not
+specified, then "image/png" will result. For "image/jpeg", specify a quality
+level as quality (range 0.0 - 1.0)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image url. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toImage(config)

+ + +
+
+ + +
+

converts node into an image. Since the toImage
+method is asynchronous, the resulting image can only be retrieved from the config callback
+or the returned Promise. toImage is most commonly used
+to cache complex drawings as an image so that they don't have to constantly be redrawn

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDescription
callback + + +function + + + + + + + <optional>
+ + + + + +

function executed when the composite has completed

mimeType + + +String + + + + + + + <optional>
+ + + + + +

can be "image/png" or "image/jpeg".
+"image/png" is the default

x + + +Number + + + + + + + <optional>
+ + + + + +

x position of canvas section

y + + +Number + + + + + + + <optional>
+ + + + + +

y position of canvas section

width + + +Number + + + + + + + <optional>
+ + + + + +

width of canvas section

height + + +Number + + + + + + + <optional>
+ + + + + +

height of canvas section

quality + + +Number + + + + + + + <optional>
+ + + + + +

jpeg quality. If using an "image/jpeg" mimeType,
+you can specify the quality from 0 to 1, where 0 is very poor quality and 1
+is very high quality

pixelRatio + + +Number + + + + + + + <optional>
+ + + + + +

pixelRatio of output image. Default is 1.
+You can use that property to increase quality of the image, for example for super hight quality exports
+or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
+If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.

imageSmoothingEnabled + + +Boolean + + + + + + + <optional>
+ + + + + +

set this to false if you want to disable imageSmoothing

+ +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Image> + + + +
+
+ + + + + +
Example
+ +
var image = node.toImage({
+  callback(img) {
+    // do stuff with img
+  }
+});
+ + + +
+ + + +
+
+

toJSON()

+ + +
+
+ + +
+

convert Node into a JSON string. Returns a JSON string.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
+ + + +
+
+

toObject()

+ + +
+
+ + +
+

convert Node into an object for serialization. Returns an object.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
+ + + +
+
+

transformsEnabled(enabled)

+ + +
+
+ + +
+

get/set transforms that are enabled. Can be "all", "none", or "position". The default
+is "all"

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +String + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + +
Example
+ +
// enable position transform only to improve draw performance
+node.transformsEnabled('position');
+
+// enable all transforms
+node.transformsEnabled('all');
+ + + +
+ + + +
+
+

value(value)

+ + +
+
+ + +
+

get/set hsv value. Use with Konva.Filters.HSV filter.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
value + + +Number + + + + +

0 is no change, -1.0 halves the value, 1.0 doubles, etc..

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
+ + + +
+
+

visible(visible)

+ + +
+
+ + +
+

get/set visible attr. Can be true, or false. The default is true.
+If you need to determine if a node is visible or not
+by taking into account its parents, use the isVisible() method

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
visible + + +Boolean + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + +
Example
+ +
// get visible attr
+var visible = node.visible();
+
+// make invisible
+node.visible(false);
+
+// make visible (according to the parent)
+node.visible(true);
+ + + +
+ + + +
+
+

width(width)

+ + +
+
+ + +
+

get/set width

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
width + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get width
+var width = node.width();
+
+// set width
+node.width(100);
+ + + +
+ + + +
+
+

x(x)

+ + +
+
+ + +
+

get/set x position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + +
Example
+ +
// get x
+var x = node.x();
+
+// set x
+node.x(5);
+ + + +
+ + + +
+
+

y(y)

+ + +
+
+ + +
+

get/set y position

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
y + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Integer + + + +
+
+ + + + + +
Example
+ +
// get y
+var y = node.y();
+
+// set y
+node.y(5);
+ + + +
+ + + +
+
+

zIndex(index)

+ + +
+
+ + +
+

get/set zIndex relative to the node's siblings who share the same parent.
+Please remember that zIndex is not absolute (like in CSS). It is relative to parent element only.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
index + + +Number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Number + + + +
+
+ + + + + +
Example
+ +
// get index
+var index = node.zIndex();
+
+// set index
+node.zIndex(2);
+ + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/Konva.html b/api/Konva.html new file mode 100644 index 000000000..627851ab4 --- /dev/null +++ b/api/Konva.html @@ -0,0 +1,1795 @@ + + + + + + + Konva Namespace: Konva + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Namespace: Konva

+
+ +
+ +

+ Konva +

+ + +
+ + +
+
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + +
+ + + + + + +

Classes

+ +
+
Animation
+
+ +
Arc
+
+ +
Arrow
+
+ +
Canvas
+
+ +
Circle
+
+ +
Container
+
+ +
Context
+
+ +
Ellipse
+
+ +
FastLayer
+
+ +
Group
+
+ +
Image
+
+ +
Label
+
+ +
Layer
+
+ +
Line
+
+ +
Node
+
+ +
Path
+
+ +
Rect
+
+ +
RegularPolygon
+
+ +
Ring
+
+ +
Shape
+
+ +
Sprite
+
+ +
Stage
+
+ +
Star
+
+ +
Tag
+
+ +
Text
+
+ +
TextPath
+
+ +
Transform
+
+ +
Transformer
+
+ +
Tween
+
+ +
Wedge
+
+
+ + + + + +

Namespaces

+ +
+
Easings
+
+ +
Filters
+
+ +
Util
+
+
+ + + +

Members

+ +
+ +
+
+

<static> angleDeg

+ + +
+
+ +
+

Use degree values for angle properties. You may set this property to false if you want to use radian values.

+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
angleDeg + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
+
    +
  • true
  • +
+
+ + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + +
Example
+ +
node.rotation(45); // 45 degrees
+Konva.angleDeg = false;
+node.rotation(Math.PI / 2); // PI/2 radian
+ + + +
+ + + +
+
+

<static> autoDrawEnabled

+ + +
+
+ +
+

Should Konva automatically update canvas on any changes. Default is true.

+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
autoDrawEnabled + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
+
    +
  • true
  • +
+
+ + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + +
Example
+ +
Konva.autoDrawEnabled = true;
+ + + +
+ + + +
+
+

<static> capturePointerEventsEnabled

+ + +
+
+ +
+

Should we capture touch events and bind them to the touchstart target? That is how it works on DOM elements.
+The case: we touchstart on div1, then touchmove out of that element into another element div2.
+DOM will continue trigger touchmove events on div1 (not div2). Because events are "captured" into initial target.
+By default Konva do not do that and will trigger touchmove on another element, while pointer is moving.

+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
capturePointerEventsEnabled + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
+
    +
  • false
  • +
+
+ + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + +
Example
+ +
Konva.capturePointerEventsEnabled = true;
+ + + +
+ + + +
+
+

<static> dragButtons

+ + +
+
+ +
+

Configure what mouse buttons can be used for drag and drop.
+Default value is [0] - only left mouse button.

+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragButtons + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
+
    +
  • true
  • +
+
+ + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + +
Example
+ +
// enable left and right mouse buttons
+Konva.dragButtons = [0, 2];
+ + + +
+ + + +
+
+

<static> dragDistance

+ + +
+
+ +
+

Drag distance property. If you start to drag a node you may want to wait until pointer is moved to some distance from start point,
+only then start dragging. Default is 3px.

+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dragDistance + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
+
    +
  • 0
  • +
+
+ + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + +
Example
+ +
Konva.dragDistance = 10;
+ + + +
+ + + +
+
+

<static> hitOnDragEnabled

+ + +
+
+ +
+

Should we enable hit detection while dragging? For performance reasons, by default it is false.
+But on some rare cases you want to see hit graph and check intersections. Just set it to true.

+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hitOnDragEnabled + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
+
    +
  • false
  • +
+
+ + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + +
Example
+ +
Konva.hitOnDragEnabled = true;
+ + + +
+ + + +
+
+

<static> pixelRatio

+ + +
+
+ +
+

Global pixel ratio configuration. KonvaJS automatically detect pixel ratio of current device.
+But you may override such property, if you want to use your value. Set this value before any components initializations.

+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pixelRatio + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
+
    +
  • undefined
  • +
+
+ + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + +
Example
+ +
// before any Konva code:
+Konva.pixelRatio = 1;
+ + + +
+ + + +
+
+

<static> releaseCanvasOnDestroy

+ + +
+
+ +
+

Should Konva release canvas elements on destroy. Default is true.
+Useful to avoid memory leak issues in Safari on macOS/iOS.

+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
releaseCanvasOnDestroy + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
+
    +
  • true
  • +
+
+ + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + +
Example
+ +
Konva.releaseCanvasOnDestroy = true;
+ + + +
+ + + +
+
+

<static> showWarnings

+ + +
+
+ +
+

Show different warnings about errors or wrong API usage

+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
showWarnings + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
+
    +
  • true
  • +
+
+ + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + +
Example
+ +
Konva.showWarnings = false;
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+
+

<static> isDragging()

+ + +
+
+ + +
+

returns whether or not drag and drop is currently active

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

<static> isDragReady()

+ + +
+
+ + +
+

returns whether or not a drag and drop operation is ready, but may
+not necessarily have started

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ konva.js +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/classes.list.html b/api/classes.list.html new file mode 100644 index 000000000..2fdab5ea1 --- /dev/null +++ b/api/classes.list.html @@ -0,0 +1,481 @@ + + + + + + + Konva Classes + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Classes

+
+ +
+ +

+ +

+ + +
+ + +
+
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + +

Classes

+ +
+
Animation
+
+ +
Arc
+
+ +
Arrow
+
+ +
Canvas
+
+ +
Circle
+
+ +
Container
+
+ +
Context
+
+ +
Ellipse
+
+ +
FastLayer
+
+ +
Group
+
+ +
Image
+
+ +
Label
+
+ +
Layer
+
+ +
Line
+
+ +
Node
+
+ +
Path
+
+ +
Rect
+
+ +
RegularPolygon
+
+ +
Ring
+
+ +
Shape
+
+ +
Sprite
+
+ +
Stage
+
+ +
Star
+
+ +
Tag
+
+ +
Text
+
+ +
TextPath
+
+ +
Transform
+
+ +
Transformer
+
+ +
Tween
+
+ +
Wedge
+
+
+ + + + + +

Namespaces

+ +
+
Konva
+
+ +
Easings
+
+ +
Filters
+
+ +
Util
+
+
+ + + + + + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/fonts/glyphicons-halflings-regular.eot b/api/fonts/glyphicons-halflings-regular.eot new file mode 100644 index 000000000..b93a4953f Binary files /dev/null and b/api/fonts/glyphicons-halflings-regular.eot differ diff --git a/api/fonts/glyphicons-halflings-regular.svg b/api/fonts/glyphicons-halflings-regular.svg new file mode 100644 index 000000000..94fb5490a --- /dev/null +++ b/api/fonts/glyphicons-halflings-regular.svg @@ -0,0 +1,288 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/fonts/glyphicons-halflings-regular.ttf b/api/fonts/glyphicons-halflings-regular.ttf new file mode 100644 index 000000000..1413fc609 Binary files /dev/null and b/api/fonts/glyphicons-halflings-regular.ttf differ diff --git a/api/fonts/glyphicons-halflings-regular.woff b/api/fonts/glyphicons-halflings-regular.woff new file mode 100644 index 000000000..9e612858f Binary files /dev/null and b/api/fonts/glyphicons-halflings-regular.woff differ diff --git a/api/fonts/glyphicons-halflings-regular.woff2 b/api/fonts/glyphicons-halflings-regular.woff2 new file mode 100644 index 000000000..64539b54c Binary files /dev/null and b/api/fonts/glyphicons-halflings-regular.woff2 differ diff --git a/api/img/glyphicons-halflings-white.png b/api/img/glyphicons-halflings-white.png new file mode 100644 index 000000000..3bf6484a2 Binary files /dev/null and b/api/img/glyphicons-halflings-white.png differ diff --git a/api/img/glyphicons-halflings.png b/api/img/glyphicons-halflings.png new file mode 100644 index 000000000..a99699932 Binary files /dev/null and b/api/img/glyphicons-halflings.png differ diff --git a/api/index.html b/api/index.html new file mode 100644 index 000000000..218f90584 --- /dev/null +++ b/api/index.html @@ -0,0 +1,464 @@ + + + + + + + Konva Index + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + +
+

+ Konva logo +

+

Konva

+

Financial Contributors on Open Collective
+npm version
+Build Status
+Build StatusCDNJS version

+

Konva is an HTML5 Canvas JavaScript framework that enables high performance animations, transitions, node nesting, layering, filtering, caching, event handling for desktop and mobile applications, and much more.

+

You can draw things onto the stage, add event listeners to them, move them, scale them, and rotate them independently from other shapes to support high performance animations, even if your application uses thousands of shapes. Served hot with a side of awesomeness.

+

This repository began as a GitHub fork of ericdrowell/KineticJS.

+ +

Quick Look

+
<script src="https://unpkg.com/konva@9/konva.min.js"></script>
+<div id="container"></div>
+<script>
+  var stage = new Konva.Stage({
+    container: 'container',
+    width: window.innerWidth,
+    height: window.innerHeight,
+  });
+
+  // add canvas element
+  var layer = new Konva.Layer();
+  stage.add(layer);
+
+  // create shape
+  var box = new Konva.Rect({
+    x: 50,
+    y: 50,
+    width: 100,
+    height: 50,
+    fill: '#00D2FF',
+    stroke: 'black',
+    strokeWidth: 4,
+    draggable: true,
+  });
+  layer.add(box);
+
+  // add cursor styling
+  box.on('mouseover', function () {
+    document.body.style.cursor = 'pointer';
+  });
+  box.on('mouseout', function () {
+    document.body.style.cursor = 'default';
+  });
+</script>
+
+

Browsers support

+

Konva works in all modern mobile and desktop browsers. A browser need to be capable to run javascript code from ES2015 spec. For older browsers you may need polyfills for missing functions.

+

At the current moment Konva doesn't work in IE11 directly. To make it work you just need to provide some polyfills such as Array.prototype.find, String.prototype.trimLeft, String.prototype.trimRight, Array.from.

+

Debugging

+

The Chrome inspector simply shows the canvas element. To see the Konva objects and their details, install the konva-dev extension at https://github.com/konvajs/konva-devtool.

+

Loading and installing Konva

+

Konva supports UMD loading. So you can use all possible variants to load the framework into your project:

+

Load Konva via classical <script> tag from CDN:

+
<script src="https://unpkg.com/konva@9/konva.min.js"></script>
+
+

Install with npm:

+
npm install konva --save
+
+
// The modern way (e.g. an ES6-style import for webpack, parcel)
+import Konva from 'konva';
+
+

Typescript usage

+

Add DOM definitions into your tsconfig.json:

+
{
+  "compilerOptions": {
+    "lib": [
+        "es6",
+        "dom"
+    ]
+  }
+}
+
+

3 Minimal bundle

+
import Konva from 'konva/lib/Core';
+// Now you have a Konva object with Stage, Layer, FastLayer, Group, Shape and some additional utils function.
+// Also core currently already have support for drag&drop and animations.
+// BUT there are no shapes (rect, circle, etc), no filters.
+
+// but you can simply add anything you need:
+import { Rect } from 'konva/lib/shapes/Rect';
+// importing a shape will automatically inject it into Konva object
+
+var rect1 = new Rect();
+// or:
+var shape = new Konva.Rect();
+
+// for filters you can use this:
+import { Blur } from 'konva/lib/filters/Blur';
+
+

4 NodeJS env

+

In order to run konva in nodejs environment you also need to install canvas package manually. Konva will use it for 2d canvas API.

+
npm install konva canvas
+
+

Then you can use the same Konva API and all Konva demos will work just fine. You just don't need to use container attribute in your stage.

+
import Konva from 'konva';
+
+const stage = new Konva.Stage({
+  width: 500,
+  height: 500,
+});
+// then all regular Konva code will work
+
+

Backers

+

https://simpleshow.com
+https://www.notably.ai/

+ +

Change log

+

See CHANGELOG.md.

+

Building the Konva Framework

+

To make a full build run npm run build. The command will compile all typescript files, combine then into one bundle and run minifier.

+

Testing

+

Konva uses Mocha for testing.

+
    +
  • If you need run test only one time run npm run test.
  • +
  • While developing it is easy to use npm start. Just run it and go to http://localhost:1234/unit-tests.html. The watcher will rebuild the bundle on any change.
  • +
+

Konva is covered with hundreds of tests and well over a thousand assertions.
+Konva uses TDD (test driven development) which means that every new feature or bug fix is accompanied with at least one new test.

+

Generate documentation

+

Run npx gulp api which will build the documentation files and place them in the api folder.

+

Pull Requests

+

I'd be happy to review any pull requests that may better the Konva project,
+in particular if you have a bug fix, enhancement, or a new shape (see src/shapes for examples). Before doing so, please first make sure that all of the tests pass (npm run test).

+

Contributors

+

Financial Contributors

+

Become a financial contributor and help us sustain our community. [Contribute]

+

Individuals

+

+

Organizations

+

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

+


+
+
+
+
+
+
+
+
+

+
+ + + + + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/namespaces.list.html b/api/namespaces.list.html new file mode 100644 index 000000000..a85162bf4 --- /dev/null +++ b/api/namespaces.list.html @@ -0,0 +1,481 @@ + + + + + + + Konva Namespaces + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Namespaces

+
+ +
+ +

+ +

+ + +
+ + +
+
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + +

Classes

+ +
+
Animation
+
+ +
Arc
+
+ +
Arrow
+
+ +
Canvas
+
+ +
Circle
+
+ +
Container
+
+ +
Context
+
+ +
Ellipse
+
+ +
FastLayer
+
+ +
Group
+
+ +
Image
+
+ +
Label
+
+ +
Layer
+
+ +
Line
+
+ +
Node
+
+ +
Path
+
+ +
Rect
+
+ +
RegularPolygon
+
+ +
Ring
+
+ +
Shape
+
+ +
Sprite
+
+ +
Stage
+
+ +
Star
+
+ +
Tag
+
+ +
Text
+
+ +
TextPath
+
+ +
Transform
+
+ +
Transformer
+
+ +
Tween
+
+ +
Wedge
+
+
+ + + + + +

Namespaces

+ +
+
Konva
+
+ +
Easings
+
+ +
Filters
+
+ +
Util
+
+
+ + + + + + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/quicksearch.html b/api/quicksearch.html new file mode 100644 index 000000000..6917ef83a --- /dev/null +++ b/api/quicksearch.html @@ -0,0 +1,31 @@ + + + + + + + + + + + + + diff --git a/api/scripts/docstrap.lib.js b/api/scripts/docstrap.lib.js new file mode 100644 index 000000000..09d9272a0 --- /dev/null +++ b/api/scripts/docstrap.lib.js @@ -0,0 +1,11 @@ +if(!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){function c(a){var b="length"in a&&a.length,c=_.type(a);return"function"!==c&&!_.isWindow(a)&&(!(1!==a.nodeType||!b)||("array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a))}function d(a,b,c){if(_.isFunction(b))return _.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return _.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(ha.test(b))return _.filter(b,a,c);b=_.filter(b,a)}return _.grep(a,function(a){return U.call(b,a)>=0!==c})}function e(a,b){for(;(a=a[b])&&1!==a.nodeType;);return a}function f(a){var b=oa[a]={};return _.each(a.match(na)||[],function(a,c){b[c]=!0}),b}function g(){Z.removeEventListener("DOMContentLoaded",g,!1),a.removeEventListener("load",g,!1),_.ready()}function h(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=_.expando+h.uid++}function i(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(ua,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c||"false"!==c&&("null"===c?null:+c+""===c?+c:ta.test(c)?_.parseJSON(c):c)}catch(a){}sa.set(a,b,c)}else c=void 0;return c}function j(){return!0}function k(){return!1}function l(){try{return Z.activeElement}catch(a){}}function m(a,b){return _.nodeName(a,"table")&&_.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function n(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function o(a){var b=Ka.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function p(a,b){for(var c=0,d=a.length;d>c;c++)ra.set(a[c],"globalEval",!b||ra.get(b[c],"globalEval"))}function q(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(ra.hasData(a)&&(f=ra.access(a),g=ra.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)_.event.add(b,e,j[e][c])}sa.hasData(a)&&(h=sa.access(a),i=_.extend({},h),sa.set(b,i))}}function r(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&_.nodeName(a,b)?_.merge([a],c):c}function s(a,b){var c=b.nodeName.toLowerCase();"input"===c&&ya.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}function t(b,c){var d,e=_(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:_.css(e[0],"display");return e.detach(),f}function u(a){var b=Z,c=Oa[a];return c||(c=t(a,b),"none"!==c&&c||(Na=(Na||_(" --> + + + + + + + + +
+
+ +
+ + + + +

To create custom animations with Konva, we can use the Konva.Animation
constructor which takes two arguments, the required update function and
an optional layer, or array of layers, that will be updated with each animation frame.
The animation function is passed a frame object which contains a time property which is the number
of milliseconds that the animation has been running, a timeDiff property which
is the number of milliseconds that have passed since the last frame,
and a frameRate property which is the current frame rate in frames per second.

+

The update function should never redraw the stage or a layer because the animation
engine will intelligently handle that for us.
The update function should only contain logic that updates Node properties,
such as position, rotation, scale, width, height, radius, colors, etc.
Once the animation has been created, we can start it at anytime with the start() method.

+

For a full list of attributes and methods, check out the Konva.Animation documentation.

+

HTML5 Canvas Konva Animation Template

<script>
var anim = new Konva.Animation(function(frame) {
var time = frame.time,
timeDiff = frame.timeDiff,
frameRate = frame.frameRate;

// update stuff
}, layer);

anim.start();
</script>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/animations/Moving.html b/docs/animations/Moving.html new file mode 100644 index 000000000..c70418101 --- /dev/null +++ b/docs/animations/Moving.html @@ -0,0 +1,723 @@ + + + + + + Animate Position Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Animate Position Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

How to animate movement with Konva?

To animate a shape’s position with Konva, we can create a new animation with Konva.Animation
which modifies the shape’s position with each animation frame.

+

For a full list of attributes and methods, check out the Konva.Animation documentation.

+ + +
Konva Animate Position Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Animate Position Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var hexagon = new Konva.RegularPolygon({
x: stage.width() / 2,
y: stage.height() / 2,
sides: 6,
radius: 20,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

layer.add(hexagon);
stage.add(layer);

var amplitude = 100;
var period = 2000;
// in ms
var centerX = stage.width() / 2;

var anim = new Konva.Animation(function (frame) {
hexagon.x(
amplitude * Math.sin((frame.time * 2 * Math.PI) / period) + centerX
);
}, layer);

anim.start();
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/animations/Rotation.html b/docs/animations/Rotation.html new file mode 100644 index 000000000..6538ce3da --- /dev/null +++ b/docs/animations/Rotation.html @@ -0,0 +1,724 @@ + + + + + + Rotation Animation tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Rotation Animation tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

How to animation shape rotation?

To animate a shape’s rotation with Konva, we can create a new animation with
Konva.Animation, and define a function which modifies the shape’s rotation with each animation frame.

+

In this tutorial, we’ll rotate a blue rectangle about the top left corner,
a yellow rectangle about its center, and a red rectangle about an outside point.

+

For a full list of attributes and methods, check out the Konva.Animation documentation.

+ + +
Konva Rotation Animation Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Rotation Animation Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

/*
* leave center point positioned
* at the default which is the top left
* corner of the rectangle
*/

var blueRect = new Konva.Rect({
x: 50,
y: 75,
width: 100,
height: 50,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
});

/*
* move center point to the center
* of the rectangle with offset
*/
var yellowRect = new Konva.Rect({
x: 220,
y: 75,
width: 100,
height: 50,
fill: 'yellow',
stroke: 'black',
strokeWidth: 4,
offset: {
x: 50,
y: 25,
},
});

/*
* move center point outside of the rectangle
* with offset
*/

var redRect = new Konva.Rect({
x: 400,
y: 75,
width: 100,
height: 50,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
offset: {
x: -100,
y: 0,
},
});

layer.add(blueRect);
layer.add(yellowRect);
layer.add(redRect);
stage.add(layer);

// one revolution per 4 seconds
var angularSpeed = 90;
var anim = new Konva.Animation(function (frame) {
var angleDiff = (frame.timeDiff * angularSpeed) / 1000;
blueRect.rotate(angleDiff);
yellowRect.rotate(angleDiff);
redRect.rotate(angleDiff);
}, layer);

anim.start();
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/animations/Scaling.html b/docs/animations/Scaling.html new file mode 100644 index 000000000..b0247867d --- /dev/null +++ b/docs/animations/Scaling.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Konva Scale Animation Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Konva Scale Animation Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To animate a shape’s scale with Konva, we can create a new animation with
Konva.Animation, and define a function which modifies the shape’s scale with each animation frame.

+

In this tutorial, we’ll scale the x and y component of a blue hexagon, the y component
of a yellow hexagon, and the x component of a red hexagon about an axis positioned on the right side of the shape.

+

Instructions: drag and drop the hexagons as they animate

+

For a full list of attributes and methods, check out the Konva.Animation documentation.

+ + +
Konva Scale Animation Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Scale Animation Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

/*
* leave center point positioned
* at the default which is at the center
* of the hexagon
*/
var blueHex = new Konva.RegularPolygon({
x: 50,
y: stage.height() / 2,
sides: 6,
radius: 40,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
draggable: true,
});

var yellowHex = new Konva.RegularPolygon({
x: 150,
y: stage.height() / 2,
sides: 6,
radius: 50,
fill: 'yellow',
stroke: 'black',
strokeWidth: 4,
draggable: true,
});

/*
* move center point to right side
* of hexagon
*/
var redHex = new Konva.RegularPolygon({
x: 300,
y: stage.height() / 2,
sides: 6,
radius: 50,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
offset: {
x: 50,
y: 0,
},
draggable: true,
});

layer.add(blueHex);
layer.add(yellowHex);
layer.add(redHex);
stage.add(layer);

var period = 2000;

var anim = new Konva.Animation(function (frame) {
var scale = Math.sin((frame.time * 2 * Math.PI) / period) + 0.001;
// scale x and y
blueHex.scale({ x: scale, y: scale });
// scale only y
yellowHex.scaleY(scale);
// scale only x
redHex.scaleX(scale);
}, layer);

anim.start();
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/animations/Stop_Animation.html b/docs/animations/Stop_Animation.html new file mode 100644 index 000000000..39ad5ca26 --- /dev/null +++ b/docs/animations/Stop_Animation.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Konva Stop Animation Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Konva Stop Animation Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To stop an animation with Konva, we can use the stop() method.
To restart the animation, we can again call the start().

+

Instructions: Click on “Start” to start the animation and “Stop” to stop the animation.

+

For a full list of attributes and methods, check out the Konva.Animation documentation.

+ + +
Konva Stop Animation Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Stop Animation Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
#buttons {
position: absolute;
top: 5px;
left: 10px;
}
#buttons > input {
padding: 10px;
display: block;
margin-top: 5px;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="buttons">
<input type="button" id="start" value="Start" />
<input type="button" id="stop" value="Stop" />
</div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
var hexagon = new Konva.RegularPolygon({
x: stage.width() / 2,
y: stage.height() / 2,
sides: 6,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

layer.add(hexagon);
stage.add(layer);

var amplitude = 150;
// in ms
var period = 2000;
var centerX = stage.width() / 2;

var anim = new Konva.Animation(function (frame) {
hexagon.x(
amplitude * Math.sin((frame.time * 2 * Math.PI) / period) + centerX
);
}, layer);

document.getElementById('start').addEventListener(
'click',
function () {
anim.start();
},
false
);

document.getElementById('stop').addEventListener(
'click',
function () {
anim.stop();
},
false
);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/clipping/Clipping_Function.html b/docs/clipping/Clipping_Function.html new file mode 100644 index 000000000..3ca37a98c --- /dev/null +++ b/docs/clipping/Clipping_Function.html @@ -0,0 +1,723 @@ + + + + + + Clipping Functions Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Clipping Functions Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

How to clip nodes in the layer?

To draw things inside of complex clipping regions with Konva, we can set the clipFunc
property of a group, a layer.
In this tutorial, we’ll draw blobs inside of a two circles clipping region applied to a group.

+ + +
Konva Clipping Functions Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Clipping Function Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var group = new Konva.Group({
clipFunc: function (ctx) {
ctx.arc(250, 120, 50, 0, Math.PI * 2, false);
ctx.arc(150, 120, 60, 0, Math.PI * 2, false);
},
draggable: true,
});

var blueBlob = new Konva.Line({
points: [73, 140, 340, 23, 500, 109, 300, 170],
stroke: 'blue',
strokeWidth: 10,
fill: '#aaf',
tension: 0.8,
closed: true,
});

var redBlob = new Konva.Line({
points: [73, 140, 340, 23, 500, 109],
stroke: 'red',
strokeWidth: 10,
fill: '#faa',
tension: 1.2,
scale: { x: 0.5, y: 0.5 },
x: 100,
y: 50,
closed: true,
});

group.add(blueBlob);
group.add(redBlob);
layer.add(group);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/clipping/Clipping_Regions.html b/docs/clipping/Clipping_Regions.html new file mode 100644 index 000000000..bb244a1a1 --- /dev/null +++ b/docs/clipping/Clipping_Regions.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Simple Clipping tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Simple Clipping tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To draw things inside of clipping regions with Konva, we can set the clip
property of a group or a layer.
Clipping regions are defined by an x, y, width, and height. In this tutorial,
we’ll draw blobs inside of a rectangular clipping region applied to a group.

+

For more complex cases take a look into clipping function. Clipping Function

+ + +
Konva Simple Clipping Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Simple Clipping Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var group = new Konva.Group({
clip: {
x: 100,
y: 40,
width: 200,
height: 100,
},
draggable: true,
});

var blueBlob = new Konva.Line({
points: [73, 140, 340, 23, 500, 109, 300, 170],
stroke: 'blue',
strokeWidth: 10,
fill: '#aaf',
tension: 0.8,
closed: true,
});

var redBlob = new Konva.Line({
points: [73, 140, 340, 23, 500, 109],
stroke: 'red',
strokeWidth: 10,
fill: '#faa',
tension: 1.2,
scale: { x: 0.5, y: 0.5 },
x: 100,
y: 50,
closed: true,
});

group.add(blueBlob);
group.add(redBlob);
layer.add(group);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/data_and_serialization/Best_Practices.html b/docs/data_and_serialization/Best_Practices.html new file mode 100644 index 000000000..7f4df6cb8 --- /dev/null +++ b/docs/data_and_serialization/Best_Practices.html @@ -0,0 +1,741 @@ + + + + + + Save and Load HTML5 Canvas Stage Best Practices | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Save and Load HTML5 Canvas Stage Best Practices

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

What is the best way to save/load full stage content and how to implement undo/redo?

If you want to save/load simple canvas content you can use the built-in Konva methods: node.toJSON() and Node.create(json).
See simple and complex demos.

+

But those methods are useful only in very small apps. In bigger apps it is VERY hard to use those methods. Why? Because the tree structure is usually very complex in larger apps, you may have a lot of event listeners, images, filters, etc. That data is not serializable into JSON (or it is very hard to do that).

+

Also it is very common that nodes in a tree have a lot information that is not directly related to the state of your app, but just used to describe visual view of your app.

+

For instance, let’s think we have a game, that draws several balls in canvas. The balls are not just circles, but the complex visual groups of objects with shadows and texts inside them (like “Made in China”). Now let’s think you want to serialize state of your app and use it somewhere else. Like send to another computer or implement undo/redo. Almost all the visual information (shadows, texts, sizes) is not critical and may be you don’t need to save it. Because all balls have the same shadows, sizes, etc. But what is critical? In that case it is just a number of balls and their coordinates. You need to save/load only that information. It will be just a simple array:

+
var state = [{x: 10, y: 10}, { x: 160, y: 1041}]
+ +

Now when you have that information, you need to have a function, that can create the whole canvas structure.
If you want to update your canvas, for instance, you want to create a new ball, you don’t need to create a new canvas node directly (like creating new instance of Konva.Circle), you just need to push a new object into a state and update (or recreate) canvas.

+

In that case you don’t need to care about image loading, filters, event listeners, etc in saving/loading phases. Because you do all these actions in your create or update functions.

+

You would better understand what I am talking about if you know how many modern frameworks work (like React, Vue, Angular and many other).

+

Also take a look into these demos to have a better idea:

+
    +
  1. Undo/redo with react
  2. +
  3. Save/load with Vue
  4. +
+

How to implement that create and update functions? It depends. From my point of view it will be easier to use frameworks that can do that job for you, like react-konva.

+

If you don’t want to use such frameworks you need to think in terms of your own app. Here I will try to make a small demo to give you an idea.

+

The super naive method is to implement just one function create(state) that will do all the complex job of loading.
If you have some changes in your app you just need to destroy the canvas and create a new one. But the drawback of such approach is possibly a bad performance.

+

A bit smarter implementation is to create two functions create(state) and update(state). create will make instances of all required objects, attach events and load images. update will update properties of nodes. If number of objects is changed - destroy all and create from scratch. If only some properties changed - call update.

+

Instructions: In that demo we will have a bunch of images with filters, and you can add more, move them, apply a new filter by clicking on images and use undo/redo.

+ + +
Konva Load Complex Stage Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Load Complex Stage Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<button id="create-yoda">Create yoda</button>
<button id="create-darth">Create darth</button>
<button id="undo">Undo</button>
<button id="redo">Redo</button>
<div id="container"></div>
<script>
var possibleFilters = ['', 'blur', 'invert'];

function createObject(attrs) {
return Object.assign({}, attrs, {
// define position
x: 0,
y: 0,
// here should be url to image
src: '',
// and define filter on it, let's define that we can have only
// "blur", "invert" or "" (none)
filter: 'blur',
});
}
function createYoda(attrs) {
return Object.assign(createObject(attrs), {
src: '/assets/yoda.jpg',
});
}

function createDarth(attrs) {
return Object.assign(createObject(attrs), {
src: '/assets/darth-vader.jpg',
});
}

// initial state
var state = [createYoda({ x: 50, y: 50 })];

// our history
var appHistory = [state];
var appHistoryStep = 0;

var width = window.innerWidth;
var height = window.innerHeight;
var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

// create function will destroy previous drawing
// then it will created required nodes and attach all events
function create() {
layer.destroyChildren();
state.forEach((item, index) => {
var node = new Konva.Image({
draggable: true,
name: 'item-' + index,
// make it smaller
scaleX: 0.5,
scaleY: 0.5,
});
layer.add(node);
node.on('dragend', () => {
// make new state
state = state.slice();
// update object data
state[index] = Object.assign({}, state[index], {
x: node.x(),
y: node.y(),
});
// save it into history
saveStateToHistory(state);
// don't need to call update here
// because changes already in node
});

node.on('click', () => {
// find new filter
var oldFilterIndex = possibleFilters.indexOf(state[index].filter);
var nextIndex = (oldFilterIndex + 1) % possibleFilters.length;
var filter = possibleFilters[nextIndex];

// apply state changes
state = state.slice();
state[index] = Object.assign({}, state[index], {
filter: filter,
});
// save state to history
saveStateToHistory(state);
// update canvas from state
update(state);
});

var img = new window.Image();
img.onload = function () {
node.image(img);
update(state);
};
img.src = item.src;
});
update(state);
}

function update() {
state.forEach(function (item, index) {
var node = stage.findOne('.item-' + index);
node.setAttrs({
x: item.x,
y: item.y,
});

if (!node.image()) {
return;
}
if (item.filter === 'blur') {
node.filters([Konva.Filters.Blur]);
node.blurRadius(10);
node.cache();
} else if (item.filter === 'invert') {
node.filters([Konva.Filters.Invert]);
node.cache();
} else {
node.filters([]);
node.clearCache();
}
});
}

//
function saveStateToHistory(state) {
appHistory = appHistory.slice(0, appHistoryStep + 1);
appHistory = appHistory.concat([state]);
appHistoryStep += 1;
}
create(state);

document
.querySelector('#create-yoda')
.addEventListener('click', function () {
// create new object
state.push(
createYoda({
x: width * Math.random(),
y: height * Math.random(),
})
);
// recreate canvas
create(state);
});

document
.querySelector('#create-darth')
.addEventListener('click', function () {
// create new object
state.push(
createDarth({
x: width * Math.random(),
y: height * Math.random(),
})
);
// recreate canvas
create(state);
});

document.querySelector('#undo').addEventListener('click', function () {
if (appHistoryStep === 0) {
return;
}
appHistoryStep -= 1;
state = appHistory[appHistoryStep];
// create everything from scratch
create(state);
});

document.querySelector('#redo').addEventListener('click', function () {
if (appHistoryStep === appHistory.length - 1) {
return;
}
appHistoryStep += 1;
state = appHistory[appHistoryStep];
// create everything from scratch
create(state);
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/data_and_serialization/Complex_Load.html b/docs/data_and_serialization/Complex_Load.html new file mode 100644 index 000000000..ce3167080 --- /dev/null +++ b/docs/data_and_serialization/Complex_Load.html @@ -0,0 +1,724 @@ + + + + + + Load HTML5 Canvas Stage from JSON Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Load HTML5 Canvas Stage from JSON Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

How to import canvas from JSON?

To load a complex stage that originally contained images and event bindings using Konva,
we need to create a stage node using Konva.Node.create(), and then set the
images and event handlers with the help of selectors using the find() method.
Images and event handlers must be manually set because they aren’t serializable.

+

That methods works for small apps. For more complex cases take a look into Best Practices

+ + +
Konva Load Complex Stage Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Load Complex Stage Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var json =
'{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{"width":"auto","height":"auto","text":"Text Shadow!","fontFamily":"Calibri","fontSize":95,"x":20,"y":20,"stroke":"red","strokeWidth":2,"shadowColor":"black","shadowBlur":2,"shadowOffsetX":10,"shadowOffsetY":10,"shadowOpacity":0.5},"className":"Text"},{"attrs":{"stroke":"green","strokeWidth":10,"lineJoin":"round","lineCap":"round","points":[{"x":50,"y":140},{"x":450,"y":160}],"shadowColor":"black","shadowBlur":10,"shadowOffsetX":5,"shadowOffsetY":5,"shadowOpacity":0.5},"className":"Line"},{"attrs":{"x":280,"y":100,"width":100,"height":50,"fill":"#00D2FF","stroke":"black","strokeWidth":4,"shadowColor":"black","shadowBlur":10,"shadowOffsetX":5,"shadowOffsetY":5,"shadowOpacity":0.5,"rotation":0.35038503988659,"id":"blueRectangle"},"className":"Rect"},{"attrs":{"x":100,"y":41,"width":106,"height":118,"id":"yodaImage"},"className":"Image"}]}]}';

var stage = Konva.Node.create(json, 'container');

/*
* set functions
*/
stage.findOne('#blueRectangle').on('mouseover mouseout', function () {
var stroke = this.stroke();
this.stroke(stroke === 'black' ? 'red' : 'black');
});
/*
* set images
*/
var imageObj = new Image();
imageObj.onload = function () {
stage.findOne('#yodaImage').image(imageObj);
};
imageObj.src = '/assets/yoda.jpg';
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/data_and_serialization/High-Quality-Export.html b/docs/data_and_serialization/High-Quality-Export.html new file mode 100644 index 000000000..dab5f21a5 --- /dev/null +++ b/docs/data_and_serialization/High-Quality-Export.html @@ -0,0 +1,731 @@ + + + + + + HTML5 Canvas Export to High Quality Image Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Export to High Quality Image Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

How to export a high quality image from a stage?

If you need to export a stage as an image or as base64 then you can use the stage.toDataURL() or stage.toImage() methods.

+

By default in Konva, exported images have the pixelRatio attribute set to 1. This means that if you export a stage with a size of 500x500, then the exported image will have the same size of 500x500.

+

In some cases you may want to export an image that is more suited to higher (or even smaller) resolutions. For instance, you may wish to export something as an image and then use that image on a canvas on HDPI devices (with a high pixel ratio, like a retina display). Another scenario may be that you need to export a user’s drawing onto a computer running a high resolution.

+

If you were to do this with the default settings, then you would see a blurred image. You can read more about the global pixelRatio attribute here MDN - devicePixelRatio.

+

For both of these use cases, you can use:

+
stage.toDataURL({
pixelRatio: 2 // or other value you need
})
+ +

Now, a stage with a size of 500x500 would be exported as an image with a size of 1000x1000. Almost all nodes in Konva are stored as vector data, apart from bitmap images and cached nodes. This results in a high quality exported image.

+

Usage: try to save stage as an image. You will see that it has a high resolution.

+ + +
Konva Pixel Ratio Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva High Quality Export Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#buttons {
position: absolute;
top: 5px;
left: 10px;
}

#buttons > input {
padding: 10px;
display: block;
margin-top: 5px;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="buttons"><button id="save">Save as image</button></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var box = new Konva.Rect({
x: stage.width() / 2 - 50,
y: stage.height() / 2 - 25,
width: 100,
height: 50,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
draggable: true,
});
layer.add(box);

var circle = new Konva.Circle({
x: stage.width() - 50,
y: stage.height() - 50,
radius: 50,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
draggable: true,
});
layer.add(circle);

// function from https://stackoverflow.com/a/15832662/512042
function downloadURI(uri, name) {
var link = document.createElement('a');
link.download = name;
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
delete link;
}

document.getElementById('save').addEventListener(
'click',
function () {
var dataURL = stage.toDataURL({ pixelRatio: 3 });
downloadURI(dataURL, 'stage.png');
},
false
);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/data_and_serialization/Serialize_a_Stage.html b/docs/data_and_serialization/Serialize_a_Stage.html new file mode 100644 index 000000000..f1651b7cb --- /dev/null +++ b/docs/data_and_serialization/Serialize_a_Stage.html @@ -0,0 +1,724 @@ + + + + + + Save HTML5 Canvas Stage as JSON String | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Save HTML5 Canvas Stage as JSON String

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

How to export canvas to JSON?

To save the stage as a JSON string with Konva, we can use the toJSON()
method which serializes the Konva Node tree into text which can be saved
in web storage or in an offline database. We can also serialize other nodes,
including layers, groups, and shapes.

+

toJSON() method can’t save filters, images and event listeners. So it works for very small apps. For more complex cases read Best Practices

+ + +
Konva Save Stage Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Save Stage Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var hexagon = new Konva.RegularPolygon({
x: width / 2,
y: height / 2,
sides: 6,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

// add the shape to the layer
layer.add(hexagon);

// add the layer to the stage
stage.add(layer);

// save stage as a json string
var json = stage.toJSON();

console.log(json);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/data_and_serialization/Simple_Load.html b/docs/data_and_serialization/Simple_Load.html new file mode 100644 index 000000000..87a45bf83 --- /dev/null +++ b/docs/data_and_serialization/Simple_Load.html @@ -0,0 +1,724 @@ + + + + + + Load Stage with JSON String | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Load Stage with JSON String

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To deserialize a JSON string with Konva, we can use the Konva.Node.create()
method which creates a node from a JSON string. If we want to deserialize
a stage node, we can also pass in an optional container parameter.

+

That methods works for very small apps. For more complex cases take a look into Complex Load or even better to Best Practices

+ + +
Konva Simple Load Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Simple Load Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var json =
'{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{"x":100,"y":100,"sides":6,"radius":70,"fill":"red","stroke":"black","strokeWidth":4},"className":"RegularPolygon"}]}]}';

// create node using json string
var stage = Konva.Node.create(json, 'container');
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/data_and_serialization/Stage_Data_URL.html b/docs/data_and_serialization/Stage_Data_URL.html new file mode 100644 index 000000000..ee71165ed --- /dev/null +++ b/docs/data_and_serialization/Stage_Data_URL.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas to Data URL Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas to Data URL Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

How to export canvas content into image?

To get the data URL of the stage with Konva, we can use the toDataURL()
method which requires a callback function for Stage (for other nodes callback is not required).
In addition, we can also pass in a mime type such as image/jpeg and a quality value that ranges between 0 and 1.
We can also get the data URLs of specific nodes, including layers, groups, and shapes.

+

Note: The toDataURL() method requires that any images drawn onto the canvas
are hosted on a web server with the same domain as the code executing it.
If this condition is not met, a SECURITY_ERR exception is thrown.

+

Instructions: Drag and drop the rectangle and then click on the save button to get the composite data url and open the resulting image in a new window

+ + +
Konva Stage Data URL Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Stage Data URL Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#buttons {
position: absolute;
top: 5px;
left: 10px;
}

#buttons > input {
padding: 10px;
display: block;
margin-top: 5px;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="buttons">
<button id="save">Save as image</button>
</div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var rectX = stage.width() / 2 - 50;
var rectY = stage.height() / 2 - 25;

var box = new Konva.Rect({
x: rectX,
y: rectY,
width: 100,
height: 50,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
draggable: true,
});

box.on('mouseover', function () {
document.body.style.cursor = 'pointer';
});

box.on('mouseout', function () {
document.body.style.cursor = 'default';
});

layer.add(box);
stage.add(layer);

// function from https://stackoverflow.com/a/15832662/512042
function downloadURI(uri, name) {
var link = document.createElement('a');
link.download = name;
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
delete link;
}

document.getElementById('save').addEventListener(
'click',
function () {
var dataURL = stage.toDataURL();
downloadURI(dataURL, 'stage.png');
},
false
);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/donate.html b/docs/donate.html new file mode 100644 index 000000000..d099b653f --- /dev/null +++ b/docs/donate.html @@ -0,0 +1,730 @@ + + + + + + How to support and donate to Konva project? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to support and donate to Konva project?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

Hello, my name is Anton. I am core maintainer of Konva framework.

+

If you want to support development of Konva and all its ecosystem tools like react-konva and vue-konva you can use:

+ +

I am spending a large amount of time to support Konva users and develop new versions with bugs fixes and new features.

+

If you are making money, by using Konva in your project, it makes sense to support Konva development. By doing this you will make sure that you have a good quality and maintained framework.

+

Even if you are not making money from your project but Konva saved you a lot of time, it will be very kind to support it.

+

Your company is using Konva?

It may be hard for many developers to make a financial donation. But if you are using konva as part of your work in the company, talk to your managers to support the project. Well-supported project is a good value for the company.

+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/drag_and_drop/Complex_Drag_and_Drop.html b/docs/drag_and_drop/Complex_Drag_and_Drop.html new file mode 100644 index 000000000..42002a5e5 --- /dev/null +++ b/docs/drag_and_drop/Complex_Drag_and_Drop.html @@ -0,0 +1,725 @@ + + + + + + Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

title: HTML5 Canvas Complex Drag and Drop Bounds

How to limit dragging ability with Konva?

To bound the movement of nodes being dragged and dropped inside regions with
Konva, we can use the dragmove event to define boundaries that the node cannot cross.

+

Tip: you can use shape.absolutePosition() method to get/set absolute position of a node, instead of relative x and y.

+

Instructions: Drag and drop the the light blue rectangle and observe that it
is bound below an imaginary boundary at y = 50. Drag and drop the yellow
rectangle and observe that it is bound inside of an imaginary circle.

+ + +
Konva Complex Drag and Drop Bounds Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Complex Drag and Drop Bounds Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var blueGroup = new Konva.Group({
x: 30,
y: 70,
draggable: true,
});

// bound below y=50
blueGroup.on('dragmove', () => {
blueGroup.y(Math.max(blueGroup.y(), 50));
});

// bound inside a circle
var yellowGroup = new Konva.Group({
x: stage.width() / 2,
y: 70,
draggable: true,
});

yellowGroup.on('dragmove', () => {
var x = stage.width() / 2;
var y = 70;
var radius = 50;
const pos = yellowGroup.absolutePosition();
var scale =
radius / Math.sqrt(Math.pow(pos.x - x, 2) + Math.pow(pos.y - y, 2));

if (scale < 1) {
yellowGroup.x(Math.round((pos.x - x) * scale + x));
yellowGroup.y(Math.round((pos.y - y) * scale + y));
}
});

var blueText = new Konva.Text({
fontSize: 26,
fontFamily: 'Calibri',
text: 'bound below',
fill: 'black',
padding: 10,
});

var blueRect = new Konva.Rect({
width: blueText.width(),
height: blueText.height(),
fill: '#aaf',
stroke: 'black',
strokeWidth: 4,
});

var yellowText = new Konva.Text({
fontSize: 26,
fontFamily: 'Calibri',
text: 'bound in circle',
fill: 'black',
padding: 10,
});

var yellowRect = new Konva.Rect({
width: yellowText.width(),
height: yellowText.height(),
fill: 'yellow',
stroke: 'black',
strokeWidth: 4,
});

blueGroup.add(blueRect).add(blueText);
yellowGroup.add(yellowRect).add(yellowText);

layer.add(blueGroup);
layer.add(yellowGroup);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/drag_and_drop/Drag_Events.html b/docs/drag_and_drop/Drag_Events.html new file mode 100644 index 000000000..6e63b095b --- /dev/null +++ b/docs/drag_and_drop/Drag_Events.html @@ -0,0 +1,722 @@ + + + + + + HTML5 Canvas Drag and Drop Events | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Drag and Drop Events

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To detect drag and drop events with Konva, we can use the on() method to
bind dragstart, dragmove, or dragend events to a node.
The on() method requires an event type and a function to be executed when the event occurs.

+ + +
Konva Drag Events Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Drag Events Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
function writeMessage(message) {
text.text(message);
}
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var text = new Konva.Text({
x: 10,
y: 10,
fontFamily: 'Calibri',
fontSize: 24,
text: '',
fill: 'black',
});

var box = new Konva.Rect({
x: 20,
y: 100,
offset: [50, 25],
width: 100,
height: 50,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
draggable: true,
});

// write out drag and drop events
box.on('dragstart', function () {
writeMessage('dragstart');
});
box.on('dragend', function () {
writeMessage('dragend');
});

layer.add(text);
layer.add(box);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/drag_and_drop/Drag_a_Group.html b/docs/drag_and_drop/Drag_a_Group.html new file mode 100644 index 000000000..9b44db033 --- /dev/null +++ b/docs/drag_and_drop/Drag_a_Group.html @@ -0,0 +1,722 @@ + + + + + + HTML5 Canvas Drag and Drop a Group Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Drag and Drop a Group Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To drag and drop groups with Konva, we can set the draggable property
of the config object to true when the group is instantiated, or we can use the draggable() method.

+ + +
Konva Drag and Drop the Group Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Drag and Drop a Group Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var shapesLayer = new Konva.Layer();
var group = new Konva.Group({
draggable: true,
});
var colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'];

for (var i = 0; i < 6; i++) {
var box = new Konva.Rect({
x: i * 30 + 10,
y: i * 18 + 40,
width: 100,
height: 50,
name: colors[i],
fill: colors[i],
stroke: 'black',
strokeWidth: 4,
});
group.add(box);
}

group.on('mouseover', function () {
document.body.style.cursor = 'pointer';
});
group.on('mouseout', function () {
document.body.style.cursor = 'default';
});

shapesLayer.add(group);
stage.add(shapesLayer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/drag_and_drop/Drag_a_Line.html b/docs/drag_and_drop/Drag_a_Line.html new file mode 100644 index 000000000..81fa2d1d2 --- /dev/null +++ b/docs/drag_and_drop/Drag_a_Line.html @@ -0,0 +1,722 @@ + + + + + + Drag and Drop a Line | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Drag and Drop a Line

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To drag and drop a line with Konva, we can set the draggable property
of the config object to true when the group is instantiated, or we can use the draggable() method.

+ + +
Konva Drag and Drop the Line Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Drag and Drop a Line Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

// complex dashed and dotted line
var blueLine = new Konva.Line({
y: 50,
points: [10, 70, 40, 23, 150, 60, 250, 20],
stroke: 'blue',
strokeWidth: 10,
lineCap: 'round',
lineJoin: 'round',
/*
* line segments with a length of 29px with a gap
* of 20px followed by a line segment of 0.001px (a dot)
* followed by a gap of 20px
*/
dash: [29, 20, 0.001, 20],
draggable: true,
});

layer.add(blueLine);
stage.add(layer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/drag_and_drop/Drag_a_Stage.html b/docs/drag_and_drop/Drag_a_Stage.html new file mode 100644 index 000000000..b63fa35a3 --- /dev/null +++ b/docs/drag_and_drop/Drag_a_Stage.html @@ -0,0 +1,723 @@ + + + + + + HTML5 Canvas Drag and Drop the Stage | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Drag and Drop the Stage

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To drag and drop a stage with Konva, we can set the draggable property
of the config object to true when the group is instantiated, or we can use the draggable() method.

+

Unlike drag and drop for other nodes, such as shapes, groups, and layers,
we can drag the entire stage by dragging any portion of the stage.

+ + +
Konva Drag and Drop the Stage Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Drag and Drop the Stage Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
draggable: true,
});

var layer = new Konva.Layer();

var circle = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

// add the shape to the layer
layer.add(circle);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/drag_and_drop/Drag_an_Image.html b/docs/drag_and_drop/Drag_an_Image.html new file mode 100644 index 000000000..fb1e7c58e --- /dev/null +++ b/docs/drag_and_drop/Drag_an_Image.html @@ -0,0 +1,722 @@ + + + + + + HTML5 Canvas Drag and Drop an Image | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Drag and Drop an Image

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To drag and drop an image with Konva, we can set the draggable property
to true when we instantiate a shape, or we can use the draggable() method.
The draggable() method enables drag and drop for both desktop and mobile
applications automatically.

+ + +
Konva Drag and Drop an Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Drag and Drop an Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

function drawImage(imageObj) {
var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
// darth vader
var darthVaderImg = new Konva.Image({
image: imageObj,
x: stage.width() / 2 - 200 / 2,
y: stage.height() / 2 - 137 / 2,
width: 200,
height: 137,
draggable: true,
});

// add cursor styling
darthVaderImg.on('mouseover', function () {
document.body.style.cursor = 'pointer';
});
darthVaderImg.on('mouseout', function () {
document.body.style.cursor = 'default';
});

layer.add(darthVaderImg);
stage.add(layer);
}
var imageObj = new Image();
imageObj.onload = function () {
drawImage(this);
};
imageObj.src = '/assets/darth-vader.jpg';
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/drag_and_drop/Drag_and_Drop.html b/docs/drag_and_drop/Drag_and_Drop.html new file mode 100644 index 000000000..39efa4d95 --- /dev/null +++ b/docs/drag_and_drop/Drag_and_Drop.html @@ -0,0 +1,723 @@ + + + + + + HTML5 Canvas Drag and Drop Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Drag and Drop Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To drag and drop shapes with Konva, we can set the draggable property
to true when we instantiate a shape, or we can use the draggable() method.
The draggable() method enables drag and drop for both desktop and mobile
applications automatically.

+

To detect drag and drop events with Konva, we can use the on() method to
bind dragstart, dragmove, or dragend events to a node.
The on() method requires an event type and a function to be executed when the event occurs.

+ + +
Konva Drag and Drop Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Drag and Drop Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
var rectX = stage.width() / 2 - 50;
var rectY = stage.height() / 2 - 25;

var box = new Konva.Rect({
x: rectX,
y: rectY,
width: 100,
height: 50,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
draggable: true,
});

// add cursor styling
box.on('mouseover', function () {
document.body.style.cursor = 'pointer';
});
box.on('mouseout', function () {
document.body.style.cursor = 'default';
});

layer.add(box);
stage.add(layer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/drag_and_drop/Drop_Events.html b/docs/drag_and_drop/Drop_Events.html new file mode 100644 index 000000000..5565af2d5 --- /dev/null +++ b/docs/drag_and_drop/Drop_Events.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Drop Events | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Drop Events

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

Konva does not support drop events. But you can write your own drop events detections.
To detect drop target shape you have to move dragging object into another layer.

+

In this example you can see implementation of drop, dragenter, dragleave, dragover events.

+

Instructions: drag one shape over another. Or drag and drop one shape into another.

+ + +
Konva Drop Events Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Drop Events Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

stage.add(layer);

var tempLayer = new Konva.Layer();
stage.add(tempLayer);

var text = new Konva.Text({
fill: 'black',
});
layer.add(text);

var star;
for (var i = 0; i < 10; i++) {
star = new Konva.Star({
x: stage.width() * Math.random(),
y: stage.height() * Math.random(),
fill: 'blue',
numPoints: 10,
innerRadius: 20,
outerRadius: 25,
draggable: true,
name: 'star ' + i,
shadowOffsetX: 5,
shadowOffsetY: 5,
});
layer.add(star);
}

stage.on('dragstart', function (e) {
e.target.moveTo(tempLayer);
layer.draw();
text.text('Moving ' + e.target.name());
});

var previousShape;
stage.on('dragmove', function (evt) {
var pos = stage.getPointerPosition();
var shape = layer.getIntersection(pos);
if (previousShape && shape) {
if (previousShape !== shape) {
// leave from old targer
previousShape.fire(
'dragleave',
{
evt: evt.evt,
},
true
);

// enter new targer
shape.fire(
'dragenter',
{
evt: evt.evt,
},
true
);
previousShape = shape;
} else {
previousShape.fire(
'dragover',
{
evt: evt.evt,
},
true
);
}
} else if (!previousShape && shape) {
previousShape = shape;
shape.fire(
'dragenter',
{
evt: evt.evt,
},
true
);
} else if (previousShape && !shape) {
previousShape.fire(
'dragleave',
{
evt: evt.evt,
},
true
);
previousShape = undefined;
}
});
stage.on('dragend', function (e) {
var pos = stage.getPointerPosition();
var shape = layer.getIntersection(pos);
if (shape) {
previousShape.fire(
'drop',
{
evt: e.evt,
},
true
);
}
previousShape = undefined;
e.target.moveTo(layer);
});

stage.on('dragenter', function (e) {
e.target.fill('green');
text.text('dragenter ' + e.target.name());
});

stage.on('dragleave', function (e) {
e.target.fill('blue');
text.text('dragleave ' + e.target.name());
});

stage.on('dragover', function (e) {
text.text('dragover ' + e.target.name());
});

stage.on('drop', function (e) {
e.target.fill('red');
text.text('drop ' + e.target.name());
});
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/drag_and_drop/Simple_Drag_Bounds.html b/docs/drag_and_drop/Simple_Drag_Bounds.html new file mode 100644 index 000000000..6cdeef6c4 --- /dev/null +++ b/docs/drag_and_drop/Simple_Drag_Bounds.html @@ -0,0 +1,728 @@ + + + + + + Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

title: HTML5 Canvas Simple Drag Bounds Tutorial

To restrict the movement of shapes being dragged and dropped with Konva,
we can use the dragmove event and overrides the drag and drop position inside of it.

+

This event can be used to constrain the drag and drop movement in all kinds of ways, such as constraining the motion horizontally, vertically, diagonally, or radially, or even constrain the node
to stay inside of a box, circle, or any other path.

+
shape.on('dragmove', () => {
// lock position of the shape on x axis
// keep y position as is
shape.x(0);
});
+ +

Tip: you can use shape.absolutePosition() method to get/set absolute position of a node, instead of relative x and y.

+

Instructions: Drag and drop the the horizontal text and observe that it can only
move horizontally. Drag and drop the vertical text and observe that it can only move vertically.

+ + +
Konva Simple Drag Bounds Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Simple Drag Bounds Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
// add the layer to the stage
stage.add(layer);

var rectHeight = 50;
var rectY = (stage.height() - rectHeight) / 2;

var hbox = new Konva.Text({
x: 20,
y: 70,
fontSize: 24,
fontFamily: 'Calibri',
text: 'horizontal',
fill: 'black',
padding: 15,
draggable: true,
dragBoundFunc: function (pos) {
return {
x: pos.x,
y: this.absolutePosition().y,
};
},
});
layer.add(hbox);
var originalY = hbox.y();
hbox.on('dragmove', () => {
// we will keep new x position
// but reset y position to the original
hbox.y(originalY);
});

var vbox = new Konva.Text({
x: 150,
y: 70,
draggable: true,
fontSize: 24,
fontFamily: 'Calibri',
text: 'vertical',
fill: 'black',
padding: 15,
});
layer.add(vbox);
var originalX = vbox.x();
vbox.on('dragmove', () => {
// we will keep new x position
// but reset y position to the original
vbox.x(originalX);
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/events/Binding_Events.html b/docs/events/Binding_Events.html new file mode 100644 index 000000000..83e65a471 --- /dev/null +++ b/docs/events/Binding_Events.html @@ -0,0 +1,730 @@ + + + + + + HTML5 Canvas Shape Events | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Shape Events

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To detect shape events with Konva, we can use the on() method to bind event handlers to a node.

+

The on() method requires an event type and a function to be executed when the event occurs.

+

Mouse events: mouseover, mouseout, mouseenter, mouseleave, mousemove, mousedown, mouseup, wheel, click, dblclick.

+

Touch events: touchstart, touchmove, touchend, tap, dbltap.

+

Pointer events: pointerdown, pointermove, pointereup, pointercancel, pointerover, pointerenter, pointerout,pointerleave, pointerclick, pointerdblclick.

+

Drag events: dragstart, dragmove, and dragend.

+

Transform events: transformstart, transform, transformend.

+

Instructions: Mouseover and mouseout of the triangle, and mouseover, mouseout, mousedown, and mouseup over the circle.

+ + +
Konva Binding_Events Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Shape Events Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
function writeMessage(message) {
text.text(message);
}

var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var triangle = new Konva.RegularPolygon({
x: 80,
y: 120,
sides: 3,
radius: 80,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
});

var text = new Konva.Text({
x: 10,
y: 10,
fontFamily: 'Calibri',
fontSize: 24,
text: '',
fill: 'black',
});

triangle.on('mouseout', function () {
writeMessage('Mouseout triangle');
});

triangle.on('mousemove', function () {
var mousePos = stage.getPointerPosition();
writeMessage('x: ' + mousePos.x + ', y: ' + mousePos.y);
});

var circle = new Konva.Circle({
x: 230,
y: 100,
radius: 60,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

circle.on('mouseover', function () {
writeMessage('Mouseover circle');
});
circle.on('mouseout', function () {
writeMessage('Mouseout circle');
});
circle.on('mousedown', function () {
writeMessage('Mousedown circle');
});
circle.on('mouseup', function () {
writeMessage('Mouseup circle');
});

layer.add(triangle);
layer.add(circle);
layer.add(text);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/events/Cancel_Propagation.html b/docs/events/Cancel_Propagation.html new file mode 100644 index 000000000..040a56af5 --- /dev/null +++ b/docs/events/Cancel_Propagation.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Cancel Event Bubble Propagation with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Cancel Event Bubble Propagation with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To cancel event bubble propagation with Konva, we can set the cancelBubble
property of the Event object to true.

+

Instructions: Click on the circle to observe that only the circle event binding
is handled because the event propagation was canceled when the circle event was triggered,
therefore preventing the event object from bubbling upwards.

+ + +
Konva Cancel_Propagation Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Cancel Event Bubble Propagation Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var group = new Konva.Group();

var circle = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

circle.on('click', function (evt) {
alert('You clicked the circle!');
evt.cancelBubble = true;
});

group.on('click', function () {
alert('You clicked on the group!');
});

layer.on('click', function () {
alert('You clicked on the layer!');
});

group.add(circle);
layer.add(group);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/events/Custom_Hit_Region.html b/docs/events/Custom_Hit_Region.html new file mode 100644 index 000000000..96109756b --- /dev/null +++ b/docs/events/Custom_Hit_Region.html @@ -0,0 +1,729 @@ + + + + + + HTML5 Canvas Custom Hit Detection Function Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Custom Hit Detection Function Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

There are two ways to change hit region of the shape: hitFunc and hitStrokeWidth properties.

+

1. What is hitFunc?

To create a custom hit draw function for a shape with Konva, we can set
the hitFunc property. A hit draw function is the function that Konva
will use to draw a region used for hit detection. Using a custom draw hit
function can have several benefits, such as making the hit region larger
so that it’s easier for users to interact with a shape, making some portions
of a shape detectable and others not, or simplifying the hit draw function
in order to improve rendering performance.

+

Also take a look into some best practices of writing custom sceneFunc that can be used for hitFunc too.

+

hitFunc is a function with two arguments: Konva.Context renderer and a shape instance.

+

With hitFunc you have full control over drawing.

+

2. What is hitStrokeWidth?

For some shapes, like Konva.Line it is too hard to overwrite hitFunc. In some cases you just want to make it thicker for events. In this case it is better to use hitStrokeWidth property with a large value.

+

Instructions: Mouseover, mouseout, mousedown, and mouseup over the star and
observe that the hit region is an over sized circle encompassing the shape. Also try the same for a a line.
Also you can toggle hit canvas too see how it looks. It may be useful for debugging.

+ + +
Konva Custom_Hit_Region Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Custom Hit Function Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
button {
position: absolute;
top: 5px;
left: 5px;
z-index: 2;
}
</style>
</head>

<body>
<button id="toggle">Toggle hit canvas</button>
<div id="container"></div>
<script>
function writeMessage(message) {
text.text(message);
}

var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();
stage.add(layer);

var text = new Konva.Text({
x: 10,
y: 30,
fontSize: 24,
fill: 'black',
});
layer.add(text);

var star = new Konva.Star({
x: stage.width() / 2,
y: stage.height() / 2,
numPoints: 7,
innerRadius: 50,
outerRadius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
hitFunc: function (context) {
context.beginPath();
context.arc(0, 0, this.outerRadius() + 10, 0, Math.PI * 2, true);
context.closePath();
context.fillStrokeShape(this);
},
});
layer.add(star);

var line = new Konva.Line({
x: 50,
y: 100,
points: [0, 0, 50, 0, 50, 100, 0, 100],
tension: 1,
strokeWidth: 1,
hitStrokeWidth: 20,
stroke: 'black',
});
layer.add(line);

star.on('mouseover', function () {
writeMessage('Mouseover star');
});
star.on('mouseout', function () {
writeMessage('Mouseout star');
});
star.on('mousedown', function () {
writeMessage('Mousedown star');
});
star.on('mouseup', function () {
writeMessage('Mouseup star');
});

line.on('mouseover', function () {
writeMessage('Mouseover line');
});
line.on('mouseout', function () {
writeMessage('Mouseout line');
});
line.on('mousedown', function () {
writeMessage('Mousedown line');
});
line.on('mouseup', function () {
writeMessage('Mouseup line');
});

document.getElementById('toggle').addEventListener('click', function () {
layer.toggleHitCanvas();
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/events/Desktop_and_Mobile.html b/docs/events/Desktop_and_Mobile.html new file mode 100644 index 000000000..fc66f1e6f --- /dev/null +++ b/docs/events/Desktop_and_Mobile.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Desktop and Mobile Events Support Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Desktop and Mobile Events Support Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

Note: this demo may be outdate, because modern browsers support pointer events. And you can use pointer events in Konva too. See Pointer Events Demo. But if you prefer not to use pointer events, keep reading…

+

To add event handlers to shapes that work for both desktop and mobile applications with Konva, we can use the on() method and pass in paired events.
For example, in order for the mousedown event to be triggered on desktop and mobile applications, we can use the "mousedown touchstart" event pair to cover both mediums.
In order for the mouseup event to be triggered on both desktop and mobile applications, we can use the "mouseup touchend" event pair.
We can also use the "dblclick dbltap" event pair to bind a double click event that works for both desktop and mobile devices.

+

Instructions: Mousedown, mouseup, touchstart, or touchend the circle on either a desktop or mobile device to observe the same functionality.

+ + +
Konva Desktop_and_Mobile Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Desktop and Mobile Events Support Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
function writeMessage(message) {
text.text(message);
}

var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var text = new Konva.Text({
x: 10,
y: 10,
fontFamily: 'Calibri',
fontSize: 20,
text: '',
fill: 'black',
});

var circle = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2 + 10,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

/*
* mousedown and touchstart are desktop and
* mobile equivalents so they are often times
* used together
*/
circle.on('mousedown touchstart', function () {
writeMessage('Mousedown or touchstart');
});
/*
* mouseup and touchend are desktop and
* mobile equivalents so they are often times
* used together
*/
circle.on('mouseup touchend', function () {
writeMessage('Mouseup or touchend');
});

layer.add(circle);
layer.add(text);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/events/Event_Delegation.html b/docs/events/Event_Delegation.html new file mode 100644 index 000000000..0cc60b04b --- /dev/null +++ b/docs/events/Event_Delegation.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Event Delegation with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Event Delegation with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To get the event target with Konva, we can access the target property
of the Event object. This is particularly useful when using event delegation,
in which we can bind an event handler to a parent node, and listen to events
that occur on its children.

+

Instructions: Click on the star and observe that the layer event binding
correctly identifies the shape that was clicked on.

+ + +
Konva Event_Delegation Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Event Delegation Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var star = new Konva.Star({
x: stage.width() / 2,
y: stage.height() / 2,
numPoints: 15,
innerRadius: 40,
outerRadius: 70,
fill: 'blue',
scale: {
x: 2,
y: 0.5,
},
name: 'my star',
});

layer.on('click', function (evt) {
// get the shape that was clicked on
var shape = evt.target;
alert('you clicked on "' + shape.name() + '"');
});

layer.add(star);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/events/Fire_Events.html b/docs/events/Fire_Events.html new file mode 100644 index 000000000..b6e1848e6 --- /dev/null +++ b/docs/events/Fire_Events.html @@ -0,0 +1,723 @@ + + + + + + HTML5 Canvas Fire Event with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Fire Event with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

HTML5 Canvas Fire Event with Konva

To fire events with Konva, we can use the fire() method.
This enables us to programmatically fire events like click, mouseover,
mousemove, etc., and also fire custom events, like foo and bar.

+ + +
Konva Fire_Events Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Fire Event Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var circle = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2 + 10,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

var text = new Konva.Text({
text: '',
fontFamily: 'Calibri',
fontSize: 24,
fill: 'black',
x: 10,
y: 10,
});

circle.on('click', function (evt) {
text.text('you clicked on the circle!');
});

layer.add(circle).add(text);
stage.add(layer);

// simulate click on circle
circle.fire('click');
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/events/Image_Events.html b/docs/events/Image_Events.html new file mode 100644 index 000000000..37a2cb972 --- /dev/null +++ b/docs/events/Image_Events.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Image Events with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Image Events with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

HTML5 Canvas Image Events with Konva

To only detect events for non transparent pixels in an image with Konva, we can use the drawHitFromCache() method to generate a more precise image hit region.
By default, events can be triggered for any pixel inside of an image, even if it’s transparent. The drawHitFromCache() method also accepts an optional callback method to be executed whenever the image hit region has been created.

+

Note: The drawHitFromCache() method requires that the image is hosted on a web server with the same domain as the code executing it.

+

Instructions: Mouse over the monkey and the lion and observe the mouseover event bindings. Notice that the event is triggered for the monkey if you mouseover any portion of the image, including transparent pixels. Since we created an image hit region for the lion, transparent pixels are ignored, which enables more precise event detection.

+ + +
Konva Image_Events Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Image Events Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
function writeMessage(message) {
text.text(message);
}
function loadImages(sources, callback) {
var images = {};
var loadedImages = 0;
var numImages = 0;
for (var src in sources) {
numImages++;
}
for (var src in sources) {
images[src] = new Image();
images[src].onload = function () {
if (++loadedImages >= numImages) {
callback(images);
}
};
images[src].src = sources[src];
}
}
function buildStage(images) {
var monkey = new Konva.Image({
image: images.monkey,
x: 120,
y: 50,
});

var lion = new Konva.Image({
image: images.lion,
x: 280,
y: 30,
});

monkey.on('mouseover', function () {
writeMessage('mouseover monkey');
});

monkey.on('mouseout', function () {
writeMessage('');
});

lion.on('mouseover', function () {
writeMessage('mouseover lion');
});

lion.on('mouseout', function () {
writeMessage('');
});

lion.cache();
lion.drawHitFromCache();

layer.add(monkey);
layer.add(lion);
layer.add(text);
stage.add(layer);
}
var stage = new Konva.Stage({
container: 'container',
width: 578,
height: 200,
});

var layer = new Konva.Layer();

var text = new Konva.Text({
x: 10,
y: 10,
fontFamily: 'Calibri',
fontSize: 24,
text: '',
fill: 'black',
});

var sources = {
lion: '/assets/lion.png',
monkey: '/assets/monkey.png',
};

loadImages(sources, buildStage);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/events/Keyboard_Events.html b/docs/events/Keyboard_Events.html new file mode 100644 index 000000000..52394f450 --- /dev/null +++ b/docs/events/Keyboard_Events.html @@ -0,0 +1,729 @@ + + + + + + HTML5 Canvas Keyboard events with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Keyboard events with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

HTML5 Canvas Keyboard events with Konva

There are no build-in keyboards events like keydown or keyup in Konva.

+

But how to listen keydown or keyup events on canvas?

You can easily add them by two ways:

+
    +
  1. Listen global events on window object
  2. +
  3. Or make stage container focusable with tabIndex property and listen events on it.
  4. +
+

Instructions: click on stage to focus it, move a shape with arrows

+ + +
HTML5 Canvas Keyboard eventsview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Canvas Keyboard events Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();
stage.add(layer);

var circle = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2 + 10,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

layer.add(circle);

var container = stage.container();

// make it focusable

container.tabIndex = 1;
// focus it
// also stage will be in focus on its click
container.focus();

const DELTA = 4;

container.addEventListener('keydown', function (e) {
if (e.keyCode === 37) {
circle.x(circle.x() - DELTA);
} else if (e.keyCode === 38) {
circle.y(circle.y() - DELTA);
} else if (e.keyCode === 39) {
circle.x(circle.x() + DELTA);
} else if (e.keyCode === 40) {
circle.y(circle.y() + DELTA);
} else {
return;
}
e.preventDefault();
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/events/Listen_for_Events.html b/docs/events/Listen_for_Events.html new file mode 100644 index 000000000..af65467ad --- /dev/null +++ b/docs/events/Listen_for_Events.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Listen or Don’t Listen to Events with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Listen or Don’t Listen to Events with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To listen or don’t listen to events with Konva, we can set the listening
property of the config object to true or false when a shape is instantiated,
or we can set the listening property with the setListening() method.
Once we’ve set the listening property for one or more nodes, we’ll also need
to redraw the hit graph for each affected layer with the drawHit() method.

+

Instructions: Mouseover the oval to observe that the event handler is not executed.
Click on “Listen” to start listening for events and observe that the event handler is now executed.

+ + +
Konva Listen_for_Events Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Listen or Don’t Listen to Events Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#buttons {
position: absolute;
top: 5px;
left: 10px;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="buttons">
<button id="listen">Listen</button>
<button id="dontListen">Dont' Listen</button>
</div>
<script>
function writeMessage(message) {
text.text(message);
}

var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var text = new Konva.Text({
x: 70,
y: 10,
fontFamily: 'Calibri',
fontSize: 24,
text: '',
fill: 'black',
});

var oval = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2,
radius: 50,
scaleX: 2,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
strokeScaleEnabled: false,
listening: false,
});

oval.on('mouseover', function () {
writeMessage('Mouseover oval');
});
oval.on('mouseout', function () {
writeMessage('');
});

layer.add(oval);
layer.add(text);
stage.add(layer);

document.getElementById('listen').addEventListener(
'click',
function () {
oval.listening(true);
layer.drawHit();
},
false
);

document.getElementById('dontListen').addEventListener(
'click',
function () {
oval.listening(false);
layer.drawHit();
},
false
);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/events/Mobile_Events.html b/docs/events/Mobile_Events.html new file mode 100644 index 000000000..1f32f77d8 --- /dev/null +++ b/docs/events/Mobile_Events.html @@ -0,0 +1,727 @@ + + + + + + HTML5 Canvas Mobile Touch Events Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Mobile Touch Events Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To bind event handlers to shapes on a mobile device with Konva, we can use the on() method.
The on() method requires an event type and a function to be executed when the event occurs.
Konva supports touchstart, touchmove, touchend, tap, dbltap, dragstart, dragmove, and dragend mobile events.

+

For more complex gestures like rotate take a look into Gestures Demo.

+

If you are looking for pan and zoom logic for the whole stage take a look into Multi-touch scale Stage demo.

+

Note: This example only works on mobile devices because it makes use of touch events rather than mouse events.

+

Instructions: move your finger across the triangle to see touch coordinates and touch start and touch end the circle.

+ + +
Konva Mobile_Events Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Mobile Touch Events Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
function writeMessage(message) {
text.text(message);
}

var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var triangle = new Konva.RegularPolygon({
x: 80,
y: 120,
sides: 3,
radius: 80,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
});

var text = new Konva.Text({
x: 10,
y: 10,
fontFamily: 'Calibri',
fontSize: 24,
text: '',
fill: 'black',
});

var circle = new Konva.Circle({
x: 230,
y: 100,
radius: 60,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

triangle.on('touchmove', function () {
var touchPos = stage.getPointerPosition();
var x = touchPos.x - 190;
var y = touchPos.y - 40;
writeMessage('x: ' + x + ', y: ' + y);
});

circle.on('touchstart', function () {
writeMessage('Touchstart circle');
});
circle.on('touchend', function () {
writeMessage('Touchend circle');
});

layer.add(triangle);
layer.add(circle);
layer.add(text);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/events/Mobile_Scrolling.html b/docs/events/Mobile_Scrolling.html new file mode 100644 index 000000000..ac741b84c --- /dev/null +++ b/docs/events/Mobile_Scrolling.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Mobile Scrolling and Native Events with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Mobile Scrolling and Native Events with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

By default Konva will prevent default behaviour off all pointer interactions with a stage.
That will prevent unexpected scrolling of a page when you are trying to drag&drop a shape on a mobile device.

+

But in some cases you may want to keep default behaviour of browser events. In that case you may set preventDefault property of a shape to false.

+

Instructions: if you are on mobile device try to scroll a page by each rectangle.
Green - should prevent default behaviour (no page scrolling).
Red - will keep default behaviour (scrolling should work).

+ + +
Konva Mobile Scrolling Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Mobile Scrolling and Native Events Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var defaultBehaviourRect = new Konva.Rect({
width: 100,
height: 100,
fill: 'green',
});
layer.add(defaultBehaviourRect);

var noPreventDefaultRect = new Konva.Rect({
x: 200,
y: 50,
width: 100,
height: 100,
fill: 'red',
preventDefault: false,
});

layer.add(noPreventDefaultRect);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/events/Multi_Event.html b/docs/events/Multi_Event.html new file mode 100644 index 000000000..d6b7bc5b6 --- /dev/null +++ b/docs/events/Multi_Event.html @@ -0,0 +1,726 @@ + + + + + + HTML5 Canvas Canvas Multi-Event Binding Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Canvas Multi-Event Binding Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To bind multiple events to a single handler with Konva, we can use the on() method and pass in a space delimited string containing multiple event types.

+
shape.on('mouseover mousedown mouseup', function (e) {
console.log('events: ' + e.type);
});
+ +

Instructions: Mouseover, mousedown, and mouseup over the circle to observe that the function bound to the circle is executed for each event.

+ + +
Konva Multi_Event Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Multi-Event Binding Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
function writeMessage(message) {
text.text(message);
}

var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var text = new Konva.Text({
x: 10,
y: 10,
fontFamily: 'Calibri',
fontSize: 20,
text: '',
fill: 'black',
});

var numEvents = 0;

var circle = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2 + 10,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

circle.on('mouseover mousedown mouseup', function () {
writeMessage('Multi-event binding! Events: ' + ++numEvents);
});
circle.on('mouseout', function () {
writeMessage('');
});

layer.add(circle);
layer.add(text);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/events/Pointer_Events.html b/docs/events/Pointer_Events.html new file mode 100644 index 000000000..377273b82 --- /dev/null +++ b/docs/events/Pointer_Events.html @@ -0,0 +1,726 @@ + + + + + + HTML5 Canvas Pointer Events Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Pointer Events Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

Pointer events can be useful to handle both mobile and desktop events with one handler.

+

To bind pointer event handlers to shapes with Konva, we can use the on() method.
The on() method requires an event type and a function to be executed when the event occurs.
Konva supports pointerdown, pointermove, pointerup, pointercancel, pointerover, pointerenter, pointerout,pointerleave, pointerclick, pointerdblclick events.

+

Note: This example works on both mobile and desktop devices.

+

Instructions: move your mouse/finger across the triangle to see pointer coordinates.

+ + +
Konva Pointer Events Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Pointer Events Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
function writeMessage(message) {
text.text(message);
}

var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var triangle = new Konva.RegularPolygon({
x: 80,
y: 120,
sides: 3,
radius: 80,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
});

var text = new Konva.Text({
x: 10,
y: 10,
fontFamily: 'Calibri',
fontSize: 24,
text: '',
fill: 'black',
});

var circle = new Konva.Circle({
x: 230,
y: 100,
radius: 60,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

triangle.on('pointermove', function () {
var pointerPos = stage.getPointerPosition();
var x = pointerPos.x - 190;
var y = pointerPos.y - 40;
writeMessage('x: ' + x + ', y: ' + y);
});

circle.on('pointerdown', function () {
writeMessage('pointerdown circle');
});
circle.on('pointerup', function () {
writeMessage('pointerup circle');
});

circle.on('pointerdblclick', function () {
writeMessage('pointerdblclick circle');
});

layer.add(triangle);
layer.add(circle);
layer.add(text);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/events/Remove_Event.html b/docs/events/Remove_Event.html new file mode 100644 index 000000000..03ff41501 --- /dev/null +++ b/docs/events/Remove_Event.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Remove Event Listener with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Remove Event Listener with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To remove an event listener with Konva, we can use the off() method of
a shape object which requires an event type such as click or mousedown.

+

Instructions: Click on the circle to see an alert triggered from the onclick
event binding. Remove the event listener by clicking on the button and again
click on the circle to observe that the event binding has been removed.

+ + +
Konva Remove_Event Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Remove Event Listener Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#buttons {
position: absolute;
top: 5px;
left: 10px;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="buttons">
<button id="removeClick">Remove onclick</button>
</div>
<script>
function writeMessage(message) {
text.text(message);
}

var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var circle = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2 + 10,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

circle.on('click', function () {
alert('You clicked on the circle');
});

layer.add(circle);
stage.add(layer);

document.getElementById('removeClick').addEventListener(
'click',
function () {
circle.off('click');
alert('onclick removed');
},
false
);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/events/Remove_by_Name.html b/docs/events/Remove_by_Name.html new file mode 100644 index 000000000..d20ee042a --- /dev/null +++ b/docs/events/Remove_by_Name.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Remove Event Listener by Name with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Remove Event Listener by Name with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To remove an event listener by name with Konva,
we can namespace the event type with the on() method so that we can later
remove the event listener by the same namespace with the off() method.

+

Instructions: Click on the circle to see two alerts triggered from two different
onclick event bindings. Remove the event listeners using the buttons to
the left, and again click on the circle to observe the new onclick bindings.

+ + +
Konva Remove By Name Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Remove Event Listener by Name Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#buttons {
position: absolute;
top: 5px;
left: 10px;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="buttons">
<button id="remove1">Remove First Listener</button>
<button id="remove2">Remove Second Listener</button>
<button id="removeAll">Remove All Listeners</button>
</div>
<script>
function writeMessage(message) {
text.text(message);
}

var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var circle = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2 + 10,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

circle.on('click.event1', function () {
alert('First Listener');
});
circle.on('click.event2', function () {
alert('Second Listener');
});

layer.add(circle);
stage.add(layer);

document.getElementById('remove1').addEventListener(
'click',
function () {
circle.off('click.event1');
alert('First onclick removed');
},
false
);

document.getElementById('remove2').addEventListener(
'click',
function () {
circle.off('click.event2');
alert('Second onclick removed');
},
false
);

document.getElementById('removeAll').addEventListener(
'click',
function () {
circle.off('click');
alert('All onclicks removed');
},
false
);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/events/Stage_Events.html b/docs/events/Stage_Events.html new file mode 100644 index 000000000..5426db20b --- /dev/null +++ b/docs/events/Stage_Events.html @@ -0,0 +1,723 @@ + + + + + + HTML5 Canvas Special Stage Events Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Special Stage Events Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

All events are started from Shapes. So if you click on an empty space within a canvas, a click event will not trigger on Layer But it will trigger on the Stage object instead.

+ + +
Konva Stage Events Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Stage Events Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
// add the layer to the stage
stage.add(layer);

var circle = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2,
fill: 'blue',
radius: 30,
});

stage.on('click', function (e) {
// e.target is a clicked Konva.Shape or current stage if you clicked on empty space
console.log('clicked on', e.target);
console.log(
'usual click on ' + JSON.stringify(stage.getPointerPosition())
);
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/Blur.html b/docs/filters/Blur.html new file mode 100644 index 000000000..99cccffa0 --- /dev/null +++ b/docs/filters/Blur.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Blur Image Filter Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Blur Image Filter Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply filter to an Konva.Image, we have to cache it first with cache()
function. Then apply filter with filters() function.

+

To blur an image with Konva, we can use the Konva.Filters.Blur filter
and set the blur amount with the blurRadius property.

+

Instructions: Slide the control to adjust the blur radius.

+

For all available filters go to Filters Documentation.

+ + +
Konva Blur Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Blur Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#slider {
position: absolute;
top: 20px;
left: 20px;
}
</style>
</head>

<body>
<div id="container"></div>
<input id="slider" type="range" min="0" max="40" step="0.05" value="20" />
<script>
function loadImages(sources, callback) {
var images = {};
var loadedImages = 0;
var numImages = 0;
for (var src in sources) {
numImages++;
}
for (var src in sources) {
images[src] = new Image();
images[src].onload = function () {
if (++loadedImages >= numImages) {
callback(images);
}
};
images[src].src = sources[src];
}
}
function buildStage(images) {
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var lion = new Konva.Image({
image: images.lion,
x: 80,
y: 30,
blurRadius: 20,
draggable: true,
});

lion.cache();
lion.filters([Konva.Filters.Blur]);
layer.add(lion);
stage.add(layer);
var slider = document.getElementById('slider');
slider.oninput = function () {
lion.blurRadius(slider.value);
};
}

var sources = {
lion: '/assets/lion.png',
};

loadImages(sources, buildStage);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/Brighten.html b/docs/filters/Brighten.html new file mode 100644 index 000000000..dfa4ccab4 --- /dev/null +++ b/docs/filters/Brighten.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Brighten Image Filter Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Brighten Image Filter Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply filter to an Konva.Image, we have to cache it first with cache()
function. Then apply filter with filters() function.

+

To brighten or darken an image with Konva, we can use the Konva.Filters.Brighten
filter and set the brightness amount with the brightness property.
The brightness property can be set to any integer between -1 and 1.
Negative values darken the image, and positive values brighten the image.

+

Instructions: Slide the control to adjust the brightness

+

For all available filters go to Filters Documentation.

+ + +
Konva Brighten Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Brighten Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#slider {
position: absolute;
top: 20px;
left: 20px;
}
</style>
</head>

<body>
<div id="container"></div>
<input id="slider" type="range" min="-1" max="1" step="0.05" value="0" />
<script>
function loadImages(sources, callback) {
var images = {};
var loadedImages = 0;
var numImages = 0;
for (var src in sources) {
numImages++;
}
for (var src in sources) {
images[src] = new Image();
images[src].onload = function () {
if (++loadedImages >= numImages) {
callback(images);
}
};
images[src].src = sources[src];
}
}
function buildStage(images) {
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var lion = new Konva.Image({
image: images.lion,
x: 80,
y: 30,
draggable: true,
});

lion.cache();
lion.filters([Konva.Filters.Brighten]);
layer.add(lion);
stage.add(layer);
var slider = document.getElementById('slider');
slider.oninput = function () {
lion.brightness(slider.value);
};
}

var sources = {
lion: '/assets/lion.png',
};

loadImages(sources, buildStage);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/Contrast.html b/docs/filters/Contrast.html new file mode 100644 index 000000000..080c48739 --- /dev/null +++ b/docs/filters/Contrast.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Contrast filter Image Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Contrast filter Image Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply filter to an Konva.Node, we have to cache it first with cache()
function. Then apply filter with filters() function.

+

To change contrast of an image with Konva, we can use the Konva.Filters.Contrast.

+

Instructions: Slide the control to change contrast value.

+

For all available filters go to Filters Documentation.

+ + +
Konva Contrast Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Contrast Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#controls {
position: absolute;
top: 20px;
left: 20px;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="controls">
contrast:
<input
id="contrast"
type="range"
min="-100"
max="100"
step="1"
value="0"
/>
</div>
<script>
Konva.Image.fromURL('../../../assets/lion.png', function (lion) {
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

lion.position({
x: 50,
y: 50,
});
lion.cache();
lion.filters([Konva.Filters.Contrast]);
layer.add(lion);
stage.add(layer);

var sliders = ['contrast'];
sliders.forEach(function (attr) {
var slider = document.getElementById(attr);
function update() {
lion[attr](parseFloat(slider.value));
}
slider.oninput = update;
update();
});
});
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/Custom_Filter.html b/docs/filters/Custom_Filter.html new file mode 100644 index 000000000..03fdf855b --- /dev/null +++ b/docs/filters/Custom_Filter.html @@ -0,0 +1,728 @@ + + + + + + HTML5 Canvas Custom Filter Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Custom Filter Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

How apply custom filter for Konva nodes?

This demo demonstrate how to use custom filters with Konva framework.

+

Filter is a function that have canvas ImageData as input and it should mutate it.

+
function Filter(imageData) {
// do something with image data
imageData.data[0] = 0;
}
+ +

For all available filters go to Filters Documentation.

+

Also take a look into Image Border Demo for custom filter example.

+

In this demo we will remove all transparency from the image..

+ + +
Konva Custom Filter Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Custom Filter Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();
stage.add(layer);

// lets define a custom filter:
var OpacityFilter = function (imageData) {
// make all pixels opaque 100%
var nPixels = imageData.data.length;
for (var i = 3; i < nPixels; i += 4) {
imageData.data[i] = 255;
}
};

Konva.Image.fromURL('/assets/lion.png', function (image) {
layer.add(image);
image.setAttrs({
x: 80,
y: 30,
borderSize: 5,
borderColor: 'red',
});

image.filters([OpacityFilter]);
image.cache();
});
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/Emboss.html b/docs/filters/Emboss.html new file mode 100644 index 000000000..96887da0b --- /dev/null +++ b/docs/filters/Emboss.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Emboss filter Image Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Emboss filter Image Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply filter to an Konva.Image, we have to cache it first with cache()
function. Then apply filter with filters() function.

+

Instructions: Slide the controls to change emboss values.

+

For all available filters go to Filters Documentation.

+ + +
Konva Emboss Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Emboss Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#controls {
position: absolute;
top: 20px;
left: 20px;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="controls">
Strength:
<input
id="Strength"
type="range"
min="0"
max="1"
step="0.1"
value="0.5"
/>
WhiteLevel:
<input
id="WhiteLevel"
type="range"
min="0"
max="1"
step="0.1"
value="0.5"
/>
Direction:
<select id="Direction">
<option value="top" selected>top</option>
<option value="top-left">top-left</option>
<option value="top-right">top-right</option>
<option value="left">left</option>
<option value="right">right</option>
<option value="bottom">bottom</option>
<option value="bottom-left">bottom-left</option>
<option value="bottom-right">bottom-right</option>
</select>
Blend:
<input id="Blend" type="checkbox" checked />
</div>
<script>
Konva.Image.fromURL('../../../assets/lion.png', function (lion) {
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

lion.position({
x: 50,
y: 50,
});
lion.cache();
lion.filters([Konva.Filters.Emboss]);
layer.add(lion);
stage.add(layer);

var sliders = ['Strength', 'WhiteLevel', 'Direction'];
sliders.forEach(function (attr) {
var slider = document.getElementById(attr);
function update() {
lion['emboss' + attr](slider.value);
console.log(slider.value);
}
slider.oninput = update;
update();
});
var slider = document.getElementById('Blend');
function update() {
lion.embossBlend(slider.checked);
console.log(slider.checked);
}
slider.onchange = update;
update();
});
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/Enhance.html b/docs/filters/Enhance.html new file mode 100644 index 000000000..34c08f827 --- /dev/null +++ b/docs/filters/Enhance.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Enhance Image Filter Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Enhance Image Filter Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply filter to an Konva.Image, we have to cache it first with cache()
function. Then apply filter with filters() function.

+

To enhance an image with Konva, we can use the Konva.Filters.Enhance filter
and set the enhance amount with the enhance property.

+

Instructions: Slide the control to adjust the enhance value.

+

For all available filters go to Filters Documentation.

+ + +
Konva Enhance Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Enhance Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#slider {
position: absolute;
top: 20px;
left: 20px;
}
</style>
</head>

<body>
<div id="container"></div>
<input id="slider" type="range" min="-1" max="1" step="0.01" value="20" />
<script>
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();
stage.add(layer);

Konva.Image.fromURL('/assets/lion.png', function (lion) {
lion.setAttrs({
x: 80,
y: 30,
enhance: 0.5,
draggable: true,
});
lion.cache();
lion.filters([Konva.Filters.Enhance]);
layer.add(lion);

var slider = document.getElementById('slider');
slider.oninput = function () {
lion.enhance(parseFloat(slider.value));
};
});
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/Grayscale.html b/docs/filters/Grayscale.html new file mode 100644 index 000000000..8d0952478 --- /dev/null +++ b/docs/filters/Grayscale.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Grayscale Image Filter Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Grayscale Image Filter Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply filter to an Konva.Image, we have to cache it first with cache() function. Then apply filter with filters() function.

+

To invert the colors of an image with Konva, we can use the
Konva.Filters.Grayscale filter.

+

For all available filters go to Filters Documentation.

+ + +
Konva Grayscale Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Grayscale Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
function loadImages(sources, callback) {
var images = {};
var loadedImages = 0;
var numImages = 0;
for (var src in sources) {
numImages++;
}
for (var src in sources) {
images[src] = new Image();
images[src].onload = function () {
if (++loadedImages >= numImages) {
callback(images);
}
};
images[src].src = sources[src];
}
}
function buildStage(images) {
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var lion = new Konva.Image({
image: images.lion,
x: 80,
y: 30,
draggable: true,
});

lion.cache();
lion.filters([Konva.Filters.Grayscale]);
layer.add(lion);
stage.add(layer);
}

var sources = {
lion: '/assets/lion.png',
};

loadImages(sources, buildStage);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/HSL.html b/docs/filters/HSL.html new file mode 100644 index 000000000..8c5fba0af --- /dev/null +++ b/docs/filters/HSL.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Hue, Saturation and Luminance filter Image Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Hue, Saturation and Luminance filter Image Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply filter to an Konva.Node, we have to cache it first with cache() function. Then apply filter with filters() function.

+

To change hue, saturation and luminance components of an image with Konva, we can use the `Konva.Filters.HSL.

+

Instructions: Slide the controls to change hsl values.

+

For all available filters go to Filters Documentation.

+ + +
Konva Hue, Saturation and Luminance Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva HSL Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#controls {
position: absolute;
top: 20px;
left: 20px;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="controls">
hue:
<input id="hue" type="range" min="0" max="259" step="1" value="150" />
saturation:
<input
id="saturation"
type="range"
min="-2"
max="10"
step="0.5"
value="0"
/>
luminance:
<input
id="luminance"
type="range"
min="-2"
max="2"
step="0.1"
value="0"
/>
</div>
<script>
Konva.Image.fromURL('../../../assets/lion.png', function (lion) {
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

lion.position({
x: 50,
y: 50,
});
lion.cache();
lion.filters([Konva.Filters.HSL]);
layer.add(lion);
stage.add(layer);

var sliders = ['hue', 'saturation', 'luminance'];
sliders.forEach(function (attr) {
var slider = document.getElementById(attr);
function update() {
lion[attr](parseFloat(slider.value));
}
slider.oninput = update;
update();
});
});
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/HSV.html b/docs/filters/HSV.html new file mode 100644 index 000000000..304cef608 --- /dev/null +++ b/docs/filters/HSV.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Hue, Saturation and Value filter Image Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Hue, Saturation and Value filter Image Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply filter to an Konva.Node, we have to cache it first with cache() function. Then apply filter with filters() function.

+

To change hue, saturation and value components of an image with Konva, we can use the Konva.Filters.HSV.

+

Instructions: Slide the controls to change hsv values.

+

For all available filters go to Filters Documentation.

+ + +
Konva Hue, Saturation and Value Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva HSV Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#controls {
position: absolute;
top: 20px;
left: 20px;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="controls">
hue:
<input id="hue" type="range" min="0" max="259" step="1" value="150" />
saturation:
<input
id="saturation"
type="range"
min="-2"
max="10"
step="0.5"
value="0"
/>
value:
<input id="value" type="range" min="-2" max="2" step="0.1" value="0" />
</div>
<script>
Konva.Image.fromURL('../../../assets/lion.png', function (lion) {
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

lion.position({
x: 50,
y: 50,
});
lion.cache();
lion.filters([Konva.Filters.HSV]);
layer.add(lion);
stage.add(layer);

var sliders = ['hue', 'saturation', 'value'];
sliders.forEach(function (attr) {
var slider = document.getElementById(attr);
function update() {
lion[attr](parseFloat(slider.value));
}
slider.oninput = update;
update();
});
});
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/Invert.html b/docs/filters/Invert.html new file mode 100644 index 000000000..598d3dc60 --- /dev/null +++ b/docs/filters/Invert.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Invert Image Filter Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Invert Image Filter Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply filter to an Konva.Image, we have to cache it first with cache() function. Then apply filter with filters() function.

+

To invert the colors of an image with Konva, we can use the
Konva.Filters.Invert filter.

+

For all available filters go to Filters Documentation.

+ + +
Konva Invert Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Invert Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
function loadImages(sources, callback) {
var images = {};
var loadedImages = 0;
var numImages = 0;
for (var src in sources) {
numImages++;
}
for (var src in sources) {
images[src] = new Image();
images[src].onload = function () {
if (++loadedImages >= numImages) {
callback(images);
}
};
images[src].src = sources[src];
}
}
function buildStage(images) {
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var lion = new Konva.Image({
image: images.lion,
x: 80,
y: 30,
draggable: true,
});

lion.cache();
lion.filters([Konva.Filters.Invert]);
layer.add(lion);
stage.add(layer);
}

var sources = {
lion: '/assets/lion.png',
};

loadImages(sources, buildStage);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/Kaleidoscope.html b/docs/filters/Kaleidoscope.html new file mode 100644 index 000000000..912e90110 --- /dev/null +++ b/docs/filters/Kaleidoscope.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Kaleidoscope Image Filter Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Kaleidoscope Image Filter Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply filter to an Konva.Image, we have to cache it first with cache()
function. Then apply filter with filters() function.

+

To create a kaleidoscope with Konva, we can use the Konva.Filters.Kaleidoscope
filter and set the kaleidoscopePower and kaleidoscopeAngle properties.

+

Instructions: Slide the control to adjust the kaleidoscope angle.

+

For all available filters go to Filters Documentation.

+ + +
Konva Kaleidoscope Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Kaleidoscope Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#slider {
position: absolute;
top: 20px;
left: 20px;
}
</style>
</head>

<body>
<div id="container"></div>
<input id="slider" type="range" min="0" max="360" step="5" value="20" />
<script>
function loadImages(sources, callback) {
var images = {};
var loadedImages = 0;
var numImages = 0;
for (var src in sources) {
numImages++;
}
for (var src in sources) {
images[src] = new Image();
images[src].onload = function () {
if (++loadedImages >= numImages) {
callback(images);
}
};
images[src].src = sources[src];
}
}
function buildStage(images) {
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var lion = new Konva.Image({
image: images.lion,
x: 80,
y: 30,
draggable: true,
});

lion.cache();
lion.filters([Konva.Filters.Kaleidoscope]);
lion.kaleidoscopePower(3);
layer.add(lion);
stage.add(layer);
var slider = document.getElementById('slider');
slider.oninput = function () {
lion.kaleidoscopeAngle(slider.value);
};
}

var sources = {
lion: '/assets/lion.png',
};

loadImages(sources, buildStage);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/Mask.html b/docs/filters/Mask.html new file mode 100644 index 000000000..e778f78d2 --- /dev/null +++ b/docs/filters/Mask.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Mask Image Filter Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Mask Image Filter Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply filter to an Konva.Image, we have to cache it first with cache() function. Then apply filter with filters() function.

+

To mark the colors of an image with Konva, we can use the
Konva.Filters.Mask filter.

+

For all available filters go to Filters Documentation.

+ + +
Konva Mask Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Mask Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#slider {
position: absolute;
top: 20px;
left: 20px;
}
</style>
</head>

<body>
<div id="container"></div>
<input id="slider" type="range" min="0" max="300" step="1" value="20" />
<script>
function loadImages(sources, callback) {
var images = {};
var loadedImages = 0;
var numImages = 0;
for (var src in sources) {
numImages++;
}
for (var src in sources) {
images[src] = new Image();
images[src].onload = function () {
if (++loadedImages >= numImages) {
callback(images);
}
};
images[src].src = sources[src];
}
}
function buildStage(images) {
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var vader = new Konva.Image({
image: images.vader,
x: 80,
y: 30,
threshold: 20,
draggable: true,
});

vader.cache();
vader.filters([Konva.Filters.Mask]);
layer.add(vader);
stage.add(layer);
var slider = document.getElementById('slider');
slider.oninput = function () {
vader.threshold(parseInt(slider.value, 10));
};
}

var sources = {
vader: '/assets/darth-vader.jpg',
};

loadImages(sources, buildStage);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/Multiple_Filters.html b/docs/filters/Multiple_Filters.html new file mode 100644 index 000000000..79f8f760f --- /dev/null +++ b/docs/filters/Multiple_Filters.html @@ -0,0 +1,723 @@ + + + + + + HTML5 Canvas Multiple Filters Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Multiple Filters Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply multiple filters to an Konva.Image, we have to cache it first with cache()
function. Then apply filters with filter() function.

+

For all available filters go to Filters Documentation.

+ + +
Konva Multiple Filters Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Multiple Filters Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#slider {
position: absolute;
top: 20px;
left: 20px;
}
</style>
</head>

<body>
<div id="container"></div>
<input id="slider" type="range" min="0" max="40" step="0.05" value="20" />
<script>
function loadImages(sources, callback) {
var images = {};
var loadedImages = 0;
var numImages = 0;
for (var src in sources) {
numImages++;
}
for (var src in sources) {
images[src] = new Image();
images[src].onload = function () {
if (++loadedImages >= numImages) {
callback(images);
}
};
images[src].src = sources[src];
}
}
function buildStage(images) {
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var lion = new Konva.Image({
image: images.lion,
x: 80,
y: 30,
blurRadius: 20,
draggable: true,
});

lion.cache();
lion.filters([Konva.Filters.Blur, Konva.Filters.Invert]);
layer.add(lion);
stage.add(layer);
var slider = document.getElementById('slider');
slider.oninput = function () {
lion.blurRadius(slider.value);
};
}

var sources = {
lion: '/assets/lion.png',
};

loadImages(sources, buildStage);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/Noise.html b/docs/filters/Noise.html new file mode 100644 index 000000000..50b7552ea --- /dev/null +++ b/docs/filters/Noise.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Noise filter Image Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Noise filter Image Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply filter to an Konva.Node, we have to cache it first with cache()
function. Then apply filter with filters() function.

+

To change noise of an image with Konva, we can use the Konva.Filters.Noise.

+

Instructions: Slide the control to change noise value.

+

For all available filters go to Filters Documentation.

+ + +
Konva Noise Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Noise Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#controls {
position: absolute;
top: 20px;
left: 20px;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="controls">
noise:
<input id="noise" type="range" min="0" max="4" step="0.1" value="0.8" />
</div>
<script>
Konva.Image.fromURL('../../../assets/lion.png', function (lion) {
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

lion.position({
x: 50,
y: 50,
});
lion.cache();
lion.filters([Konva.Filters.Noise]);
layer.add(lion);
stage.add(layer);

var sliders = ['noise'];
sliders.forEach(function (attr) {
var slider = document.getElementById(attr);
function update() {
lion[attr](parseFloat(slider.value));
}
slider.oninput = update;
update();
});
});
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/Pixelate.html b/docs/filters/Pixelate.html new file mode 100644 index 000000000..1a8dd5438 --- /dev/null +++ b/docs/filters/Pixelate.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Pixelate filter Image Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Pixelate filter Image Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply filter to an Konva.Node, we have to cache it first with cache()
function. Then apply filter with filters() function.

+

To change pixelate effect of an image with Konva, we can use the Konva.Filters.Pixelate.

+

Instructions: Slide the control to change pixel size value.

+

For all available filters go to Filters Documentation.

+ + +
Konva Pixelate Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Pixelate Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#controls {
position: absolute;
top: 20px;
left: 20px;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="controls">
pixelSize:
<input id="pixelSize" type="range" min="1" max="20" step="1" value="4" />
</div>
<script>
Konva.Image.fromURL('../../../assets/lion.png', function (lion) {
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

lion.position({
x: 50,
y: 50,
});
lion.cache();
lion.filters([Konva.Filters.Pixelate]);
layer.add(lion);
stage.add(layer);

var sliders = ['pixelSize'];
sliders.forEach(function (attr) {
var slider = document.getElementById(attr);
function update() {
lion[attr](parseFloat(slider.value));
}
slider.oninput = update;
update();
});
});
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/RGB.html b/docs/filters/RGB.html new file mode 100644 index 000000000..6a5ca25df --- /dev/null +++ b/docs/filters/RGB.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas RGB filter Image Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas RGB filter Image Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply filter to an Konva.Image, we have to cache it first with cache()
function. Then apply filter with filters() function.

+

To change rgb components of an image with Konva, we can use the `Konva.Filters.RGB.

+

Instructions: Slide the controls to change rgb values.

+

For all available filters go to Filters Documentation.

+ + +
Konva RGB Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva RGB Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#controls {
position: absolute;
top: 20px;
left: 20px;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="controls">
Red:
<input id="red" type="range" min="0" max="256" step="1" value="150" />
Green:
<input id="green" type="range" min="0" max="256" step="1" value="150" />
Blue:
<input id="blue" type="range" min="0" max="256" step="1" value="150" />
</div>
<script>
Konva.Image.fromURL('../../../assets/lion.png', function (lion) {
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

lion.position({
x: 50,
y: 50,
});
lion.cache();
lion.filters([Konva.Filters.RGB]);
layer.add(lion);
stage.add(layer);

var sliders = ['red', 'green', 'blue'];
sliders.forEach(function (attr) {
var slider = document.getElementById(attr);
function update() {
lion[attr](parseFloat(slider.value));
}
slider.oninput = update;
update();
});
});
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/filters/RGBA.html b/docs/filters/RGBA.html new file mode 100644 index 000000000..ed5c48fc2 --- /dev/null +++ b/docs/filters/RGBA.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas RGBA filter Image Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas RGBA filter Image Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply filter to an Konva.Image, we have to cache it first with cache()
function. Then apply filter with filters() function.

+

To change rgba components of an image with Konva, we can use the Konva.Filters.RGBA.

+

Instructions: Slide the controls to change rgba values.

+

For all available filters go to Filters Documentation.

+ + +
Konva RGBA Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva RGBA Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#controls {
position: absolute;
top: 20px;
left: 20px;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="controls">
Red:
<input id="red" type="range" min="0" max="256" step="1" value="150" />
Green:
<input id="green" type="range" min="0" max="256" step="1" value="150" />
Blue:
<input id="blue" type="range" min="0" max="256" step="1" value="150" />
Alpha:
<input id="alpha" type="range" min="0" max="1" step="0.05" value="0.5" />
</div>
<script>
Konva.Image.fromURL('../../../assets/lion.png', function (lion) {
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

lion.position({
x: 50,
y: 50,
});
lion.cache();
lion.filters([Konva.Filters.RGBA]);
layer.add(lion);
stage.add(layer);

var sliders = ['red', 'green', 'blue', 'alpha'];
sliders.forEach(function (attr) {
var slider = document.getElementById(attr);
function update() {
lion[attr](parseFloat(slider.value));
}
slider.oninput = update;
update();
});
});
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/groups_and_layers/Change_Containers.html b/docs/groups_and_layers/Change_Containers.html new file mode 100644 index 000000000..d684fda62 --- /dev/null +++ b/docs/groups_and_layers/Change_Containers.html @@ -0,0 +1,723 @@ + + + + + + HTML5 Canvas Move Shape to Another Container Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Move Shape to Another Container Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To move a shape from one container into another with Konva, we can use the
moveTo() method which requires a container as a parameter.
A container can be another stage, a layer, or a group. You can also move groups
into other groups and layers, or shapes from groups directly into other layers.

+

Instructions: Drag and drop the groups and observe that the red rectangle is
bound to either the yellow group or the blue group.
Use the buttons on the left to move the box from one group into another.

+ + +
Konva Move Shape to Another Container Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Move Shape to Another Container Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
#buttons {
position: absolute;
left: 10px;
top: 0;
}
button {
margin-top: 10px;
display: block;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="buttons">
<button id="toBlue">Move red box to blue group</button>
<button id="toYellow">Move red box to yellow group</button>
</div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
var yellowGroup = new Konva.Group({
x: 100,
y: 100,
draggable: true,
});
var blueGroup = new Konva.Group({
x: 300,
y: 80,
draggable: true,
});

var box = new Konva.Rect({
x: 10,
y: 10,
width: 100,
height: 50,
fill: 'red',
stroke: 'black',
});

var yellowCircle = new Konva.Circle({
x: 0,
y: 0,
radius: 50,
fill: 'yellow',
stroke: 'black',
});

var blueCircle = new Konva.Circle({
x: 0,
y: 0,
radius: 50,
fill: 'blue',
stroke: 'black',
});

// build node tree
yellowGroup.add(yellowCircle);
yellowGroup.add(box);
blueGroup.add(blueCircle);
layer.add(yellowGroup);
layer.add(blueGroup);
stage.add(layer);

// add button event bindings
document.getElementById('toBlue').addEventListener(
'click',
function () {
box.moveTo(blueGroup);
},
false
);

document.getElementById('toYellow').addEventListener(
'click',
function () {
box.moveTo(yellowGroup);
},
false
);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/groups_and_layers/Groups.html b/docs/groups_and_layers/Groups.html new file mode 100644 index 000000000..df9943673 --- /dev/null +++ b/docs/groups_and_layers/Groups.html @@ -0,0 +1,722 @@ + + + + + + HTML5 Canvas Shape Groups | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Shape Groups

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To group multiple shapes together with Konva, we can instantiate
a Konva.Group() object and then add shapes to it with the add() method.
Grouping shapes together is really handy when we want to transform multiple
shapes together, e.g. if we want to move, rotate, or scale multiple shapes
at once. Groups can also be added to other groups to create more complex
Node trees. For a full list of attributes and methods, check out the Konva.Group documentation.

+ + +
Konva Groups Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Groups Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

/*
* create a group which will be used to combine
* multiple simple shapes. Transforming the group will
* transform all of the simple shapes together as
* one unit
*/
var group = new Konva.Group({
x: 120,
y: 40,
rotation: 20,
});

var colors = ['red', 'orange', 'yellow'];

for (var i = 0; i < 3; i++) {
var box = new Konva.Rect({
x: i * 30,
y: i * 18,
width: 100,
height: 50,
name: colors[i],
fill: colors[i],
stroke: 'black',
strokeWidth: 4,
});

group.add(box);
}

layer.add(group);
stage.add(layer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/groups_and_layers/Layering.html b/docs/groups_and_layers/Layering.html new file mode 100644 index 000000000..3f924f0ff --- /dev/null +++ b/docs/groups_and_layers/Layering.html @@ -0,0 +1,723 @@ + + + + + + HTML5 Canvas Shape Layering | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Shape Layering

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To layer shapes with Konva, we can use one of the following layering methods:
moveToTop(), moveToBottom(), moveUp(), moveDown(), or zIndex().
You can also layer groups and layers.

+

Instructions: Drag and drop the boxes to move them around, and then use the
buttons on the left to reorder the yellow box.

+ + +
Konva Shape Layering Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Shape Layering Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
#buttons {
position: absolute;
left: 10px;
top: 0px;
}
button {
margin-top: 10px;
display: block;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="buttons">
<button id="toTop">Move yellow box to top</button>
<button id="toBottom">Move yellow box to bottom</button>
<button id="up">Move yellow box up</button>
<button id="down">Move yellow box down</button>
<button id="zIndex">Set yellow box zIndex to 3</button>
</div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
var offsetX = 0;
var offsetY = 0;
var colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'];
var yellowBox = null;

for (var n = 0; n < 6; n++) {
// anonymous function to induce scope
(function () {
var i = n;
var box = new Konva.Rect({
x: i * 30 + 210,
y: i * 18 + 40,
width: 100,
height: 50,
fill: colors[i],
stroke: 'black',
strokeWidth: 4,
draggable: true,
name: colors[i],
});

box.on('mouseover', function () {
document.body.style.cursor = 'pointer';
});
box.on('mouseout', function () {
document.body.style.cursor = 'default';
});
if (colors[i] === 'yellow') {
yellowBox = box;
}
layer.add(box);
})();
}

stage.add(layer);

// add button event bindings
document.getElementById('toTop').addEventListener(
'click',
function () {
yellowBox.moveToTop();
},
false
);

document.getElementById('toBottom').addEventListener(
'click',
function () {
yellowBox.moveToBottom();
},
false
);

document.getElementById('up').addEventListener(
'click',
function () {
yellowBox.moveUp();
},
false
);

document.getElementById('down').addEventListener(
'click',
function () {
yellowBox.moveDown();
},
false
);

document.getElementById('zIndex').addEventListener(
'click',
function () {
yellowBox.setZIndex(3);
},
false
);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/groups_and_layers/zIndex.html b/docs/groups_and_layers/zIndex.html new file mode 100644 index 000000000..f95114f17 --- /dev/null +++ b/docs/groups_and_layers/zIndex.html @@ -0,0 +1,739 @@ + + + + + + How to set correct order of nodes using zIndex? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to set correct order of nodes using zIndex?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

What is zIndex of a node?

You can get/set zIndex of a node in this way:

+
// get
const zIndex = shape.zIndex();

// set
shape.zIndex(1);
+ +

zIndex is just index of a node in its parent children array. Please don’t confuse zIndex in Konva with z-index in CSS.

+
const group = new Konva.Group();

const circle = new Konva.Circle({});

group.add(circle);

// it will log 0.
console.log(circle.zIndex());

// the next line will not work. Because the group have only one child
circle.zIndex(1);

// still logs 0
console.log(circle.zIndex());

// for any node that equations will be true:
console.log(circle.zIndex() === circle.getParent().children.indexOf(circle))
+ + +

You can’t use zIndex to set absolute position of the node, like we do this in CSS.
Konva is drawing nodes in the strict order as they defined in nodes tree.

+

Let make a demo. I will create a layer with two groups. The first group has two shapes (black rect and red circle). The second group has one shape (green rect).

+ + +
Show source code! +

+

Konva ZIndex demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Shape Layering Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

// create first group with two shapes
var group1 = new Konva.Group();
layer.add(group1);

var blackRect = new Konva.Rect({
x: 20,
y: 20,
fill: 'black',
width: 100,
height: 100,
});
group1.add(blackRect);

var redCircle = new Konva.Circle({
x: 70,
y: 70,
fill: 'red',
radius: 30,
});
group1.add(redCircle);

// now the red circle on on top of black rectangle
// we can change its zIndex with:
redCircle.zIndex(0);

// if we what to move it back to the top we can change its zIndex again
// or we can change zIndex of black rectangle:
blackRect.zIndex(0);
// after that zIndex of red circle will be changed back to 1:
console.log('red circle index: ' + redCircle.zIndex());

// crete second group with one shape
var group2 = new Konva.Group();
layer.add(group2);

var greenRect = new Konva.Rect({
x: 70,
y: 70,
width: 100,
height: 100,
fill: 'green',
});
group2.add(greenRect);
</script>
</body>
</html>
+

+
+ +

What is zIndex of red circle. It is 1 (second element in array of children of the first group).
What is zIndex of green rect? It is 0.

+

Red circle has higher zIndex than green rect. But why we see green rect above red circle? As mentioned above Konva is drawing in strict order of the tree.
So at first it will draw all children of the first group. Then above that picture it will draw all children of the second group (and so on if we have more elements in the layer).

+

How to draw red circle above green rect? You can move it into the second group. Or you can move it into the layer and make sure it has larger zIndex than previous groups.

+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/how_it_works.html b/docs/how_it_works.html new file mode 100644 index 000000000..423e0b1c7 --- /dev/null +++ b/docs/how_it_works.html @@ -0,0 +1,725 @@ + + + + + + How It Works | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How It Works

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

Konva stages are made up of user defined layers.
Each layer has two canvas renderers, a scene renderer and a hit graph renderer.
The scene renderer is what you can see, and the hit graph renderer is a special hidden
canvas that’s used for high performance event detection.

+

Each layer can contain shapes, groups of shapes, or groups of other groups.
The stage, layers, groups, and shapes are virtual nodes, similar to DOM nodes in an HTML page.
Here’s an example Node hierarchy:

+
              Stage
|
+------+------+
| |
Layer Layer
| |
+-----+-----+ Shape
| |
Group Group
| |
+ +---+---+
| | |
Shape Group Shape
|
+
|
Shape
+ +

All nodes can be styled and transformed. Although Konva has prebuilt shapes available,
such as rectangles, circles, images, sprites, text, lines, polygons, regular polygons, paths, stars, etc.,
you can also create custom shapes by instantiating the Shape class and creating a draw function.

+

Once you have a stage set up with layers and shapes,
you can bind event listeners, transform nodes, run animations,
apply filters, and much more.

+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 000000000..7dc0db005 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,734 @@ + + + + + + Starting with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Starting with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

What’s Konva?

Konva is an HTML5 Canvas JavaScript framework that extends the 2d context
by enabling canvas interactivity for desktop and mobile applications.

+

Konva enables high performance animations, transitions, node nesting, layering, filtering,
caching, event handling for desktop and mobile applications, and much more.

+

You can draw things onto the stage, add event listeners to them, move them,
scale them, and rotate them independently from other shapes to support high performance
animations, even if your application uses thousands of shapes.

+

This project began as a GitHub fork of KineticJS.

+

Install Konva

If you are using package managers:

+
npm install konva
+ +

Or just use script tag:

+
<script src="https://unpkg.com/konva@9/konva.min.js"></script>
+ +

Or download from CDN:

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/overview.html b/docs/overview.html new file mode 100644 index 000000000..06e0c3d12 --- /dev/null +++ b/docs/overview.html @@ -0,0 +1,782 @@ + + + + + + Konva Framework Overview | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Konva Framework Overview

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

What’s Konva?

Konva is an HTML5 Canvas JavaScript framework that extends the 2d context
by enabling canvas interactivity for desktop and mobile applications.

+

Konva enables high performance animations, transitions, node nesting, layering, filtering,
caching, event handling for desktop and mobile applications, and much more.

+

How does it work?

Every thing starts from Konva.Stage that contains several user’s layers (Konva.Layer).

+

Each layer has two <canvas> renderers: a scene renderer and a hit graph renderer.
The scene renderer is what you can see, and the hit graph renderer is a special hidden
canvas that’s used for high performance event detection.

+

Each layer can contain shapes, groups of shapes, or groups of other groups.
The stage, layers, groups, and shapes are virtual nodes, similar to DOM nodes in an HTML page.

+

Here’s an example Node hierarchy:

+
              Stage
|
+------+------+
| |
Layer Layer
| |
+-----+-----+ Shape
| |
Group Group
| |
+ +---+---+
| | |
Shape Group Shape
|
+
|
Shape
+ +

All nodes can be styled and transformed. Although Konva has prebuilt shapes available,
such as rectangles, circles, images, sprites, text, lines, polygons, regular polygons, paths, stars, etc.,
you can also create custom shapes by instantiating the Shape class and creating a draw function.

+

Once you have a stage set up with layers and shapes,
you can bind event listeners, transform nodes, run animations,
apply filters, and much more.

+

Minimal code example:

+
// first we need to create a stage
var stage = new Konva.Stage({
container: 'container', // id of container <div>
width: 500,
height: 500
});

// then create layer
var layer = new Konva.Layer();

// create our shape
var circle = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4
});

// add the shape to the layer
layer.add(circle);

// add the layer to the stage
stage.add(layer);

// draw the image
layer.draw();
+

Result:
Minimal code demo

+

Basic shapes

Konva.js supports shapes: Rect, Circle, Ellipse, Line, Polygon, Spline, Blob, Image, Text, TextPath, Star, Label, SVG Path, RegularPolygon.
Also you can create custom shape:

+
var triangle = new Konva.Shape({
sceneFunc: function(context) {
context.beginPath();
context.moveTo(20, 50);
context.lineTo(220, 80);
context.quadraticCurveTo(150, 100, 260, 170);
context.closePath();

// special Konva.js method
context.fillStrokeShape(this);
},
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4
});
+

Custom shape

+

Styles

Each shape supports the following style properties:

+
    +
  • Fill. Solid color, gradients or images
  • +
  • Stroke (color, width)
  • +
  • Shadow (color, offset, opacity, blur)
  • +
  • Opacity
  • +
+
var pentagon = new Konva.RegularPolygon({
x: stage.width() / 2,
y: stage.height() / 2,
sides: 5,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
shadowOffsetX : 20,
shadowOffsetY : 25,
shadowBlur : 40,
opacity : 0.5
});
+

Styles

+

Events

With Konva you can easily listen to user input events (click, dblclick, mouseover, tap, dbltap, touchstart etc),
attributes change events (scaleXChange, fillChange) and drag&drop events (dragstart, dragmove, dragend).

+
circle.on('mouseout touchend', function() {
console.log('user input');
});

circle.on('xChange', function() {
console.log('position change');
});

circle.on('dragend', function() {
console.log('drag stopped');
});
+

See working example.

+

DRAG AND DROP

Konva has builtin drag support. For the current moment there is no drop events (drop, dragenter, dragleave, dragover)
but it is very easy to implement them via framework.

+

To enable drag&drop just set property draggable = true.

+
shape.draggable('true');
+ +

Then you can subscribe to drag&drop events and setup moving limits.

+

Filters

Konva has several filters: blur, invert, noise etc. For all available filters see Filters API.

+

Example:
Filter

+

Animation

You can create animations in two ways:

+
    +
  1. via Konva.Animation Demo:

    +
    var anim = new Konva.Animation(function(frame) {
    var time = frame.time,
    timeDiff = frame.timeDiff,
    frameRate = frame.frameRate;
    // update stuff
    }, layer);
    anim.start();
    +
  2. +
  3. via Konva.Tween Demo:

    +
    var tween = new Konva.Tween({
    node: rect,
    duration: 1,
    x: 140,
    rotation: Math.PI * 2,
    opacity: 1,
    strokeWidth: 6
    });
    tween.play();

    // or new shorter method:
    circle.to({
    duration : 1,
    fill : 'green'
    });
    + +
  4. +
+

Selectors

It is very useful to use searching in elements when you are building large application.
Konva helps you to find an element with selectors. You can use find() method (returns collection) or findOne() method (return first element of collection).

+
var circle = new Konva.Circle({
radius: 10,
fill: 'red',
id : 'face',
name : 'red circle'
});
layer.add(circle);

// then try to search

// find by type
layer.find('Circle'); // returns array of all circles

// find by id
layer.findOne('#face');

// find by name (like css class)
layer.find('.red')
+ +

Serialisation and Deserialization

All created objects you can save as JSON. You may save it to server or local storage.

+
var json = stage.toJSON();
+

Also you can restore objects from JSON:

+
var json = '{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{"x":100,"y":100,"sides":6,"radius":70,"fill":"red","stroke":"black","strokeWidth":4},"className":"RegularPolygon"}]}]}';

var stage = Konva.Node.create(json, 'container');
+ +

Performance

Konva has a lot of tools to improve speed of your app. Most important methods:

+
    +
  1. Caching allows you to draw an element into buffer canvas. Then draw element from the canvas. It may improve performance a lot for complex nodes such as text or shapes with shadow and strokes.

    +
    shape.cache();
    +

    Demo

    +
  2. +
  3. Layering. As framework supports several <canvas> elements you can put objects at your discretion.
    For example your application consists from complex background and several moving shapes. You can use one layer for background and another one for shapes.
    While updating shapes you don’t need to update background canvas. Demo

    +
  4. +
+

You can find all available performance tips here:
https://konvajs.org/docs/performance/All_Performance_Tips.html

+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/performance/All_Performance_Tips.html b/docs/performance/All_Performance_Tips.html new file mode 100644 index 000000000..eee2ec2c6 --- /dev/null +++ b/docs/performance/All_Performance_Tips.html @@ -0,0 +1,762 @@ + + + + + + HTML5 Canvas All Konva performance tips list | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas All Konva performance tips list

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

HTML5 Canvas All Konva performance tips list

Don’t want to spend your time with performance issues? Request a performance review.

+

Why this is important

The HTML5 canvas is efficient at what it does and internally Konva has many features that aim to provide great performance. However, when your project starts to grow in complexity, or when you just have a lot of shapes on the stage, there must inevitably be some negative performance impact.

+

Optimization targets

The optimizations here focus on two general rules:

+
    +
  • Compute as little as possible: all computation takes time to complete. Each individual computation may run in a tiny fraction of a second, but the thousands or millions of computations caused by your code, Konva, JavaScript, and the layers below that, will add up to something more observable by the human eye if that super-slick animation or effect is, in fact, jerky.

    +
  • +
  • Draw as little as possible: this is important because all drawing has a performance cost. There are two categories of cost - firstly the computation of the drawing which we covered in the point above, and then the movement of the drawing from memory to the screen. Depending on the case, there may also be intermediate off-screen compositing or per-pixel processing. The rule is therefore do as little drawing as possible.

    +
  • +
+

The Stage

    +
  1. Optimise stage size - following the rule of ‘draw as little as possible’, try to avoid creating a large stage because moving all those bytes from memory to screen is going to have a negative impact. There are some tips here that offer alternative approaches to the mega-stage problem!

    +
  2. +
  3. Set a viewport on mobile - Scaling images is a significant performance hit, so for mobile applications set viewport: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> which will avoid unnecessary scaling of your Konva output.

    +
  4. +
  5. Use Konva.pixelRatio = 1 on retina devices - Konva automatically handles pixel ratio adjustments in order to render crisp drawings on all devices. But, just in case you have bad performance on retina devices, set Konva.pixelRatio = 1 to reduce the scaling work Konva has to do. This setting might affect the output in some cases, so make sure that quality of the result is ok for you.

    +
  6. +
+

Layers

    +
  1. Layer Management - under the hood, each Konva layer is a separate HTML5 canvas element which gives some useful capabilities, including the ability to refresh only a layer that changed and so avoid the performance cost of refreshing the entire stage. But with great power great responsibility comes, and each layer has an incremental performance overhead so we should keep the number of layers to a minimum.

    +
  2. +
  3. Use layer.listening(false) - Konva gives us mouse and touch event listeners on all the shapes we draw. But there is a performance cost for each one, and for a layer with many shapes Konva has to expend many cycles checking which listeners might be triggered. If you have a layer on which none of the shapes need to react to events, take this burden away by setting layer.listening(false). See Demo. There is a similar point in the shapes section.

    +
  4. +
  5. Optimise dragging costs - while you drag a shape across a layer that layer must be redrawn per cycle of the move event listener. To avoid this performance cost, move the shape to a dedicated layer while dragging, then move it back to original layer at drag end. See Demo

    +
  6. +
+

Shapes

    +
  1. Shape Caching - internally Konva makes an image of your shape and uses that when the shape has to be drawn. Drawing images avoids the overhead of composing the shape from its drawing instructions, and can increase performance impressively for complex shapes and groups.

    +
  2. +
  3. Keep the shapes tidy - each shape in your stage has a cost just to exist. To optimise performance, hide or remove from the layer any objects that become invisible / opacity = 0, or objects that go out of view.

    +
  4. +
  5. Use shape.listening(false) - as with layers (see point 7 above), Konva looks out for when events should be triggered for shapes, which has a performance cost. Telling a shape to stop listening for events reduces this cost, as explained at Listening false.

    +
  6. +
  7. Switch off perfect drawing - In some cases the result of drawing with the HTML5 canvas is not what you might have expected - see the demo for an example Disable Perfect Drawing. Konva does extra work via its perfect drawing feature to put that right, but this comes with a performance cost. By setting shape.perfectDrawEnabled(false) this cost can be avoided, with no reduction in output quality, when a shape has fill, stroke and opacity.

    +
  8. +
  9. Optimize Stroke Drawing - To achieve drawing results that look as expected, Konva makes an extra internal drawing when a shape has both stroke and shadow. Avoid this performance burden by switching off the shadow that Konva adds for the stroke.

    +
  10. +
+

Animations

    +
  1. Optimize Animation - Avoiding unnecessary redraw costs for animation steps that fall between visual changes.
  2. +
+

Memory

    +
  1. Avoid Memory Leaks - Konva looks after a lot of cases where you might make memory leaks, but bringing shapes and tweens into the world and managing their exit is an area where you can help.
  2. +
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/performance/Avoid_Memory_Leaks.html b/docs/performance/Avoid_Memory_Leaks.html new file mode 100644 index 000000000..baf5aa673 --- /dev/null +++ b/docs/performance/Avoid_Memory_Leaks.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas How to avoid Memory leaks Tip | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas How to avoid Memory leaks Tip

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

Deleting shapes

There are two very close methods remove() and destroy(). If you need to completely delete a node you should destroy() it. The destroy() method deletes all references to node from the KonvaJS engine. If you are going to reuse a node you should remove() it then later you can add it again to any container.

+

Tweening

When you are using Konva.Tween instance you have to destroy it after usage.

+
var tween = new Konva.Tween({
node : circle,
x : 0,
duration : 0.5,
onFinish : function() {
// remove all references from Konva
tween.destroy();
}
});
tween.play();
+ +

Or if you don’t need to reuse the tween you can use the new to() method:

+
// the tween will be automatically started and destroyed on finish
circle.to({
x : 0,
duration : 0.5
});
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/performance/Batch_Draw.html b/docs/performance/Batch_Draw.html new file mode 100644 index 000000000..3fa8fb7d1 --- /dev/null +++ b/docs/performance/Batch_Draw.html @@ -0,0 +1,727 @@ + + + + + + HTML5 Canvas Batch Draw Tip | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Batch Draw Tip

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

Update: this demo is not relevant with the new konva@8. In the new version, Konva is doing all batching draws automatically on any changes on canvas.

+

The demo may be still relevant if you use Konva.autoDrawEnabled = false.

+

In some situations, we may want to update a Konva shape as fast as possible,
but without causing too many redraws. For example, if we want to update an
element on the stage via mousemove, we don’t want to redraw the layer with the
draw() method, because the mousemove event could be fired hundreds of times per
second, which would result in a forced frame rate of over a hundred frames per second.
Often times this can cause jumpy animations because browsers simply can’t handle excessive redraws.

+

For situations like this, it’s much better to use the batchDraw() method
which automatically hooks redraws into the Konva animation engine.
No matter how many times you call batchDraw(), Konva will automatically
limit the number of redraws per second based on the maximum number of frames
per second that the browser can handle at any given point in time.

+

Instructions: Move your mouse over the stage to spin the rectangle

+ + +
Konva Batch Draw Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Batch Draw Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
// disable auto draw for the demo
// most applications don't need that
Konva.autoDrawEnabled = false;

var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var rect = new Konva.Rect({
x: 110,
y: 100,
width: 200,
height: 20,
offset: {
x: 100,
y: 10,
},
fill: 'green',
stroke: 'black',
strokeWidth: 4,
});

// add the shape to the layer
layer.add(rect);

// add the layer to the stage
stage.add(layer);

stage.on('mousemove', function () {
rect.rotate(5);
layer.batchDraw();
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/performance/Disable_Perfect_Draw.html b/docs/performance/Disable_Perfect_Draw.html new file mode 100644 index 000000000..5371e70b4 --- /dev/null +++ b/docs/performance/Disable_Perfect_Draw.html @@ -0,0 +1,735 @@ + + + + + + HTML5 Canvas Disable Perfect Drawing Tip | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Disable Perfect Drawing Tip

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

In some case drawing on canvas has unexpected result.
For example let’s draw shape with fill, stroke and opacity.
As stroke are drawn on top of fill. There’s a line of half the size of the stroke inside the shape which is darker
because it’s the intersection of the fill and the stroke.

+

Probably that is not expected for you. So Konva fixes such behavior with using buffer canvas.

+

In this case Konva is doing these:

+
    +
  1. Draw shape on buffer canvas
  2. +
  3. Fill and stroke it WITHOUT opacity
  4. +
  5. Apply opacity on layer’s canvas
  6. +
  7. Then draw on layer canvas result from buffer
  8. +
+

But using buffer canvas might drop performance. So you can disable such fixing:

+
shape.perfectDrawEnabled(false);
+ +

See difference here:

+ + +
Konva Disable Perfect Drawing Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Disable Perfect Drawing Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var group1 = new Konva.Group({
x: 50,
y: 50,
});
layer.add(group1);
var lebel1 = new Konva.Text({
text: 'Shape with default drawing behaviour',
});
group1.add(lebel1);
var rect = new Konva.Rect({
y: 20,
width: 100,
height: 50,
fill: 'green',
stroke: 'black',
strokeWidth: 10,
opacity: 0.5,
});
group1.add(rect);

var group1 = new Konva.Group({
x: 200,
y: 100,
});
layer.add(group1);
var lebel1 = new Konva.Text({
text: 'Shape with perfectDrawEnabled = false',
});
group1.add(lebel1);
var rect = new Konva.Rect({
y: 20,
width: 100,
height: 50,
fill: 'green',
stroke: 'black',
strokeWidth: 10,
opacity: 0.5,
perfectDrawEnabled: false,
});
group1.add(rect);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/performance/Layer_Management.html b/docs/performance/Layer_Management.html new file mode 100644 index 000000000..8e46010db --- /dev/null +++ b/docs/performance/Layer_Management.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Layer Management Performance Tip | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Layer Management Performance Tip

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

When creating Konva applications, the most important thing to consider,
in regards to performance, is layer management. One of the things that makes
Konva stand out from other canvas libraries is that it enables us to create
individual layers, each with their own canvas elements. This means that we can
animate, transition, or update some stage elements, while not redrawing others.
If we inspect the DOM of a Konva stage, we’ll see that there is actually one
canvas element per layer.

+

This tutorial has two layers, one layer that’s animated, and another static layer
that contains text. Since there’s no reason to continually redraw the text, it’s placed in its own layer.

+

Note: Do not create too many layers. Usually 3-5 is max.

+ + +
Konva Layer Management Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Layer Management Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>

<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var animLayer = new Konva.Layer();
var staticLayer = new Konva.Layer();

/*
* leave center point positioned
* at the default which is at the center
* of the hexagon
*/

var blueHex = new Konva.RegularPolygon({
x: 50,
y: stage.height() / 2,
sides: 6,
radius: 40,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
draggable: true,
});

var yellowHex = new Konva.RegularPolygon({
x: stage.width() / 2,
y: stage.height() / 2,
sides: 6,
radius: 30,
fill: 'yellow',
stroke: 'black',
strokeWidth: 4,
draggable: true,
});

/*
* move center point to right side
* of hexagon
*/
var redHex = new Konva.RegularPolygon({
x: 250,
y: stage.height() / 2,
sides: 6,
radius: 30,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
offset: {
x: 30,
y: 0,
},
draggable: true,
});

var text = new Konva.Text({
x: 10,
y: 10,
text: 'Static Layer',
fontSize: '30',
fontFamily: 'Calibri',
fill: 'black',
});

staticLayer.add(text);

animLayer.add(blueHex, yellowHex, redHex);
stage.add(animLayer, staticLayer);

var period = 2000;
var anim = new Konva.Animation(function (frame) {
var scale = Math.sin((frame.time * 2 * Math.PI) / period) + 0.001;
// scale x and y
blueHex.scale({ x: scale, y: scale });
// scale only y
yellowHex.scaleY(scale);
// scale only x
redHex.scaleX(scale);
}, animLayer);

anim.start();
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/performance/Listening_False.html b/docs/performance/Listening_False.html new file mode 100644 index 000000000..99e18488f --- /dev/null +++ b/docs/performance/Listening_False.html @@ -0,0 +1,725 @@ + + + + + + Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

title: Disable Listening Shapes Tip

You can set listening(false) to shape to remove it from hit graph. It means that shape will be invisible for hit detection (while visible on the canvas), so they never trigger any interactions with mouse or touch. Also such nodes will be ignored in container.getIntersection() and container.getAllIntersections() methods.

+

Setting listening(false) to nodes will increase performance.

+

For example we have a button (group) with rectangle and text. We need to listen click on button.
It this case we can remove text from hit graph and listen click only from rectangle.

+ + +
Konva Disable Listening Shapes Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Listening False Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var layer = new Konva.Layer();

var button = new Konva.Group({
x: stage.width() / 2,
y: stage.height() / 2,
});

var offset = 10;
var text = new Konva.Text({
x: offset,
y: offset,
text: 'press me!',
// as we don't really need text on hit graph we can set:
listening: false,
});
var rect = new Konva.Rect({
width: text.width() + offset * 2,
height: text.height() + offset * 2,
fill: 'grey',
shadowColor: 'black',
});
button.add(rect, text);

button.on('click tap', function () {
alert('button clicked');
});

layer.add(button);
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/performance/Optimize_Animation.html b/docs/performance/Optimize_Animation.html new file mode 100644 index 000000000..6f53a5ebe --- /dev/null +++ b/docs/performance/Optimize_Animation.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Optimize Animation Performance Tip | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Optimize Animation Performance Tip

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

If you animation have frames without any updates (no nodes are changed) you may return false from animation function.

+

In this case Konva wouldn’t update layers.

+ + +
Konva Optimize Animation Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Optimize Animation Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var hexagon = new Konva.RegularPolygon({
x: stage.width() / 2,
y: stage.height() / 2,
sides: 6,
radius: 20,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

layer.add(hexagon);
stage.add(layer);

var amplitude = 100;
var period = 2000;
// in ms
var centerX = stage.width() / 2;

// we have animation that do nothing in some cases
var anim = new Konva.Animation(function (frame) {
if (frame.time % (period * 2) < period) {
// regular update
hexagon.x(
amplitude * Math.cos((frame.time * 2 * Math.PI) / period) + centerX
);
} else {
// this is "pause" phase
// we don't need update layer in this case
// so return false and Konva will skip layer draw
return false;
}
}, layer);

anim.start();
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/performance/Optimize_Strokes.html b/docs/performance/Optimize_Strokes.html new file mode 100644 index 000000000..9ab6e6464 --- /dev/null +++ b/docs/performance/Optimize_Strokes.html @@ -0,0 +1,726 @@ + + + + + + HTML5 Canvas Optimizing Strokes Performance Tip | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Optimizing Strokes Performance Tip

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

Disable shadow for stroke

By default Konva is making extra internal drawing when a shape has both stroke and shadow. It is doing that to make drawing result look expected.

+

If you don’t really need shadow for stroke you should set shape.shadowForStrokeEnabled(false). Remember that shadow will be disable if you are using Konva.Line without fill (because it is just stroked shape). Disabling shadow for stroke will increase rendering speed A LOT.

+

Remove stroke from hit

If you have a shape with fill and very small stroke you can set shape.hitStrokeWidth(0) to remove stroke from hit graph.
Don’t use this property if your stroke is critical for hit detection (like non closed lines). By default, Konva is using strokes for hit graph - for detecting shapes under pointer for events. In some situations you may not need that.

+

Instructions: take a look into very slow random movements of circles. Now try to toggle optimized rendering checkbox. Faster?

+ + +
Konva Optimizing Strokes Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Optimizing Strokes Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
label {
position: absolute;
top: 50px;
left: 0;
background-color: white;
padding: 3px;
border-radius: 3px;
}
</style>
<script src="https://mrdoob.github.io/stats.js/build/stats.min.js"></script>
</head>
<body>
<div id="container"></div>
<label>
<input type="checkbox" id="checkbox" />
Use optimized strokes
</label>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var layer = new Konva.Layer();
stage.add(layer);

var n = 100,
shape;
for (var i = 0; i < n; i++) {
shape = new Konva.Circle({
x: stage.width() * Math.random(),
y: stage.height() * Math.random(),
radius: 10 + 10 * Math.random(),
fill: Konva.Util.getRandomColor(),
stroke: 'black',
shadowColor: 'black',
draggable: true,
shadowOffset: {
x: 5,
y: 5,
},
});
layer.add(shape);
}

var stats = new Stats();
document.body.appendChild(stats.domElement);
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';

stats.begin();
const anim = new Konva.Animation(() => {
stats.end();
layer.children.forEach((child) => {
child.move({
x: (Math.random() - 0.5) * 5,
y: (Math.random() - 0.5) * 5,
});
});
stats.begin();
}, layer);
anim.start();

document.querySelector('#checkbox').addEventListener('change', (e) => {
const shouldOptimize = e.target.checked;
layer.children.forEach((child) => {
child.hitStrokeWidth(shouldOptimize ? 0 : 'auto');
child.shadowForStrokeEnabled(shouldOptimize ? false : true);
});
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/performance/Shape_Caching.html b/docs/performance/Shape_Caching.html new file mode 100644 index 000000000..6952ac296 --- /dev/null +++ b/docs/performance/Shape_Caching.html @@ -0,0 +1,732 @@ + + + + + + HTML5 Canvas Shape Caching Performance Tip | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Shape Caching Performance Tip

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

HTML5 Canvas Shape Caching Performance Tip

One way to drastically improve drawing performance for complex Konva shapes is to cache them as images.
This can be achieved by using the cache() method to convert a node into an image object.

+

This particular tutorial of drawing 10 cached stars rather than drawing 10 individual
stars sees about a 4x drawing performance boost. Caching can be applied to layers, groups, and shapes.

+

Note: The cache() method requires that the image is hosted on a web server with the same domain as the code executing it.

+

How caching works?

When you call cache() method, Konva creates a new canvas element in memory and draws the node on it. Next time, when layer is redrawn, Konva just draws cached canvas element instead of drawing the node itself. You don’t need to re-cache the shape if you change its opacity or transform (position, rotation, scale). In other cases you may need to re-cache the shape manually. Based on the logic above, there are several recommendations for caching:

+
    +
  1. Try not to cache many shapes individually. It is better to cache a group of shapes.
  2. +
  3. Try not to cache shapes that are changing frequently. It is better to cache static shapes.
  4. +
  5. Caching simple shapes, like a rectangle, is not recommended. It is better to cache complex shapes with many styles. Measure the performance before and after caching to see if it is worth it.
  6. +
  7. You can use pixelRatio property to increase or decrease the quality of the cached image. Decreasing the quality will improve performance.
  8. +
+ + +
Konva Shape Caching Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Shape Caching Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var star = new Konva.Star({
innerRadius: 20,
outerRadius: 50,
fill: 'red',
stroke: 'black',
strokeWidth: 5,
numPoints: 5,
x: 60,
y: 60,
draggable: true,
shadowOffset: { x: 5, y: 5 },
shadowColor: 'black',
shadowBlur: 5,
shadowOpacity: 0.5,
shadowForStrokeEnabled: false,
});

layer.add(star);
stage.add(layer);
star.cache();

var clone;
for (var n = 0; n < 10; n++) {
clone = star.clone({
x: Math.random() * stage.width(),
y: Math.random() * stage.height(),
});
clone.cache();
layer.add(clone);
}
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/performance/Shape_Redraw.html b/docs/performance/Shape_Redraw.html new file mode 100644 index 000000000..6974f125e --- /dev/null +++ b/docs/performance/Shape_Redraw.html @@ -0,0 +1,726 @@ + + + + + + HTML5 Canvas Shape Redraw Performance Tip | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Shape Redraw Performance Tip

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

Important note: I think using such tricks is an anti-pattern. You should avoid to use it.

+

Usually when you need to update your canvas you should call layer.draw().

+

But in small set of cases it is possible to update Konva.Node without updating whole layer.
You can call shape.draw(), BUT remember that in this case shape will be drawn OVER existing canvas.
So it is not possible to use this tip if your node should be placed under other nodes or if it has an opacity.

+

Instructions: mouseover boxes to highlight.

+ + +
Konva Shape Redraw Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Shape Redraw Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
// disable automatic redraw
Konva.autoDrawEnabled = false;
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var BOX_SIZE = 15;
var box;
// generate boxes
for (var ix = 0; ix < width / BOX_SIZE; ix++) {
for (var iy = 0; iy < height / BOX_SIZE; iy++) {
box = new Konva.Rect({
x: ix * BOX_SIZE,
y: iy * BOX_SIZE,
width: BOX_SIZE - 1,
height: BOX_SIZE - 1,
fill: 'darkgrey',
stroke: 'white',
});
layer.add(box);
}
}
layer.draw();

// as all boxes stay separately with no overlap
// and they have no opacity
// we can call 'box.draw()' and we will have expected result
// REMEMBER that is this case box will be drawn on top of existing layer
// without clearing
layer.on('mouseover', function (evt) {
var box = evt.target;
box.fill('#E5FF80');
box.draw();
});
layer.on('mouseout', function (evt) {
var box = evt.target;
box.fill('darkgrey');
box.draw();
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/posts/Position_vs_Offset.html b/docs/posts/Position_vs_Offset.html new file mode 100644 index 000000000..4db61df0d --- /dev/null +++ b/docs/posts/Position_vs_Offset.html @@ -0,0 +1,744 @@ + + + + + + What is the difference between position and offset in Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

What is the difference between position and offset in Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

There are several properties in Konva that looks similar and may lead some confusion but have a different effect and purpose.

+

In the post I will explain the difference between position (x and y coordinates) and offset (offsetX and offsetY).

+

So x and y properties define position of Node on canvas. If you set draggable = true property and start dragging, Konva will change x and y properties of the node. That logic will be applied for all nodes (even Konva.Line).

+

Position of a rectangle shape defines its top-left point. Position of circle defines its center.

+ + + +

Why do we need an offset property?

When you are changing the offset property it may looks like you are changing position of the node. But actually not. You are changing ORIGIN of the shape.

+

What is it origin? You may think of it as “point from where we start drawing of a shape” or “center of the shape” or “the point around which we rotating a shape”.

+

Just a small note, long time ago offset property was called “center” in Konva codebase (when it was KineticJS project). But later it was refactored to “offset”.

+

Take a look into this animation tutorial. All rectangles here have the same y position, but a different offset property.

+ + +

And you should understand that Konva has two main methods to define origin of the shape.
So “circle-like” shapes have origin at actual center of the shape (Circle, Ellipse, Wedge, Star, Ring ,etc).
When you set {x, y} of a circle you are defining “where will be the center of the circle”.

+

And “rectangle-like” shapes has origin at TOP LEFT (Rectangle, Sprite, Text, Image, etc)
When you set {x, y} of a rectangle you are defining “where will be the top-left point of the rect”.

+

So a shape will be rotated around its origin point (around its “center”). So if you set rotation 45 deg of a star it will be rotated around its actual center.

+

But if you set rotation 45 deg of rectangle, it will be rotated around top-left. But in some cases it is not convenient. Sometimes you may want to rotate the shape around its center.

+

In this case you can set offset property. By using it we will tell konva: “Hey, use this point as the new origin of the shape”.

+

How to set rotation point of a shape?

Now let’s think you are placed a 100x100 rectangle in x = 0, y = 0, and now you want to rotate it around its center.

+

If you are not using offset you have to recalculate position of it’t top left edge (recall you trigonometry lessons from the school).

+

You can do this by using something like this:

+
const rotatePoint = ({ x, y }, rad) => {
const rcos = Math.cos(rad);
const rsin = Math.sin(rad);
return { x: x * rcos - y * rsin, y: y * rcos + x * rsin };
};

// will work for shapes with top-left origin, like rectangle
function rotateAroundCenter(node, rotation) {
//current rotation origin (0, 0) relative to desired origin - center (node.width()/2, node.height()/2)
const topLeft = { x: -node.width() / 2, y: -node.height() / 2 };
const current = rotatePoint(topLeft, Konva.getAngle(node.rotation()));
const rotated = rotatePoint(topLeft, Konva.getAngle(rotation));
const dx = rotated.x - current.x,
dy = rotated.y - current.y;

node.rotation(rotation);
node.x(node.x() + dx);
node.y(node.y() + dy);
}

// then use it
rotateAroundCenter(rect, 180);
+ +

Or you can set offsetX = width / 2 and offsetY = height / 2. But the rectangle will be moved on the canvas (since you change its origin). So you will need to adjust the position.

+

Still have a question? Ask in comments.

+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/posts/Tainted_Canvas.html b/docs/posts/Tainted_Canvas.html new file mode 100644 index 000000000..aa2a2c614 --- /dev/null +++ b/docs/posts/Tainted_Canvas.html @@ -0,0 +1,738 @@ + + + + + + Resolving "Tainted canvases may not be exported" with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Resolving "Tainted canvases may not be exported" with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

When you are trying to export a canvas you may have an error like:

+
+

Unable to get data URL. Failed to execute ‘toDataURL’ on ‘HTMLCanvasElement’: Tainted canvases may not be exported.

+
+
+

Unable to get image data from canvas because the canvas has been tainted by cross-origin data.

+
+

Or when you apply filters you can have this error:

+
+

Unable to apply filter. Failed to execute ‘getImageData’ on ‘CanvasRenderingContext2D’: The canvas has been tainted by cross-origin data.

+
+
+

Unable to apply filter. The operation is insecure.

+
+

Why do we have that insecure error?

That is a CORS error. For security reasons, a browser can mark a canvas as tainted when you load images from another domain. In that case the browser blocks canvas exporting into dataURL or imageData (that is what we are doing on export or when filters are used).

+

How to fix CORS issue?

First you may try to set crossOrigin = Anonymous attribute of the loading image. This approach will work only if requested domain has an Access-Control-Allow-Origin headers that allow shared requests.

+
// 1
// native image loading:
const img = new Image();
img.onload = () => {
// your code
};
img.crossOrigin = 'Anonymous';
img.src = url;

// 2
// you don't need to set that attribute if you use Konva.Image.fromURL API
// it sets Anonymous automatically
Konva.Image.fromURL(url, img => {
layer.add(img);
});

// 3
// and if you use use-image hook for react-konva
const MyImage = ({ url }) => {
const [image] = useImage(url, 'Anonymous');
return <Image image={image} />;
}
+ +

What if it doesn’t work?

It may still not work for all cases. If it doesn’t work, then you have to configure your server in a different way (it is out of Konva scope) or you can try to store images somewhere else where CORS requests are supported.

+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/Access_Konva_Nodes.html b/docs/react/Access_Konva_Nodes.html new file mode 100644 index 000000000..ff39faf15 --- /dev/null +++ b/docs/react/Access_Konva_Nodes.html @@ -0,0 +1,525 @@ + + + + + + How to access Konva nodes from react-konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to access Konva nodes from react-konva?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

In some cases you may need to use the Konva API directly. For example for exporting canvases or animations.

+

There are two ways to access Konva nodes/shapes from react-konva.

+

Using the refs API.

You can use the refs API to get access to a Konva node.

+
import { Circle } from 'react-konva';
const App = () => {
const shapeRef = React.useRef(null);
React.useEffect(() => {
// it will log `Konva.Circle` instance
console.log(shapeRef.current);
});
return <Circle ref={shapeRef} />;
}
+ +

Using an event object inside of the event callback

Another common way to access a Konva node is to just use an event object that you have as an argument in any event:

+
import { Circle } from 'react-konva';
const App = () => {
const handleClick = (e) => {
// logs clicked Konva.Circle instance
console.log(e.target);
}
return <Circle onClick={handleClick} />;
}
+ + + + + + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/Canvas_Export.html b/docs/react/Canvas_Export.html new file mode 100644 index 000000000..8a7fdf49e --- /dev/null +++ b/docs/react/Canvas_Export.html @@ -0,0 +1,516 @@ + + + + + + How to export a canvas into an image from react-konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to export a canvas into an image from react-konva?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to save a drawing from react-konva?

To export any Konva node into an image you can either use the node.toDataURL() or the node.toImage() API. Take a look into the vanilla Konva image export demo.

+

You will need to use the Refs API to access a Konva node directly in order to call these methods.

+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/Canvas_Portal.html b/docs/react/Canvas_Portal.html new file mode 100644 index 000000000..c428ab054 --- /dev/null +++ b/docs/react/Canvas_Portal.html @@ -0,0 +1,523 @@ + + + + + + How to use portals in react-konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to use portals in react-konva?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How does react-konva control the zIndex?

react-konva strictly follows the order of elements in the way that you define them in your render. For more info take a look into the zIndex demo.

+

Is it possible to move a node into another container with react-konva?

Currently react-konva doesn’t support the React.createPortal API.

+

But we can use <Portal /> component from react-konva-utils package

+

Such a portal can be useful when you want to temporarily move a node into another container. The common use cases are:

+
    +
  1. Move a dragging shape into another layer for better performance
  2. +
  3. Show an element on top of other elements, but still keep it deep down in the components tree
  4. +
+

Instructions: try to drag a rectangle. You will see that it is visible on top, but in render it is still the first element.

+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/Complex_Animations.html b/docs/react/Complex_Animations.html new file mode 100644 index 000000000..9fe09ca5d --- /dev/null +++ b/docs/react/Complex_Animations.html @@ -0,0 +1,518 @@ + + + + + + How to apply canvas animations with react and konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to apply canvas animations with react and konva?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

For complex animations and high performance updates you can use the react-spring library.

+ + + + + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/Custom_Shape.html b/docs/react/Custom_Shape.html new file mode 100644 index 000000000..96091866b --- /dev/null +++ b/docs/react/Custom_Shape.html @@ -0,0 +1,520 @@ + + + + + + How to draw custom shapes with React? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to draw custom shapes with React?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

To create a custom shape with react-konva, we should use the Shape component.

+

When creating a custom shape, we need to define a drawing function that is passed to a Konva.Canvas renderer.

+

We can use the renderer to access the HTML5 Canvas context, and to use special methods like context.fillStrokeShape(shape) which automatically handle filling, stroking, and applying shadows.

+ + + + + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/DOM_Portal.html b/docs/react/DOM_Portal.html new file mode 100644 index 000000000..b2ce2a3c8 --- /dev/null +++ b/docs/react/DOM_Portal.html @@ -0,0 +1,516 @@ + + + + + + Render DOM elements inside a canvas stage | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Render DOM elements inside a canvas stage

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to put DOM elements (like inputs or divs) inside of a Konva stage?

If you want to have some DOM nodes as part of your canvas tree you can use <Html /> component from react-konva-utils package.

+

Remember that DOM nodes are not direct children of Konva containers. <Html /> is just a wrapper to work with a Portal-like API. HTML content will be not visible if you try to export canvas as image.

+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/Drag_And_Drop.html b/docs/react/Drag_And_Drop.html new file mode 100644 index 000000000..f13465804 --- /dev/null +++ b/docs/react/Drag_And_Drop.html @@ -0,0 +1,519 @@ + + + + + + Drag and drop canvas shapes | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Drag and drop canvas shapes

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

To enable drag&drop for any node on the canvas you just need to pass the draggable property into the component.

+

When you drag&drop a shape it is recommended to save its position into your app store. You can use the onDragMove and onDragEnd events for that purpose.

+ + + + + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/Drop_Image.html b/docs/react/Drop_Image.html new file mode 100644 index 000000000..d0a695632 --- /dev/null +++ b/docs/react/Drop_Image.html @@ -0,0 +1,520 @@ + + + + + + How to drop image elements into a canvas with React? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to drop image elements into a canvas with React?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

You can use native html5 drag&drop features to drop images (or other elements) from the page into the canvas area.

+

Note: this demo may not work well as it is injected into the page as an iframe.

+

Open DEMO in a new tab the test it

+ + + + + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/Events.html b/docs/react/Events.html new file mode 100644 index 000000000..5c0a386e4 --- /dev/null +++ b/docs/react/Events.html @@ -0,0 +1,521 @@ + + + + + + How to listen to an event on a canvas shape with React and Konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to listen to an event on a canvas shape with React and Konva?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

With react-konva you can attach any events that Konva supports to canvas nodes

+

To do that you can use the onEventName scheme, like onMouseDown for mousedown, onDragEnd for dragend, etc.

+

For the full list of events take a look into the on() method documentation.

+

In this demo you can see how we are using dragstart and dragend events.

+ + + + + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/Filters.html b/docs/react/Filters.html new file mode 100644 index 000000000..6820c6663 --- /dev/null +++ b/docs/react/Filters.html @@ -0,0 +1,519 @@ + + + + + + How to apply canvas filters with react and konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to apply canvas filters with react and konva?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

To apply filters you need to cache the Konva.Node manually. You can do it in componentDidMount.
You will probably need to re-cache nodes every time you update their styles in componentDidUpdate or React.useEffect.

+

Instructions: click on the rectangle to see changes.

+ + + + + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/Free_Drawing.html b/docs/react/Free_Drawing.html new file mode 100644 index 000000000..fe30852e0 --- /dev/null +++ b/docs/react/Free_Drawing.html @@ -0,0 +1,517 @@ + + + + + + How to implement free drawing on canvas with react? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to implement free drawing on canvas with react?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

This demo shows how to implement a free drawing app the “react-way” with full vector representation.

+

Such an implementation should work ok for many whiteboard apps. It allows you to simply add undo/redo functions and save the full state to the backend.

+

It will get slower if you have too many lines in the state. So you will have to do some extra optimizations if you want to enable drawings of hundreds or thousands of lines.

+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/Images.html b/docs/react/Images.html new file mode 100644 index 000000000..93b20828f --- /dev/null +++ b/docs/react/Images.html @@ -0,0 +1,519 @@ + + + + + + How to draw images on canvas with React? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to draw images on canvas with React?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

If you take a look into the image tutorial and API docs you will see that you need to use a window.Image instance as the image attribute for Konva.Image. So you need to create and download it manually.

+

Also, you can use the brand new react hook use-image to handle loading your images or you can use the lifecycle methods of React and create your own custom component.

+ + + + + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/Intro.html b/docs/react/Intro.html new file mode 100644 index 000000000..080589c30 --- /dev/null +++ b/docs/react/Intro.html @@ -0,0 +1,537 @@ + + + + + + react-konva - declarative canvas components for React | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

react-konva - declarative canvas components for React

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+
npm install react-konva konva
+ + + +
+
+

All common shapes for graphical applications

+
+
+

Support for desktop and mobile devices

+
+
+

Node nesting, grouping and event bubbling

+
+
+

High quality exports into data URLs, image data, or image objects

+
+
+ +

How does it look?

import { Stage, Layer, Rect, Circle } from 'react-konva';

export const App = () => {
return (
// Stage - is a div wrapper
// Layer - is an actual 2d canvas element, so you can have several layers inside the stage
// Rect and Circle are not DOM elements. They are 2d shapes on canvas
<Stage width={window.innerWidth} height={window.innerHeight}>
<Layer>
<Rect width={50} height={50} fill="red" />
<Circle x={200} y={200} stroke="black" radius={50} />
</Layer>
</Stage>
);
}
+ +

Demo

+ + + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/Shapes.html b/docs/react/Shapes.html new file mode 100644 index 000000000..abafe58fd --- /dev/null +++ b/docs/react/Shapes.html @@ -0,0 +1,516 @@ + + + + + + Drawing canvas shapes with React | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Drawing canvas shapes with React

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

All react-konva components correspond to Konva components of the same name.
All the parameters available for Konva objects are valid props for
corresponding react-konva components, unless noted otherwise.

+

Core shapes are: Rect, Circle, Ellipse, Line, Image, Text, TextPath, Star,
Label, SVG Path, RegularPolygon. You can also create custom shapes.

+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/Simple_Animations.html b/docs/react/Simple_Animations.html new file mode 100644 index 000000000..6768fb001 --- /dev/null +++ b/docs/react/Simple_Animations.html @@ -0,0 +1,521 @@ + + + + + + How to apply canvas animations with react and konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to apply canvas animations with react and konva?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Konva itself has two methods for animations: Tween and Animation. You can apply both of them to nodes manually.

+

For simple use cases we recommend to use the node.to() method. For more complex animations take a look at the Complex react-konva animation demo.

+

The demo is using the refs API to access shape instances directly.

+

Instructions: Try to move a rectangle.

+ + + + + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/Transformer.html b/docs/react/Transformer.html new file mode 100644 index 000000000..2f6fa8ebd --- /dev/null +++ b/docs/react/Transformer.html @@ -0,0 +1,520 @@ + + + + + + How to resize and rotate canvas shapes with react and konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to resize and rotate canvas shapes with react and konva?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Currently there is no good, pure declarative “react-way” to use the Transformer tool.
But you can still use it with some small manual requests to the Konva nodes.
And it will work just fine.

+

The Idea: you need to create a Konva.Transformer node, and attach it to the required node manually.

+

Instructions: Click on one of the shapes to select it.

+ + + + + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/Undo-Redo.html b/docs/react/Undo-Redo.html new file mode 100644 index 000000000..80a748e5d --- /dev/null +++ b/docs/react/Undo-Redo.html @@ -0,0 +1,520 @@ + + + + + + How to implement undo/redo on canvas with React? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to implement undo/redo on canvas with React?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

To implement undo/redo functionality with React you don’t need to use Konva‘s serialization and deserealization methods.

+

You just need to save a history of all the state changes within your app. There are many ways to do this. It may be simpler do to that if you use immutable structures.

+

Instructions: Try to move the square. Then undo/redo your actions.

+ + + + + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/index.html b/docs/react/index.html new file mode 100644 index 000000000..beb1662a6 --- /dev/null +++ b/docs/react/index.html @@ -0,0 +1,531 @@ + + + + + + Getting started with react and canvas via Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Getting started with react and canvas via Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+
+ +
+ +

react-konva is a JavaScript library for drawing complex canvas graphics using React. It provides declarative and reactive bindings to the Konva Framework.

+

Github Repo

+

It is an attempt to make React work with the HTML5 canvas library. The goal is to have a similar declarative markup as normal React and also a similar data-flow model.

+

Currently, react-konva is not supported in the React Native environment.

+

Currently you can use all Konva nodes and shapes as React components and all Konva events are supported on them in the same way.

+

Note: you can find a lot of demos and examples for using Konva there: https://konvajs.org/. Really, just go there and take a look at what Konva can do for you. You will be able to do the same with react-konva, too. Konva for react-konva is like DOM for React.

+

Installation

npm install react-konva konva --save
+ + + + +

Comparisons

react-konva vs react-canvas

react-canvas is a completely
different react plugin. It allows you to draw DOM-like objects (images, texts)
on canvas elements in a very performant way. It is NOT about drawing graphics, but
react-konva serves exactly this purpose: drawing complex graphics on a <canvas> element from within
React.

+

react-konva vs react-art

react-art allows you to draw graphics on
a page. It also supports SVG output. But it has no support of events on
shapes.

+

react-konva vs vanilla canvas

Vanilla canvases can be faster since react-konva comes with two layers of abstractions: (1) The Konva framework is on top of canvas and (2) React is on top of Konva. For many applications it’s performance is still very good. The purpose of react-konva is to reduce the complexity of your application and to use a well-known declarative way for drawing on canvases.

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/react/zIndex.html b/docs/react/zIndex.html new file mode 100644 index 000000000..c3566e7d9 --- /dev/null +++ b/docs/react/zIndex.html @@ -0,0 +1,523 @@ + + + + + + How to change the zIndex of nodes with React? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to change the zIndex of nodes with React?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to change the zIndex and reorder components in react-konva?

When you are working with Konva directly you have many methods to change the order of nodes like node.zIndex(5), node.moveToTop(), etc. Tutorial.

+

But it is not recommended to use these methods when you are working with the React framework.

+

react-konva is trying to follow the order of the nodes exactly as you described them in render(). So instead of changing the zIndex manually, you just need to update the state of the app correctly, so the render() returns the correct order.

+

Don’t use the zIndex for your canvas components.

+

If you want to temporarily move a node into another container, for example when you want to show an overlay, take a look into the Canvas Portal demo.

+

Instructions: Try to drag a circle. See how it goes to the top. We are doing this by manipulating the state so that the render() method returns the correct order.

+ + + + + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/10000_Shapes_with_Tooltip.html b/docs/sandbox/10000_Shapes_with_Tooltip.html new file mode 100644 index 000000000..38fa0800d --- /dev/null +++ b/docs/sandbox/10000_Shapes_with_Tooltip.html @@ -0,0 +1,677 @@ + + + + + + 10,000 Shapes with Tooltips Stress Test with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

10,000 Shapes with Tooltips Stress Test with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+ + +
Konva 10,000 Shapes with Tooltips Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva 10,000 Shapes with Tooltips Stress Test Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var circlesLayer = new Konva.Layer();
var tooltipLayer = new Konva.Layer();
var colors = [
'red',
'orange',
'yellow',
'green',
'blue',
'cyan',
'purple',
];
var colorIndex = 0;

for (var i = 0; i < 10000; i++) {
var color = colors[colorIndex++];
if (colorIndex >= colors.length) {
colorIndex = 0;
}

var randX = Math.random() * stage.width();
var randY = Math.random() * stage.height();
var circle = new Konva.Circle({
x: randX,
y: randY,
radius: 3,
fill: color,
name: i.toString(),
});

circlesLayer.add(circle);
}

var tooltip = new Konva.Text({
text: '',
fontFamily: 'Calibri',
fontSize: 12,
padding: 5,
visible: false,
fill: 'black',
opacity: 0.75,
textFill: 'white',
});

tooltipLayer.add(tooltip);
stage.add(circlesLayer);
stage.add(tooltipLayer);

circlesLayer.on('mousemove', function (e) {
// update tooltip
var mousePos = stage.getPointerPosition();
tooltip.position({
x: mousePos.x + 5,
y: mousePos.y + 5,
});
tooltip.text(
'node: ' + e.target.name() + ', color: ' + e.target.fill()
);
tooltip.show();
});
circlesLayer.on('mouseout', function () {
tooltip.hide();
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/20000_Nodes.html b/docs/sandbox/20000_Nodes.html new file mode 100644 index 000000000..f56624561 --- /dev/null +++ b/docs/sandbox/20000_Nodes.html @@ -0,0 +1,680 @@ + + + + + + Interactive Scatter Plot with 20,000 Nodes | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Interactive Scatter Plot with 20,000 Nodes

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

The purpose of this lab is to demonstrate the sheer number of nodes that Konva can handle by rendering 20,000 circles. Each circle is sensitive to mouseover events, and can be drag and dropped. This lab is also a great demonstration of event delegation, in which a single event handler attached to the stage handles the circle events.

+

Instructions: Mouse over the nodes to see more information, and then drag and drop them around the stage.

+ + +
Konva 20000 Nodes Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Interactive Scatter Plot with 20,000 Nodes Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

function addNode(obj, layer) {
var node = new Konva.Circle({
x: obj.x,
y: obj.y,
radius: 4,
fill: obj.color,
id: obj.id,
});

layer.add(node);
}
var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var tooltipLayer = new Konva.Layer();
var dragLayer = new Konva.Layer();

var tooltip = new Konva.Label({
opacity: 0.75,
visible: false,
listening: false,
});

tooltip.add(
new Konva.Tag({
fill: 'black',
pointerDirection: 'down',
pointerWidth: 10,
pointerHeight: 10,
lineJoin: 'round',
shadowColor: 'black',
shadowBlur: 10,
shadowOffsetX: 10,
shadowOffsetY: 10,
shadowOpacity: 0.2,
})
);

tooltip.add(
new Konva.Text({
text: '',
fontFamily: 'Calibri',
fontSize: 18,
padding: 5,
fill: 'white',
})
);

tooltipLayer.add(tooltip);

// build data
var data = [];

var colors = ['red', 'orange', 'cyan', 'green', 'blue', 'purple'];
for (var n = 0; n < 20000; n++) {
var x = Math.random() * width;
var y = height + Math.random() * 200 - 100 + (height / width) * -1 * x;
data.push({
x: x,
y: y,
id: n,
color: colors[Math.round(Math.random() * 5)],
});
}

// render data
var nodeCount = 0;
var layer = new Konva.Layer();
for (var n = 0; n < data.length; n++) {
addNode(data[n], layer);
nodeCount++;
if (nodeCount >= 1000) {
nodeCount = 0;
stage.add(layer);
layer = new Konva.Layer();
}
}

stage.add(dragLayer);
stage.add(tooltipLayer);

stage.on('mouseover mousemove dragmove', function (evt) {
var node = evt.target;
if (node) {
// update tooltip
var mousePos = node.getStage().getPointerPosition();
tooltip.position({
x: mousePos.x,
y: mousePos.y - 5,
});
tooltip
.getText()
.text('node: ' + node.id() + ', color: ' + node.fill());
tooltip.show();
}
});

stage.on('mouseout', function (evt) {
tooltip.hide();
});

var startLayer;

stage.on('mousedown', function (evt) {
var shape = evt.target;
if (shape) {
startLayer = shape.getLayer();
shape.moveTo(dragLayer);
// manually trigger drag and drop
shape.startDrag();
}
});

stage.on('mouseup', function (evt) {
var shape = evt.target;
if (shape) {
shape.moveTo(startLayer);
}
});
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Animals_on_the_Beach_Game.html b/docs/sandbox/Animals_on_the_Beach_Game.html new file mode 100644 index 000000000..962af5826 --- /dev/null +++ b/docs/sandbox/Animals_on_the_Beach_Game.html @@ -0,0 +1,677 @@ + + + + + + Animals on the Beach Game | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Animals on the Beach Game

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+ + +
Konva Animals on the Beach Game Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Animals on the Beach Game Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

function loadImages(sources, callback) {
var assetDir = '/assets/';
var images = {};
var loadedImages = 0;
var numImages = 0;
for (var src in sources) {
numImages++;
}
for (var src in sources) {
images[src] = new Image();
images[src].onload = function () {
if (++loadedImages >= numImages) {
callback(images);
}
};
images[src].src = assetDir + sources[src];
}
}
function isNearOutline(animal, outline) {
var a = animal;
var o = outline;
var ax = a.x();
var ay = a.y();

if (ax > o.x - 20 && ax < o.x + 20 && ay > o.y - 20 && ay < o.y + 20) {
return true;
} else {
return false;
}
}
function drawBackground(background, beachImg, text) {
var context = background.getContext();
context.drawImage(beachImg, 0, 0);
context.setAttr('font', '20pt Calibri');
context.setAttr('textAlign', 'center');
context.setAttr('fillStyle', 'white');
context.fillText(text, background.getStage().width() / 2, 40);
}

function initStage(images) {
var stage = new Konva.Stage({
container: 'container',
width: 578,
height: 530,
});
var background = new Konva.Layer();
var animalLayer = new Konva.Layer();
var animalShapes = [];
var score = 0;

// image positions
var animals = {
snake: {
x: 10,
y: 70,
},
giraffe: {
x: 90,
y: 70,
},
monkey: {
x: 275,
y: 70,
},
lion: {
x: 400,
y: 70,
},
};

var outlines = {
snake_black: {
x: 275,
y: 350,
},
giraffe_black: {
x: 390,
y: 250,
},
monkey_black: {
x: 300,
y: 420,
},
lion_black: {
x: 100,
y: 390,
},
};

// create draggable animals
for (var key in animals) {
// anonymous function to induce scope
(function () {
var privKey = key;
var anim = animals[key];

var animal = new Konva.Image({
image: images[key],
x: anim.x,
y: anim.y,
draggable: true,
});

animal.on('dragstart', function () {
this.moveToTop();
});
/*
* check if animal is in the right spot and
* snap into place if it is
*/
animal.on('dragend', function () {
var outline = outlines[privKey + '_black'];
if (!animal.inRightPlace && isNearOutline(animal, outline)) {
animal.position({
x: outline.x,
y: outline.y,
});
animal.inRightPlace = true;

if (++score >= 4) {
var text = 'You win! Enjoy your booty!';
drawBackground(background, images.beach, text);
}

// disable drag and drop
setTimeout(function () {
animal.draggable(false);
}, 50);
}
});
// make animal glow on mouseover
animal.on('mouseover', function () {
animal.image(images[privKey + '_glow']);
document.body.style.cursor = 'pointer';
});
// return animal on mouseout
animal.on('mouseout', function () {
animal.image(images[privKey]);
document.body.style.cursor = 'default';
});

animal.on('dragmove', function () {
document.body.style.cursor = 'pointer';
});

animalLayer.add(animal);
animalShapes.push(animal);
})();
}

// create animal outlines
for (var key in outlines) {
// anonymous function to induce scope
(function () {
var imageObj = images[key];
var out = outlines[key];

var outline = new Konva.Image({
image: imageObj,
x: out.x,
y: out.y,
});

animalLayer.add(outline);
})();
}

stage.add(background);
stage.add(animalLayer);

drawBackground(
background,
images.beach,
'Ahoy! Put the animals on the beach!'
);
}

var sources = {
beach: 'beach.png',
snake: 'snake.png',
snake_glow: 'snake-glow.png',
snake_black: 'snake-black.png',
lion: 'lion.png',
lion_glow: 'lion-glow.png',
lion_black: 'lion-black.png',
monkey: 'monkey.png',
monkey_glow: 'monkey-glow.png',
monkey_black: 'monkey-black.png',
giraffe: 'giraffe.png',
giraffe_glow: 'giraffe-glow.png',
giraffe_black: 'giraffe-black.png',
};
loadImages(sources, initStage);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Animation_Stress_Test.html b/docs/sandbox/Animation_Stress_Test.html new file mode 100644 index 000000000..5d2b30524 --- /dev/null +++ b/docs/sandbox/Animation_Stress_Test.html @@ -0,0 +1,677 @@ + + + + + + Animation Stress Test | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Animation Stress Test

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+ + +
Konva Animation Stress Test Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Animation Stress Test Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

function update(layer, frame) {
var angularSpeed = 100;
var angularDiff = (angularSpeed * frame.timeDiff) / 1000;
var shapes = layer.getChildren();

for (var n = 0; n < shapes.length; n++) {
var shape = shapes[n];
shape.rotate(angularDiff);
}
}

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

/*
* setting the listening property to false will improve
* drawing performance because the rectangles won't have to be
* drawn onto the hit graph
*/
var layer = new Konva.Layer({
listening: false,
});
var colors = [
'red',
'orange',
'yellow',
'green',
'blue',
'cyan',
'purple',
];
var colorIndex = 0;

for (var i = 0; i < 300; i++) {
var color = colors[colorIndex++];
if (colorIndex >= colors.length) {
colorIndex = 0;
}

var randWidth = Math.random() * 100 + 20;
var randHeight = Math.random() * 100 + 20;
var randX = Math.random() * stage.width() - 20;
var randY = Math.random() * stage.height() - 20;

var box = new Konva.Rect({
x: randX,
y: randY,
offset: {
x: randWidth / 2,
y: randHeight / 2,
},
width: randWidth,
height: randHeight,
fill: color,
stroke: 'black',
strokeWidth: 4,
});

layer.add(box);
}

stage.add(layer);

var anim = new Konva.Animation(function (frame) {
update(layer, frame);
}, layer);

anim.start();
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Canvas_Background.html b/docs/sandbox/Canvas_Background.html new file mode 100644 index 000000000..b17937d9d --- /dev/null +++ b/docs/sandbox/Canvas_Background.html @@ -0,0 +1,684 @@ + + + + + + How to add background to canvas? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to add background to canvas?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How add background to Konva stage?

There are two ways to add a background.

+

1. Adding background with Konva.Rect shape.

The Konva-way to add a background to your canvas is just by drawing Konva.Rect shape with the size of a stage on the bottom of your scene. You can style that rectangle as you want with solid color, gradient or pattern image.

+

The only thing that you should be careful about here is the rectangle’s position and size. If you are transforming any parent of background shape (such as stage or layer) by moving it, or applying scale you should “reset” background shape position/size to fill whole Stage area.

+

2. Adding background with CSS

The other solution to add background to your canvas is just use CSS styles to stage container DOM element. That solution is simpler than the first approach, because you don’t need to track position, size changes. It also has a bit better performance, because you don’t need to draw any additional shapes.

+

But it has one drawback. The CSS background will be not visible on export when you use methods like stage.toImage() and stage.toDataURL().

+

Instructions: On the demo I will show two approaches. The green solid background is made with CSS. Yellow-orange gradient will be done with Konva.Rect instance. Try to drag a stage. You will see that gradient stay on place.

+ + +
Konva background demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Background Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
draggable: true,
});

var layer = new Konva.Layer();
stage.add(layer);

// there are two ways to add background to the stage.
// the simplest solution is to just using CSS
stage.container().style.backgroundColor = 'green';

// another solution is to use rectangle shape
var background = new Konva.Rect({
x: 0,
y: 0,
width: stage.width(),
height: stage.height(),
fillLinearGradientStartPoint: { x: 0, y: 0 },
fillLinearGradientEndPoint: { x: stage.width(), y: stage.height() },
// gradient into transparent color, so we can see CSS styles
fillLinearGradientColorStops: [
0,
'yellow',
0.5,
'blue',
0.6,
'rgba(0, 0, 0, 0)',
],
// remove background from hit graph for better perf
// because we don't need any events on the background
listening: false,
});
layer.add(background);
// the stage is draggable
// that means absolute position of background may change
// so we need to reset it back to {0, 0}

stage.on('dragmove', () => {
background.absolutePosition({ x: 0, y: 0 });
});

// add demo shape
var circle = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2,
radius: 100,
fill: 'red',
});
layer.add(circle);
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Canvas_Context_Menu.html b/docs/sandbox/Canvas_Context_Menu.html new file mode 100644 index 000000000..9cccecc31 --- /dev/null +++ b/docs/sandbox/Canvas_Context_Menu.html @@ -0,0 +1,684 @@ + + + + + + How to show a context menu for HTML5 canvas shape? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to show a context menu for HTML5 canvas shape?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Do you want to show a context menu for a canvas shape?

To show a context menu we have to:

+
    +
  1. Listen to contextmenu event on canvas container (stage)
  2. +
  3. Prevent default browser behavior, so we don’t see native context menu
  4. +
  5. Create our own context menu with Konva tools or regular html
  6. +
+

Instructions: double click on the stage to create a circle. Try right click (context menu) on shapes for a menu.

+ + +
Canvas_Context_Menu.htmlview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Context Menu Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#menu {
display: none;
position: absolute;
width: 60px;
background-color: white;
box-shadow: 0 0 5px grey;
border-radius: 3px;
}

#menu button {
width: 100%;
background-color: white;
border: none;
margin: 0;
padding: 10px;
}

#menu button:hover {
background-color: lightgray;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="menu">
<div>
<button id="pulse-button">Pulse</button
><button id="delete-button">Delete</button>
</div>
</div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

// add default shape
var shape = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2,
radius: 50,
fill: 'red',
shadowBlur: 10,
});
layer.add(shape);

stage.on('dblclick dbltap', function () {
// add a new shape
var newShape = new Konva.Circle({
x: stage.getPointerPosition().x,
y: stage.getPointerPosition().y,
radius: 10 + Math.random() * 30,
fill: Konva.Util.getRandomColor(),
shadowBlur: 10,
});
layer.add(newShape);
});

// setup menu
let currentShape;
var menuNode = document.getElementById('menu');
document.getElementById('pulse-button').addEventListener('click', () => {
currentShape.to({
scaleX: 2,
scaleY: 2,
onFinish: () => {
currentShape.to({ scaleX: 1, scaleY: 1 });
},
});
});

document.getElementById('delete-button').addEventListener('click', () => {
currentShape.destroy();
});

window.addEventListener('click', () => {
// hide menu
menuNode.style.display = 'none';
});

stage.on('contextmenu', function (e) {
// prevent default behavior
e.evt.preventDefault();
if (e.target === stage) {
// if we are on empty place of the stage we will do nothing
return;
}
currentShape = e.target;
// show menu
menuNode.style.display = 'initial';
var containerRect = stage.container().getBoundingClientRect();
menuNode.style.top =
containerRect.top + stage.getPointerPosition().y + 4 + 'px';
menuNode.style.left =
containerRect.left + stage.getPointerPosition().x + 4 + 'px';
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Canvas_Editor.html b/docs/sandbox/Canvas_Editor.html new file mode 100644 index 000000000..c3a04ac42 --- /dev/null +++ b/docs/sandbox/Canvas_Editor.html @@ -0,0 +1,680 @@ + + + + + + Canvas Designer Editor for JavaScript | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Canvas Designer Editor for JavaScript

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Do you need a design editor for your web app?

This is a demonstration of full canvas editor made with Konva. The demo is made by https://polotno.dev SDK.

+

Polotno is a very opinionated JavaScript framework that built on top of Konva and React. You can make logos, presentations, designs for social media with it. polotno.dev supports all the basic editing of designs on web: texts, images, filters, selection, transformations, filters, exports, undo/redo and many more.

+

You can easily integrate Polotno SDK into your web app and make your own design editor.

+

The demo may be not optimized yet for small screens, so just open it in a new window for better experience.

+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Canvas_Scrolling.html b/docs/sandbox/Canvas_Scrolling.html new file mode 100644 index 000000000..ae0da6a0d --- /dev/null +++ b/docs/sandbox/Canvas_Scrolling.html @@ -0,0 +1,758 @@ + + + + + + HTML5 Large Canvas Scrolling Demo | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Large Canvas Scrolling Demo

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Imagine we have this scenario. There are a very large stage 3000x3000 with many nodes inside.
User wants to take a look into all nodes, but they are not visible at once.

+

How to display and scroll a very big html5 canvas?

Lets think you have a very large canvas and you want to add ability to navigate on it.

+

I will show your 4 different approaches to achieve that:

+

1. Just make large stage

This is the simplest approach. But it is very slow, because large canvases are slow.
User will be able to scroll with native scrollbars.

+

Pros:

+
    +
  • Simple implementation
  • +
+

Cons:

+
    +
  • Slow
  • +
+ + +
Show source code! +

+

Canvas Scrolling Largeview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Canvas Scrolling Demo</title>
<style>
body {
margin: 0;
padding: 0;
background-color: #f0f0f0;
height: 100%;
overflow: auto;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var WIDTH = 3000;
var HEIGHT = 3000;
var NUMBER = 200;

var stage = new Konva.Stage({
container: 'container',
width: WIDTH,
height: HEIGHT,
});

var layer = new Konva.Layer();
stage.add(layer);

function generateNode() {
return new Konva.Circle({
x: WIDTH * Math.random(),
y: HEIGHT * Math.random(),
radius: 50,
fill: 'red',
stroke: 'black',
});
}

for (var i = 0; i < NUMBER; i++) {
layer.add(generateNode());
}
</script>
</body>
</html>
+

+
+ + +

2. Make stage draggable (navigate with drag&drop)

That one is better because stage is much smaller.

+

Pros:

+
    +
  • Simple implementation
  • +
  • Fast
  • +
+

Cons

+
    +
  • Sometimes drag&drop navigation is not the best UX
  • +
+ + +
Show source code! +

+

Canvas Scrolling Dragview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Canvas Scrolling Drag Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
draggable: true,
});

var layer = new Konva.Layer();
stage.add(layer);

var WIDTH = 3000;
var HEIGHT = 3000;
var NUMBER = 200;

function generateNode() {
return new Konva.Circle({
x: WIDTH * Math.random(),
y: HEIGHT * Math.random(),
radius: 50,
fill: 'red',
stroke: 'black',
});
}

for (var i = 0; i < NUMBER; i++) {
layer.add(generateNode());
}
</script>
</body>
</html>
+

+
+ +

3. Emulate scrollbars.

You will have to draw them manually and implement all moving functionality.
That is quite a lot of work. But works good for many apps.

+

Instruction: try to scroll with bars.

+

Pros:

+
    +
  • Works ok
  • +
  • Intuitive scroll
  • +
  • Fast
  • +
+

Cons

+
    +
  • Scrollbars are not native, so you have to implement many things manually (like scroll with keyboard)
  • +
+ + +
Show source code! +

+

Canvas Scrolling Barsview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Canvas Scrolling Drag Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var WIDTH = 3000;
var HEIGHT = 3000;
var NUMBER = 200;

function generateNode() {
return new Konva.Circle({
x: WIDTH * Math.random(),
y: HEIGHT * Math.random(),
radius: 50,
fill: 'red',
stroke: 'black',
});
}

for (var i = 0; i < NUMBER; i++) {
layer.add(generateNode());
}

// now draw our bars
var scrollLayers = new Konva.Layer();
stage.add(scrollLayers);

const PADDING = 5;

var verticalBar = new Konva.Rect({
width: 10,
height: 100,
fill: 'grey',
opacity: 0.8,
x: stage.width() - PADDING - 10,
y: PADDING,
draggable: true,
dragBoundFunc: function (pos) {
pos.x = stage.width() - PADDING - 10;
pos.y = Math.max(
Math.min(pos.y, stage.height() - this.height() - PADDING),
PADDING
);
return pos;
},
});
scrollLayers.add(verticalBar);

verticalBar.on('dragmove', function () {
// delta in %
const availableHeight =
stage.height() - PADDING * 2 - verticalBar.height();
var delta = (verticalBar.y() - PADDING) / availableHeight;

layer.y(-(HEIGHT - stage.height()) * delta);
});

var horizontalBar = new Konva.Rect({
width: 100,
height: 10,
fill: 'grey',
opacity: 0.8,
x: PADDING,
y: stage.height() - PADDING - 10,
draggable: true,
dragBoundFunc: function (pos) {
pos.x = Math.max(
Math.min(pos.x, stage.width() - this.width() - PADDING),
PADDING
);
pos.y = stage.height() - PADDING - 10;

return pos;
},
});
scrollLayers.add(horizontalBar);

horizontalBar.on('dragmove', function () {
// delta in %
const availableWidth =
stage.width() - PADDING * 2 - horizontalBar.width();
var delta = (horizontalBar.x() - PADDING) / availableWidth;

layer.x(-(WIDTH - stage.width()) * delta);
});

stage.on('wheel', function (e) {
// prevent parent scrolling
e.evt.preventDefault();
const dx = e.evt.deltaX;
const dy = e.evt.deltaY;

const minX = -(WIDTH - stage.width());
const maxX = 0;

const x = Math.max(minX, Math.min(layer.x() - dx, maxX));

const minY = -(HEIGHT - stage.height());
const maxY = 0;

const y = Math.max(minY, Math.min(layer.y() - dy, maxY));
layer.position({ x, y });

const availableHeight =
stage.height() - PADDING * 2 - verticalBar.height();
const vy =
(layer.y() / (-HEIGHT + stage.height())) * availableHeight + PADDING;
verticalBar.y(vy);

const availableWidth =
stage.width() - PADDING * 2 - horizontalBar.width();

const hx =
(layer.x() / (-WIDTH + stage.width())) * availableWidth + PADDING;
horizontalBar.x(hx);
});
</script>
</body>
</html>
+

+
+ +

4. Emulate screen moving with transform.

That demo works really good, but it may be tricky.
The idea is:

+
    +
  • We will use small canvas with the size of the screen
  • +
  • We will create container with required size (3000x3000), so native scrollbars will be visible
  • +
  • When user is trying to scroll, we will apply css transform for the stage container so it will be still in the center of user’s screen
  • +
  • We will move all nodes so it looks like you scroll (by changing stage position)
  • +
+

Props:

+
    +
  • Works perfect and fast
  • +
  • Native scrolling
  • +
+

Cons:

+
    +
  • You have to understand what is going on.
  • +
+

Instruction: try to scroll with native bars.

+ + +
Show source code! +

+

Canvas Scrolling Transformview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Canvas Scrolling Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
height: 100%;
overflow: auto;
}

#large-container {
width: 3000px;
height: 3000px;
overflow: hidden;
}

#scroll-container {
width: calc(100% - 22px);
height: calc(100vh - 22px);
overflow: auto;
margin: 10px;
border: 1px solid grey;
}
</style>
</head>

<body>
<div id="scroll-container">
<div id="large-container">
<div id="container"></div>
</div>
</div>
<script>
var WIDTH = 3000;
var HEIGHT = 3000;
var NUMBER = 200;

// padding will increase the size of stage
// so scrolling will look smoother
var PADDING = 500;

var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth + PADDING * 2,
height: window.innerHeight + PADDING * 2,
});

var layer = new Konva.Layer();
stage.add(layer);

function generateNode() {
return new Konva.Circle({
x: WIDTH * Math.random(),
y: HEIGHT * Math.random(),
radius: 50,
fill: 'red',
stroke: 'black',
});
}

for (var i = 0; i < NUMBER; i++) {
layer.add(generateNode());
}

var scrollContainer = document.getElementById('scroll-container');
function repositionStage() {
var dx = scrollContainer.scrollLeft - PADDING;
var dy = scrollContainer.scrollTop - PADDING;
stage.container().style.transform =
'translate(' + dx + 'px, ' + dy + 'px)';
stage.x(-dx);
stage.y(-dy);
}
scrollContainer.addEventListener('scroll', repositionStage);
repositionStage();
</script>
</body>
</html>
+

+
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Canvas_to_PDF.html b/docs/sandbox/Canvas_to_PDF.html new file mode 100644 index 000000000..7f6bb3e2d --- /dev/null +++ b/docs/sandbox/Canvas_to_PDF.html @@ -0,0 +1,694 @@ + + + + + + How to convert canvas to pdf | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to convert canvas to pdf

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Do you want to save Konva stage into a PDF file?

PDF is a complicated format. So we have to use an external library such as jsPDF.

+

The idea of saving canvas to pdf is simple:

+
    +
  1. Generate canvas content
  2. +
  3. Export canvas into the image
  4. +
  5. Add image into PDF document created with the PDF library
  6. +
  7. Save PDF file
  8. +
+

Also I have two tips for you:

+
    +
  1. Thanks to High quality Exports, you can increase the quality of a PDF using pixelRatio attribute when you are converting a node into the image.

    +
  2. +
  3. It is possible to make a text selectable in the PDF. Even if we are adding the canvas into the PDF as an image, we can insert texts manually. That is not trivial and it can be difficult if you have complex styles. Also text rendering on PDF is different from the text rendering with Konva. But we can try to make it as close as possible. For the demo, we will draw “hidden” text inside PDF file. The text will be places under the image, so it is no visible. But it is still selectable. As a demo of “complex styles” I will blur the text.

    +
  4. +
+

Instructions: take a look into the canvas. Then try to save it as PDF.

+ + +
Konva PDF demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js"
integrity="sha384-NaWTHo/8YCBYJ59830LTz/P4aQZK1sS0SneOgAvhsIl3zBu8r9RevNg5lHCHAuQ/"
crossorigin="anonymous"
></script>
<meta charset="utf-8" />
<title>Konva PDF Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
#save {
position: absolute;
top: 5px;
left: 5px;
}
</style>
</head>

<body>
<div id="container"></div>
<button id="save">Save as PDF</button>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var back = new Konva.Rect({
width: stage.width(),
height: stage.height(),
fill: 'rgba(200, 200, 200)',
});
layer.add(back);

var text = new Konva.Text({
text: 'This is the Darth Vader',
x: 15,
y: 40,
rotation: -10,
filters: [Konva.Filters.Blur],
blurRadius: 4,
fontSize: 18,
});
text.cache();
layer.add(text);

var arrow = new Konva.Arrow({
points: [70, 50, 100, 80, 150, 100, 190, 100],
tension: 0.5,
stroke: 'black',
fill: 'black',
});
layer.add(arrow);

// alternative API:
Konva.Image.fromURL(
'https://konvajs.org//assets/darth-vader.jpg',
function (darthNode) {
darthNode.setAttrs({
x: 200,
y: 50,
scaleX: 0.5,
scaleY: 0.5,
});
layer.add(darthNode);
}
);

document.getElementById('save').addEventListener('click', function () {
var pdf = new jsPDF('l', 'px', [stage.width(), stage.height()]);
pdf.setTextColor('#000000');
// first add texts
stage.find('Text').forEach((text) => {
const size = text.fontSize() / 0.75; // convert pixels to points
pdf.setFontSize(size);
pdf.text(text.text(), text.x(), text.y(), {
baseline: 'top',
angle: -text.getAbsoluteRotation(),
});
});

// then put image on top of texts (so texts are not visible)
pdf.addImage(
stage.toDataURL({ pixelRatio: 2 }),
0,
0,
stage.width(),
stage.height()
);

pdf.save('canvas.pdf');
});
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Collision_Detection.html b/docs/sandbox/Collision_Detection.html new file mode 100644 index 000000000..7e02430bd --- /dev/null +++ b/docs/sandbox/Collision_Detection.html @@ -0,0 +1,680 @@ + + + + + + Drag and Drop Collision Detection Demo | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Drag and Drop Collision Detection Demo

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to find overlapping objects on the canvas?

In this demo we will use simple collision detection to highlight intersected objects.
For simplicity we will use just bounding boxes to detect collision.

+

Red borders are used to show bounding boxes.

+

Instructions: Drag and drop a shape, see collusion.

+ + +
Konva Drag and Drop Multiple Shapes Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Drag and Drop Collision Detection Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

function createShape() {
var group = new Konva.Group({
x: Math.random() * width,
y: Math.random() * height,
draggable: true,
});
var shape = new Konva.Rect({
width: 30 + Math.random() * 30,
height: 30 + Math.random() * 30,
fill: 'grey',
rotation: 360 * Math.random(),
name: 'fillShape',
});
group.add(shape);

var boundingBox = shape.getClientRect({ relativeTo: group });

var box = new Konva.Rect({
x: boundingBox.x,
y: boundingBox.y,
width: boundingBox.width,
height: boundingBox.height,
stroke: 'red',
strokeWidth: 1,
});
group.add(box);
return group;
}

for (var i = 0; i < 10; i++) {
layer.add(createShape());
}
layer.on('dragmove', function (e) {
var target = e.target;
var targetRect = e.target.getClientRect();
layer.children.forEach(function (group) {
// do not check intersection with itself
if (group === target) {
return;
}
if (haveIntersection(group.getClientRect(), targetRect)) {
group.findOne('.fillShape').fill('red');
} else {
group.findOne('.fillShape').fill('grey');
}
});
});

function haveIntersection(r1, r2) {
return !(
r2.x > r1.x + r1.width ||
r2.x + r2.width < r1.x ||
r2.y > r1.y + r1.height ||
r2.y + r2.height < r1.y
);
}
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Connected_Objects.html b/docs/sandbox/Connected_Objects.html new file mode 100644 index 000000000..4e08791fc --- /dev/null +++ b/docs/sandbox/Connected_Objects.html @@ -0,0 +1,683 @@ + + + + + + Connect objects HTML5 canvas with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Connect objects HTML5 canvas with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to connect two objects with a line or arrow?

Konva can’t connect two objects with a line and update its position automatically. You have to update a line manually as you need it. Usually we need to update line position when a user drag one of the connected objects. In simple cases in can be that:

+
const obj1 = new Konva.Circle({ ...obj1Props })
const obj2= new Konva.Circle({ ...obj2Props });

const line = new Konva.Line({ ...lineProps });

obj1.on('dragmove', updateLine);
obj2.on('dragmove', updateLine);

function updateLine() {
line.points([obj1.x(), obj1.y(), obj2.x(), obj2.y]);
layer.batchDraw();
}
+ +

But in that demo I will create a more complex case with the state of the app and many connected objects.

+

Instructions: try to drag a circle.

+ + +
Konva 20000 Nodes Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Connect Objects demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

// function to generate a list of "targets" (circles)
function generateTargets() {
var number = 10;
var result = [];
while (result.length < number) {
result.push({
id: 'target-' + result.length,
x: stage.width() * Math.random(),
y: stage.height() * Math.random(),
});
}
return result;
}

var targets = generateTargets();

// function to generate arrows between targets
function generateConnectors() {
var number = 10;
var result = [];
while (result.length < number) {
var from = 'target-' + Math.floor(Math.random() * targets.length);
var to = 'target-' + Math.floor(Math.random() * targets.length);
if (from === to) {
continue;
}
result.push({
id: 'connector-' + result.length,
from: from,
to: to,
});
}
return result;
}

function getConnectorPoints(from, to) {
const dx = to.x - from.x;
const dy = to.y - from.y;
let angle = Math.atan2(-dy, dx);

const radius = 50;

return [
from.x + -radius * Math.cos(angle + Math.PI),
from.y + radius * Math.sin(angle + Math.PI),
to.x + -radius * Math.cos(angle),
to.y + radius * Math.sin(angle),
];
}

var connectors = generateConnectors();

// update all objects on the canvas from the state of the app
function updateObjects() {
targets.forEach((target) => {
var node = layer.findOne('#' + target.id);
node.x(target.x);
node.y(target.y);
});
connectors.forEach((connect) => {
var line = layer.findOne('#' + connect.id);
var fromNode = layer.findOne('#' + connect.from);
var toNode = layer.findOne('#' + connect.to);

const points = getConnectorPoints(
fromNode.position(),
toNode.position()
);
line.points(points);
});
}

// generate nodes for the app
connectors.forEach((connect) => {
var line = new Konva.Arrow({
stroke: 'black',
id: connect.id,
fill: 'black',
});
layer.add(line);
});

targets.forEach((target) => {
var node = new Konva.Circle({
id: target.id,
fill: Konva.Util.getRandomColor(),
radius: 20 + Math.random() * 20,
shadowBlur: 10,
draggable: true,
});
layer.add(node);

node.on('dragmove', () => {
// mutate the state
target.x = node.x();
target.y = node.y();

// update nodes from the new state
updateObjects();
});
});

updateObjects();
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Custom_Font.html b/docs/sandbox/Custom_Font.html new file mode 100644 index 000000000..0c831f569 --- /dev/null +++ b/docs/sandbox/Custom_Font.html @@ -0,0 +1,686 @@ + + + + + + How to use custom font for HTML5 canvas? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to use custom font for HTML5 canvas?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to draw external font on html5 canvas?

If you want to use custom font for Konva.Text you just need to:

+
    +
  1. Add font style to your page
  2. +
  3. Set fontFamily attribute to required font-face.
  4. +
+

But there is one important thing here. When you set font for DOM elements (like div or span) browsers will automatically update that elements when font is loaded. But it doesn’t work the same for canvas text. You need to redraw canvas again.

+

To detect that font is loaded you can use something like FontObserver.

+

But for the demo I will use simpler font loading detection. It work ok for many fonts and much smaller in size.

+

Is even simpler solution you can redraw after delay with setTimeout, but it doesn’t guarantee that font is loaded.

+ + +
Konva Custom Fontview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Custom font loading Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>

<!-- CUSTOM FONT STYLES -->
<link
href="https://fonts.googleapis.com/css?family=Kavivanar"
rel="stylesheet"
/>
</head>

<body>
<div id="container"></div>
<script>
// FONT LOADING DETECTION CODE:
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
ctx.font = 'normal 20px Kavivanar';

var isFontLoaded = false;
var TEXT_TEXT = 'Some test text;';
var initialMeasure = ctx.measureText(TEXT_TEXT);
var initialWidth = initialMeasure.width;

// here is how the function works
// different fontFamily may have different width of symbols
// when font is not loaded a browser will use startard font as a fallback
// probably Arial
// when font is loaded measureText will return another width
function whenFontIsLoaded(callback, attemptCount) {
if (attemptCount === undefined) {
attemptCount = 0;
}
if (attemptCount >= 20) {
callback();
return;
}
if (isFontLoaded) {
callback();
return;
}
const metrics = ctx.measureText(TEXT_TEXT);
const width = metrics.width;
if (width !== initialWidth) {
isFontLoaded = true;
callback();
} else {
setTimeout(function () {
whenFontIsLoaded(callback, attemptCount + 1);
}, 1000);
}
}

// NOW build our stage

var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);
var text = new Konva.Text({
x: 50,
y: 50,
fontSize: 40,
text: 'A text with custom font.',
width: 250,
});

layer.add(text);

whenFontIsLoaded(function () {
// set font style when font is loaded
// so Konva will recalculate text wrapping if it has limited width
text.fontFamily('Kavivanar');
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Drag_and_Drop_Multiple_Shapes.html b/docs/sandbox/Drag_and_Drop_Multiple_Shapes.html new file mode 100644 index 000000000..dc5220369 --- /dev/null +++ b/docs/sandbox/Drag_and_Drop_Multiple_Shapes.html @@ -0,0 +1,678 @@ + + + + + + Drag and Drop Multiple Shapes | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Drag and Drop Multiple Shapes

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Instructions: Drag and drop the shapes or remove them by double clicking or double tapping.

+ + +
Konva Drag and Drop Multiple Shapes Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Drag and Drop Multiple Shapes Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'];

for (var i = 0; i < 6; i++) {
var box = new Konva.Rect({
x: i * 30 + 50,
y: i * 18 + 40,
fill: colors[i],
stroke: 'black',
strokeWidth: 4,
draggable: true,
width: 100,
height: 50,
});

box.on('dragstart', function () {
this.moveToTop();
});

box.on('dragmove', function () {
document.body.style.cursor = 'pointer';
});
/*
* dblclick to remove box for desktop app
* and dbltap to remove box for mobile app
*/
box.on('dblclick dbltap', function () {
this.destroy();
});

box.on('mouseover', function () {
document.body.style.cursor = 'pointer';
});
box.on('mouseout', function () {
document.body.style.cursor = 'default';
});

layer.add(box);
}

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Drag_and_Drop_Stress_Test.html b/docs/sandbox/Drag_and_Drop_Stress_Test.html new file mode 100644 index 000000000..6a7093458 --- /dev/null +++ b/docs/sandbox/Drag_and_Drop_Stress_Test.html @@ -0,0 +1,677 @@ + + + + + + Drag and Drop Stress Test with 10,000 Shapes | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Drag and Drop Stress Test with 10,000 Shapes

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+ + +
Konva Drag and Drop Stress Test with 10,000 Shapes Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Drag and Drop Stress Test with 10,000 Shapes Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

function addCircle(layer) {
var color = colors[colorIndex++];
if (colorIndex >= colors.length) {
colorIndex = 0;
}

var randX = Math.random() * stage.width();
var randY = Math.random() * stage.height();
var circle = new Konva.Circle({
x: randX,
y: randY,
radius: 6,
fill: color,
});

layer.add(circle);
}

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var dragLayer = new Konva.Layer();
var colors = [
'red',
'orange',
'yellow',
'green',
'blue',
'cyan',
'purple',
];
var colorIndex = 0;

var layersArr = [];
/*
* create 10 layers each containing 1000 shapes to create
* 10,000 shapes. This greatly improves performance because
* only 1,000 shapes will have to be drawn at a time when a
* circle is removed from a layer rather than all 10,000 shapes.
* Keep in mind that having too many layers can also slow down performance.
* I found that using 10 layers each made up of 1,000 shapes performs better
* than 20 layers with 500 shapes or 5 layers with 2,000 shapes
*/
for (var i = 0; i < 10; i++) {
var layer = new Konva.Layer();
layersArr.push(layer);

for (var n = 0; n < 1000; n++) {
addCircle(layer);
}

stage.add(layer);
}
stage.add(dragLayer);

stage.on('mousedown', function (evt) {
var circle = evt.target;
var layer = circle.getLayer();

circle.moveTo(dragLayer);
circle.startDrag();
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Drop_DOM_Element.html b/docs/sandbox/Drop_DOM_Element.html new file mode 100644 index 000000000..defc4c106 --- /dev/null +++ b/docs/sandbox/Drop_DOM_Element.html @@ -0,0 +1,682 @@ + + + + + + How to drag and drop DOM image into the canvas | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to drag and drop DOM image into the canvas

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

In this demo we will demonstrate how drop DOM element that is placed outside of canvas into the stage.

+

The first image you see is a DOM image. We can use HTML5 drag&drop to enable its dragging.

+

You will need some extra step if you need to enable drag&drop for DOM element on touch devices. You can read here for more info.

+

Instructions: drag&drop yoda into the canvas.

+ + +
Konva Elastic Stars Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Drop DOM element Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#container {
background-color: rgba(0, 0, 0, 0.1);
}

p {
margin: 4px;
}

#drag-items img {
height: 100px;
}
</style>
</head>

<body>
<p>Drag&drop yoda into the grey area.</p>
<div id="drag-items">
<img src="/assets/yoda.jpg" draggable="true" />
<img src="/assets/darth-vader.jpg" draggable="true" />
</div>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var layer = new Konva.Layer();
stage.add(layer);

// what is url of dragging element?
var itemURL = '';
document
.getElementById('drag-items')
.addEventListener('dragstart', function (e) {
itemURL = e.target.src;
});

var con = stage.container();
con.addEventListener('dragover', function (e) {
e.preventDefault(); // !important
});

con.addEventListener('drop', function (e) {
e.preventDefault();
// now we need to find pointer position
// we can't use stage.getPointerPosition() here, because that event
// is not registered by Konva.Stage
// we can register it manually:
stage.setPointersPositions(e);

Konva.Image.fromURL(itemURL, function (image) {
layer.add(image);

image.position(stage.getPointerPosition());
image.draggable(true);
});
});
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Editable_Text.html b/docs/sandbox/Editable_Text.html new file mode 100644 index 000000000..9d4f4775d --- /dev/null +++ b/docs/sandbox/Editable_Text.html @@ -0,0 +1,695 @@ + + + + + + Text editing in HTML5 canvas with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Text editing in HTML5 canvas with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

User can’t directly edit Konva.Text content for many reasons. In fact canvas API is not designed for such purpose.
It is possible to emulate text editing on canvas (by drawing blinking cursor, emulate selection, etc).
Konva has not support for such case. We recommend to edit the user input outside of your canvas with native DOM elements such as input or textarea.

+

Here we will create two demos. Basic demo for general understanding of the technic. And the more complex one, used in real-word app that cover more edge cases.

+

If you want to enable full rich text editing features see Rich Text Demo.

+

Instructions: Double click on text to edit it. Type something. Press Enter.

+

Simple demo:

+ + +
Show source code of simple demo! +

+

Konva Editable text Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Editable Text on html5 canvas Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var textNode = new Konva.Text({
text: 'Some text here',
x: 50,
y: 50,
fontSize: 20,
});

layer.add(textNode);

textNode.on('dblclick dbltap', () => {
// create textarea over canvas with absolute position

// first we need to find position for textarea
// how to find it?

// at first lets find position of text node relative to the stage:
var textPosition = textNode.getAbsolutePosition();

// then lets find position of stage container on the page:
var stageBox = stage.container().getBoundingClientRect();

// so position of textarea will be the sum of positions above:
var areaPosition = {
x: stageBox.left + textPosition.x,
y: stageBox.top + textPosition.y,
};

// create textarea and style it
var textarea = document.createElement('textarea');
document.body.appendChild(textarea);

textarea.value = textNode.text();
textarea.style.position = 'absolute';
textarea.style.top = areaPosition.y + 'px';
textarea.style.left = areaPosition.x + 'px';
textarea.style.width = textNode.width();

textarea.focus();

textarea.addEventListener('keydown', function (e) {
// hide on enter
if (e.keyCode === 13) {
textNode.text(textarea.value);
document.body.removeChild(textarea);
}
});
});
</script>
</body>
</html>
+

+
+ +

Complex demo:

+ + +
Show source code of complex demo! +

+

Canvas Complex Text Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Editable Text on html5 canvas Demo</title>
<style>
body {
margin: 0;
padding: 0;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var textNode = new Konva.Text({
text: 'Some text here',
x: 50,
y: 80,
fontSize: 20,
draggable: true,
width: 200,
});

layer.add(textNode);

var tr = new Konva.Transformer({
node: textNode,
enabledAnchors: ['middle-left', 'middle-right'],
// set minimum width of text
boundBoxFunc: function (oldBox, newBox) {
newBox.width = Math.max(30, newBox.width);
return newBox;
},
});

textNode.on('transform', function () {
// reset scale, so only with is changing by transformer
textNode.setAttrs({
width: textNode.width() * textNode.scaleX(),
scaleX: 1,
});
});

layer.add(tr);

textNode.on('dblclick dbltap', () => {
// hide text node and transformer:
textNode.hide();
tr.hide();

// create textarea over canvas with absolute position
// first we need to find position for textarea
// how to find it?

// at first lets find position of text node relative to the stage:
var textPosition = textNode.absolutePosition();

// so position of textarea will be the sum of positions above:
var areaPosition = {
x: stage.container().offsetLeft + textPosition.x,
y: stage.container().offsetTop + textPosition.y,
};

// create textarea and style it
var textarea = document.createElement('textarea');
document.body.appendChild(textarea);

// apply many styles to match text on canvas as close as possible
// remember that text rendering on canvas and on the textarea can be different
// and sometimes it is hard to make it 100% the same. But we will try...
textarea.value = textNode.text();
textarea.style.position = 'absolute';
textarea.style.top = areaPosition.y + 'px';
textarea.style.left = areaPosition.x + 'px';
textarea.style.width = textNode.width() - textNode.padding() * 2 + 'px';
textarea.style.height =
textNode.height() - textNode.padding() * 2 + 5 + 'px';
textarea.style.fontSize = textNode.fontSize() + 'px';
textarea.style.border = 'none';
textarea.style.padding = '0px';
textarea.style.margin = '0px';
textarea.style.overflow = 'hidden';
textarea.style.background = 'none';
textarea.style.outline = 'none';
textarea.style.resize = 'none';
textarea.style.lineHeight = textNode.lineHeight();
textarea.style.fontFamily = textNode.fontFamily();
textarea.style.transformOrigin = 'left top';
textarea.style.textAlign = textNode.align();
textarea.style.color = textNode.fill();
rotation = textNode.rotation();
var transform = '';
if (rotation) {
transform += 'rotateZ(' + rotation + 'deg)';
}

var px = 0;
// also we need to slightly move textarea on firefox
// because it jumps a bit
var isFirefox =
navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
if (isFirefox) {
px += 2 + Math.round(textNode.fontSize() / 20);
}
transform += 'translateY(-' + px + 'px)';

textarea.style.transform = transform;

// reset height
textarea.style.height = 'auto';
// after browsers resized it we can set actual value
textarea.style.height = textarea.scrollHeight + 3 + 'px';

textarea.focus();

function removeTextarea() {
textarea.parentNode.removeChild(textarea);
window.removeEventListener('click', handleOutsideClick);
textNode.show();
tr.show();
tr.forceUpdate();
}

function setTextareaWidth(newWidth) {
if (!newWidth) {
// set width for placeholder
newWidth = textNode.placeholder.length * textNode.fontSize();
}
// some extra fixes on different browsers
var isSafari = /^((?!chrome|android).)*safari/i.test(
navigator.userAgent
);
var isFirefox =
navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
if (isSafari || isFirefox) {
newWidth = Math.ceil(newWidth);
}

var isEdge =
document.documentMode || /Edge/.test(navigator.userAgent);
if (isEdge) {
newWidth += 1;
}
textarea.style.width = newWidth + 'px';
}

textarea.addEventListener('keydown', function (e) {
// hide on enter
// but don't hide on shift + enter
if (e.keyCode === 13 && !e.shiftKey) {
textNode.text(textarea.value);
removeTextarea();
}
// on esc do not set value back to node
if (e.keyCode === 27) {
removeTextarea();
}
});

textarea.addEventListener('keydown', function (e) {
scale = textNode.getAbsoluteScale().x;
setTextareaWidth(textNode.width() * scale);
textarea.style.height = 'auto';
textarea.style.height =
textarea.scrollHeight + textNode.fontSize() + 'px';
});

function handleOutsideClick(e) {
if (e.target !== textarea) {
textNode.text(textarea.value);
removeTextarea();
}
}
setTimeout(() => {
window.addEventListener('click', handleOutsideClick);
});
});
</script>
</body>
</html>
+

+
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Elastic_Stars.html b/docs/sandbox/Elastic_Stars.html new file mode 100644 index 000000000..35bdf2eb3 --- /dev/null +++ b/docs/sandbox/Elastic_Stars.html @@ -0,0 +1,678 @@ + + + + + + Elastic Stars | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Elastic Stars

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Instructions: Drag and drop the stars and observe the elastic drop on dragend. Refresh the page to randomize the stars again.

+ + +
Konva Elastic Stars Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Elastic Stars Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var tween = null;

function addStar(layer, stage) {
var scale = Math.random();

var star = new Konva.Star({
x: Math.random() * stage.width(),
y: Math.random() * stage.height(),
numPoints: 5,
innerRadius: 30,
outerRadius: 50,
fill: '#89b717',
opacity: 0.8,
draggable: true,
scale: {
x: scale,
y: scale,
},
rotation: Math.random() * 180,
shadowColor: 'black',
shadowBlur: 10,
shadowOffset: {
x: 5,
y: 5,
},
shadowOpacity: 0.6,
startScale: scale,
});

layer.add(star);
}
var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
var dragLayer = new Konva.Layer();

for (var n = 0; n < 10; n++) {
addStar(layer, stage);
}

stage.add(layer);
stage.add(dragLayer);

// bind stage handlers
stage.on('mousedown', function (evt) {
var shape = evt.target;
shape.moveTo(dragLayer);
// restart drag and drop in the new layer
shape.startDrag();
});

stage.on('mouseup', function (evt) {
var shape = evt.target;
shape.moveTo(layer);
});

stage.on('dragstart', function (evt) {
var shape = evt.target;
if (tween) {
tween.pause();
}
shape.setAttrs({
shadowOffset: {
x: 15,
y: 15,
},
scale: {
x: shape.getAttr('startScale') * 1.2,
y: shape.getAttr('startScale') * 1.2,
},
});
});

stage.on('dragend', function (evt) {
var shape = evt.target;

tween = new Konva.Tween({
node: shape,
duration: 0.5,
easing: Konva.Easings.ElasticEaseOut,
scaleX: shape.getAttr('startScale'),
scaleY: shape.getAttr('startScale'),
shadowOffsetX: 5,
shadowOffsetY: 5,
});

tween.play();
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Expand_Images_on_Hover.html b/docs/sandbox/Expand_Images_on_Hover.html new file mode 100644 index 000000000..735615636 --- /dev/null +++ b/docs/sandbox/Expand_Images_on_Hover.html @@ -0,0 +1,679 @@ + + + + + + Expand Image on Hover | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Expand Image on Hover

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Instructions: Mouseover images.

+ + +
Konva Expand Image on Hover Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Expand Image on Hover Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

// darth vader
var darthVaderImg = new Konva.Image({
x: 110,
y: 88,
width: 200,
height: 137,
offset: {
x: 100,
y: 68,
},
draggable: true,
});
layer.add(darthVaderImg);

// yoda
var yodaImg = new Konva.Image({
x: 290,
y: 70,
width: 93,
height: 104,
offset: {
x: 46,
y: 52,
},
draggable: true,
});
layer.add(yodaImg);

var imageObj1 = new Image();
imageObj1.onload = function () {
darthVaderImg.image(imageObj1);
};
imageObj1.src = '/assets/darth-vader.jpg';

var imageObj2 = new Image();
imageObj2.onload = function () {
yodaImg.image(imageObj2);
};
imageObj2.src = '/assets/yoda.jpg';

// use event delegation to update pointer style
// and apply borders
layer.on('mouseover', function (evt) {
var shape = evt.target;
document.body.style.cursor = 'pointer';
shape.scaleX(1.2);
shape.scaleY(1.2);
});
layer.on('mouseout', function (evt) {
var shape = evt.target;
document.body.style.cursor = 'default';
shape.scaleX(1);
shape.scaleY(1);
});
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Free_Drawing.html b/docs/sandbox/Free_Drawing.html new file mode 100644 index 000000000..a721036cc --- /dev/null +++ b/docs/sandbox/Free_Drawing.html @@ -0,0 +1,705 @@ + + + + + + Free Drawing Konva Demo | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Free Drawing Konva Demo

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

There are many ways to implement free drawing tools in Konva.

+

I see two most common and simple ways:

+
    +
  1. Konva-based vector graphics (simple)
  2. +
  3. Manual drawing into 2d canvas (advanced)
  4. +
+

Free drawing with Konva nodes

So the first and probably the simplest ways is:

+
    +
  1. Start a new Konva.Line on mousedown/touchstart
  2. +
  3. Add new point into the line while mousemove/touchmove
  4. +
+

That way works ok for many applications. Also it is simple to store the state of the drawing somewhere in vector representation (like React store or JSON saving into database).

+ + +
Show source code! +

+

Canvas Scrolling Largeview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Free Drawing Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
Tool:
<select id="tool">
<option value="brush">Brush</option>
<option value="eraser">Eraser</option>
</select>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight - 25;

// first we need Konva core things: stage and layer
var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var isPaint = false;
var mode = 'brush';
var lastLine;

stage.on('mousedown touchstart', function (e) {
isPaint = true;
var pos = stage.getPointerPosition();
lastLine = new Konva.Line({
stroke: '#df4b26',
strokeWidth: 5,
globalCompositeOperation:
mode === 'brush' ? 'source-over' : 'destination-out',
// round cap for smoother lines
lineCap: 'round',
lineJoin: 'round',
// add point twice, so we have some drawings even on a simple click
points: [pos.x, pos.y, pos.x, pos.y],
});
layer.add(lastLine);
});

stage.on('mouseup touchend', function () {
isPaint = false;
});

// and core function - drawing
stage.on('mousemove touchmove', function (e) {
if (!isPaint) {
return;
}

// prevent scrolling on touch devices
e.evt.preventDefault();

const pos = stage.getPointerPosition();
var newPoints = lastLine.points().concat([pos.x, pos.y]);
lastLine.points(newPoints);
});

var select = document.getElementById('tool');
select.addEventListener('change', function () {
mode = select.value;
});
</script>
</body>
</html>
+

+
+ + +

Free drawing manually

The first approach has limitation if we want to use some low-level 2d canvas API directly. If you need advanced access to the canvas it is better to use Native Context Access

+

We will create special offscreen canvas where we will add all drawings.
With native access to the canvas we can use low-level 2d context functions.
To display the canvas on the stage we will use Konva.Image.

+ + +
Show source code! +

+

Canvas Scrolling Largeview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Free Drawing Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
Tool:
<select id="tool">
<option value="brush">Brush</option>
<option value="eraser">Eraser</option>
</select>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight - 25;

// first we need Konva core things: stage and layer
var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

// then we are going to draw into special canvas element
var canvas = document.createElement('canvas');
canvas.width = stage.width();
canvas.height = stage.height();

// created canvas we can add to layer as "Konva.Image" element
var image = new Konva.Image({
image: canvas,
x: 0,
y: 0,
});
layer.add(image);

// Good. Now we need to get access to context element
var context = canvas.getContext('2d');
context.strokeStyle = '#df4b26';
context.lineJoin = 'round';
context.lineWidth = 5;

var isPaint = false;
var lastPointerPosition;
var mode = 'brush';

// now we need to bind some events
// we need to start drawing on mousedown
// and stop drawing on mouseup
image.on('mousedown touchstart', function () {
isPaint = true;
lastPointerPosition = stage.getPointerPosition();
});

// will it be better to listen move/end events on the window?

stage.on('mouseup touchend', function () {
isPaint = false;
});

// and core function - drawing
stage.on('mousemove touchmove', function () {
if (!isPaint) {
return;
}

if (mode === 'brush') {
context.globalCompositeOperation = 'source-over';
}
if (mode === 'eraser') {
context.globalCompositeOperation = 'destination-out';
}
context.beginPath();

var localPos = {
x: lastPointerPosition.x - image.x(),
y: lastPointerPosition.y - image.y(),
};
context.moveTo(localPos.x, localPos.y);
var pos = stage.getPointerPosition();
localPos = {
x: pos.x - image.x(),
y: pos.y - image.y(),
};
context.lineTo(localPos.x, localPos.y);
context.closePath();
context.stroke();

lastPointerPosition = pos;
// redraw manually
layer.batchDraw();
});

var select = document.getElementById('tool');
select.addEventListener('change', function () {
mode = select.value;
});
</script>
</body>
</html>
+

+
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/GIF_On_Canvas.html b/docs/sandbox/GIF_On_Canvas.html new file mode 100644 index 000000000..264a53519 --- /dev/null +++ b/docs/sandbox/GIF_On_Canvas.html @@ -0,0 +1,680 @@ + + + + + + How to animate GIF on Canvas | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to animate GIF on Canvas

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

You can’t directly insert GIF image into the canvas. But we can use external library to parse the gif and then we can draw it into the layer as Konva.Image shape.

+

In this demo I will use gifler to parse and draw the gif. You can use any other library.

+ + +
Konva GIF demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<script src="https://unpkg.com/gifler@0.1.0/gifler.min.js"></script>
<meta charset="utf-8" />
<title>Konva GIF Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var canvas = document.createElement('canvas');
// use external library to parse and draw gif animation
function onDrawFrame(ctx, frame) {
// update canvas size
canvas.width = frame.width;
canvas.height = frame.height;
// update canvas that we are using for Konva.Image
ctx.drawImage(frame.buffer, 0, 0);
// redraw the layer
layer.draw();
}

gifler('/assets/yoda.gif').frames(canvas, onDrawFrame);

// draw resulted canvas into the stage as Konva.Image
var image = new Konva.Image({
image: canvas,
});
layer.add(image);
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Gestures.html b/docs/sandbox/Gestures.html new file mode 100644 index 000000000..fa4bf65d2 --- /dev/null +++ b/docs/sandbox/Gestures.html @@ -0,0 +1,686 @@ + + + + + + Gesture Events on Canvas Shapes | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Gesture Events on Canvas Shapes

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to listen to swipe, pinch zoom, rotate and other multi-touch gesture events on canvas shapes?

By default Konva supports only basic touch events such as touchstart, touchmove, touchend.

+

You have to implement gesture events manually from that touch events.

+

If you are looking for pan and zoom logic for the whole stage take a look into Multi-touch scale Stage demo.

+

But I was able to slightly change Hammer.js to make it work with Konva!

+

You can find modified hammer.js source code here.

+

Instructions: you can try different gestures on the rectangle such as swipe, rotate, zoom, drag&drop, press.

+

For desktop browsers you can hold Shift key to emulate touch events.

+

Note: this demo is experimental.

+ + +
Konva Touch Gestures Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<!-- emulate touches on desktop -->
<script src="https://cdn.rawgit.com/hammerjs/touchemulator/master/touch-emulator.js"></script>
<!-- 3-rd party library for gesture events -->
<script src="/js/hammer-konva.js"></script>

<meta charset="utf-8" />
<title>Konva Touch Gestures Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
TouchEmulator();
Konva.hitOnDragEnabled = true;
Konva.captureTouchEventsEnabled = true;

var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var originalAttrs = {
x: stage.width() / 2,
y: stage.height() / 2,
scaleX: 1,
scaleY: 1,
draggable: true,
rotation: 0,
};

var group = new Konva.Group(originalAttrs);
layer.add(group);

var size = 200;

var rect = new Konva.Rect({
width: size,
height: size,
fill: 'yellow',
offsetX: size / 2,
offsetY: size / 2,
cornerRadius: 5,
shadowBlur: 10,
shadowColor: 'grey',
});
group.add(rect);

var defaultText = 'Try\ndrag, swipe, pinch zoom, rotate, press...';
var text = new Konva.Text({
text: defaultText,
x: -size / 2,
width: size,
align: 'center',
});
group.add(text);

// attach modified version of Hammer.js
// "domEvents" property will allow triggering events on group
// instead of "hammertime" instance
var hammertime = new Hammer(group, { domEvents: true });

// add rotate gesture
hammertime.get('rotate').set({ enable: true });

// now attach all possible events
group.on('swipe', function (ev) {
text.text('swiping');
group.to({
x: group.x() + ev.evt.gesture.deltaX,
y: group.y() + ev.evt.gesture.deltaY,

onFinish: function () {
group.to(Object.assign({}, originalAttrs));
text.text(defaultText);
},
});
});

group.on('press', function (ev) {
text.text('Under press');
rect.to({
fill: 'green',
});
});

group.on('touchend', function (ev) {
rect.to({
fill: 'yellow',
});

setTimeout(() => {
text.text(defaultText);
}, 300);
});

group.on('dragend', () => {
group.to(Object.assign({}, originalAttrs));
});

var oldRotation = 0;
var startScale = 0;
group.on('rotatestart', function (ev) {
oldRotation = ev.evt.gesture.rotation;
startScale = rect.scaleX();
group.stopDrag();
group.draggable(false);
text.text('rotating...');
});

group.on('rotate', function (ev) {
var delta = oldRotation - ev.evt.gesture.rotation;
group.rotate(-delta);
oldRotation = ev.evt.gesture.rotation;
group.scaleX(startScale * ev.evt.gesture.scale);
group.scaleY(startScale * ev.evt.gesture.scale);
});

group.on('rotateend rotatecancel', function (ev) {
group.to(Object.assign({}, originalAttrs));
text.text(defaultText);
group.draggable(true);
});
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Image_Border.html b/docs/sandbox/Image_Border.html new file mode 100644 index 000000000..b47768cd5 --- /dev/null +++ b/docs/sandbox/Image_Border.html @@ -0,0 +1,681 @@ + + + + + + Border for Image around Non Transparent parts | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Border for Image around Non Transparent parts

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How do draw a stroke around image with alpha channel?

This demo demonstrate how to use custom filters with Konva framework.

+

For more information about custom filters take a look into Custom Filter Tutorial.

+

In this demo we will create custom filter that will draw solid border around image following its contour.
Since following contour is a complex thing we will use a hack. So we will use blurred shadow as a border foundation.
We will replace transparent/blurred pixels with our solid color that we want for border.

+

For all available filters go to Filters Documentation.

+ + +
Konva Custom Filter Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Border Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();
stage.add(layer);

Konva.Image.fromURL('/assets/lion.png', function (image) {
layer.add(image);
image.setAttrs({
x: 80,
y: 30,
borderSize: 5,
borderColor: 'red',
});

image.filters([Border]);
image.cache();
});

// now we will define our border filter

var canvas = document.createElement('canvas');
var tempCanvas = document.createElement('canvas');

// make all pixels opaque 100% (except pixels that 100% transparent)
function removeTransparency(canvas) {
var ctx = canvas.getContext('2d');

var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
var nPixels = imageData.data.length;
for (var i = 3; i < nPixels; i += 4) {
if (imageData.data[i] > 0) {
imageData.data[i] = 255;
}
}
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.putImageData(imageData, 0, 0);
return canvas;
}

function Border(imageData) {
var nPixels = imageData.data.length;

var size = this.getAttr('borderSize') || 0;

// - first set correct dimensions for canvases
canvas.width = imageData.width;
canvas.height = imageData.height;

tempCanvas.width = imageData.width;
tempCanvas.height = imageData.height;

// - the draw original shape into temp canvas
tempCanvas.getContext('2d').putImageData(imageData, 0, 0);

// - then we need to remove alpha chanel, because it will affect shadow (transparent shapes has smaller shadow)
removeTransparency(tempCanvas);

var ctx = canvas.getContext('2d');
var color = this.getAttr('borderColor') || 'black';

// 3. we will use shadow as border
// so we just need apply shadow on the original image
ctx.save();
ctx.shadowColor = color;
ctx.shadowBlur = size;
ctx.drawImage(tempCanvas, 0, 0);
ctx.restore();

// - Then we will dive in into image data of [original image + shadow]
// and remove transparency from shadow
var tempImageData = ctx.getImageData(0, 0, canvas.width, canvas.height);

var SMOOTH_MIN_THRESHOLD = 3;
var SMOOTH_MAX_THRESHOLD = 10;

let val, hasValue;

var offset = 3;

for (var i = 3; i < nPixels; i += 4) {
// skip opaque pixels
if (imageData.data[i] === 255) {
continue;
}

val = tempImageData.data[i];
hasValue = val !== 0;
if (!hasValue) {
continue;
}
if (val > SMOOTH_MAX_THRESHOLD) {
val = 255;
} else if (val < SMOOTH_MIN_THRESHOLD) {
val = 0;
} else {
val =
((val - SMOOTH_MIN_THRESHOLD) /
(SMOOTH_MAX_THRESHOLD - SMOOTH_MIN_THRESHOLD)) *
255;
}
tempImageData.data[i] = val;
}

// draw resulted image (original + shadow without opacity) into canvas
ctx.putImageData(tempImageData, 0, 0);

// then fill whole image with color (after that shadow is colored)
ctx.save();
ctx.globalCompositeOperation = 'source-in';
ctx.fillStyle = color;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.restore();

// then we need to copy colored shadow into original imageData
var newImageData = ctx.getImageData(0, 0, canvas.width, canvas.height);

var indexesToProcess = [];
for (var i = 3; i < nPixels; i += 4) {
var hasTransparentOnTop =
imageData.data[i - imageData.width * 4 * offset] === 0;
var hasTransparentOnTopRight =
imageData.data[i - (imageData.width * 4 + 4) * offset] === 0;
var hasTransparentOnTopLeft =
imageData.data[i - (imageData.width * 4 - 4) * offset] === 0;
var hasTransparentOnRight = imageData.data[i + 4 * offset] === 0;
var hasTransparentOnLeft = imageData.data[i - 4 * offset] === 0;
var hasTransparentOnBottom =
imageData.data[i + imageData.width * 4 * offset] === 0;
var hasTransparentOnBottomRight =
imageData.data[i + (imageData.width * 4 + 4) * offset] === 0;
var hasTransparentOnBottomLeft =
imageData.data[i + (imageData.width * 4 - 4) * offset] === 0;
var hasTransparentAround =
hasTransparentOnTop ||
hasTransparentOnRight ||
hasTransparentOnLeft ||
hasTransparentOnBottom ||
hasTransparentOnTopRight ||
hasTransparentOnTopLeft ||
hasTransparentOnBottomRight ||
hasTransparentOnBottomLeft;

// if pixel presented in original image - skip it
// because we need to change only shadow area
if (
imageData.data[i] === 255 ||
(imageData.data[i] && !hasTransparentAround)
) {
continue;
}
if (!newImageData.data[i]) {
// skip transparent pixels
continue;
}
indexesToProcess.push(i);
}

for (var index = 0; index < indexesToProcess.length; index += 1) {
var i = indexesToProcess[index];

var alpha = imageData.data[i] / 255;

if (alpha > 0 && alpha < 1) {
var aa = 1 + 1;
}
imageData.data[i] = newImageData.data[i];
imageData.data[i - 1] =
newImageData.data[i - 1] * (1 - alpha) +
imageData.data[i - 1] * alpha;
imageData.data[i - 2] =
newImageData.data[i - 2] * (1 - alpha) +
imageData.data[i - 2] * alpha;
imageData.data[i - 3] =
newImageData.data[i - 3] * (1 - alpha) +
imageData.data[i - 3] * alpha;

if (newImageData.data[i] < 255 && alpha > 0) {
var bb = 1 + 1;
}
}
}
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Image_Border_Highlighting.html b/docs/sandbox/Image_Border_Highlighting.html new file mode 100644 index 000000000..70cf0657a --- /dev/null +++ b/docs/sandbox/Image_Border_Highlighting.html @@ -0,0 +1,679 @@ + + + + + + Drag and Drop Multiple Images with Border Highlighting | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Drag and Drop Multiple Images with Border Highlighting

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+ + +
Konva Image Border Highlighting Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Image Border Highlighting Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

// darth vader
var darthVaderImg = new Konva.Image({
x: 20,
y: 20,
width: 200,
height: 137,
stroke: 'red',
strokeWidth: 10,
draggable: true,
});
layer.add(darthVaderImg);

// yoda
var yodaImg = new Konva.Image({
x: 240,
y: 20,
width: 93,
height: 104,
draggable: true,
stroke: 'red',
strokeWidth: 10,
});
layer.add(yodaImg);

var imageObj1 = new Image();
imageObj1.onload = function () {
darthVaderImg.image(imageObj1);
};
imageObj1.src = '/assets/darth-vader.jpg';

var imageObj2 = new Image();
imageObj2.onload = function () {
yodaImg.image(imageObj2);
};
imageObj2.src = '/assets/yoda.jpg';

// use event delegation to update pointer style
// and apply borders
layer.on('mouseover', function (evt) {
var shape = evt.target;
document.body.style.cursor = 'pointer';
shape.strokeEnabled(false);
});
layer.on('mouseout', function (evt) {
var shape = evt.target;
document.body.style.cursor = 'default';
shape.strokeEnabled(true);
});
</script>
</body>
</html>
+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Image_Labeling.html b/docs/sandbox/Image_Labeling.html new file mode 100644 index 000000000..4b31379ef --- /dev/null +++ b/docs/sandbox/Image_Labeling.html @@ -0,0 +1,679 @@ + + + + + + Drawing Labels on Image with canvas | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Drawing Labels on Image with canvas

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

This is a prototype version of image labeling system I made for one of my clients.

+

Please read Full Blog Post about the process of making the prototype.

+

The widget is made with React, Konva and react-konva libraries.

+

It is not required to use React for such apps. But it was used here because the main application (where the system was used) is made with React.

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Image_Resize.html b/docs/sandbox/Image_Resize.html new file mode 100644 index 000000000..281afe33e --- /dev/null +++ b/docs/sandbox/Image_Resize.html @@ -0,0 +1,680 @@ + + + + + + HTML5 Canvas Drag, Drop, and Resize Images Demo | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Drag, Drop, and Resize Images Demo

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

The demo shows how to manually implement resizing of a shape with Konva shapes primitives.

+

But also we have a built-it methods for such cases with special Konva.Transformer node. Take a look into Select and Transform demo.

+ + +
Konva Drag, Drop, and Resize Images Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Image Resize Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

function update(activeAnchor) {
var group = activeAnchor.getParent();

var topLeft = group.findOne('.topLeft');
var topRight = group.findOne('.topRight');
var bottomRight = group.findOne('.bottomRight');
var bottomLeft = group.findOne('.bottomLeft');
var image = group.findOne('Image');

var anchorX = activeAnchor.x();
var anchorY = activeAnchor.y();

// update anchor positions
switch (activeAnchor.getName()) {
case 'topLeft':
topRight.y(anchorY);
bottomLeft.x(anchorX);
break;
case 'topRight':
topLeft.y(anchorY);
bottomRight.x(anchorX);
break;
case 'bottomRight':
bottomLeft.y(anchorY);
topRight.x(anchorX);
break;
case 'bottomLeft':
bottomRight.y(anchorY);
topLeft.x(anchorX);
break;
}

image.position(topLeft.position());

var width = topRight.x() - topLeft.x();
var height = bottomLeft.y() - topLeft.y();
if (width && height) {
image.width(width);
image.height(height);
}
}
function addAnchor(group, x, y, name) {
var stage = group.getStage();
var layer = group.getLayer();

var anchor = new Konva.Circle({
x: x,
y: y,
stroke: '#666',
fill: '#ddd',
strokeWidth: 2,
radius: 8,
name: name,
draggable: true,
dragOnTop: false,
});

anchor.on('dragmove', function () {
update(this);
});
anchor.on('mousedown touchstart', function () {
group.draggable(false);
this.moveToTop();
});
anchor.on('dragend', function () {
group.draggable(true);
});
// add hover styling
anchor.on('mouseover', function () {
var layer = this.getLayer();
document.body.style.cursor = 'pointer';
this.strokeWidth(4);
});
anchor.on('mouseout', function () {
var layer = this.getLayer();
document.body.style.cursor = 'default';
this.strokeWidth(2);
});

group.add(anchor);
}

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

// darth vader
var darthVaderImg = new Konva.Image({
width: 200,
height: 137,
});

// yoda
var yodaImg = new Konva.Image({
width: 93,
height: 104,
});

var darthVaderGroup = new Konva.Group({
x: 180,
y: 50,
draggable: true,
});
layer.add(darthVaderGroup);
darthVaderGroup.add(darthVaderImg);
addAnchor(darthVaderGroup, 0, 0, 'topLeft');
addAnchor(darthVaderGroup, 200, 0, 'topRight');
addAnchor(darthVaderGroup, 200, 138, 'bottomRight');
addAnchor(darthVaderGroup, 0, 138, 'bottomLeft');

var yodaGroup = new Konva.Group({
x: 20,
y: 110,
draggable: true,
});
layer.add(yodaGroup);
yodaGroup.add(yodaImg);
addAnchor(yodaGroup, 0, 0, 'topLeft');
addAnchor(yodaGroup, 93, 0, 'topRight');
addAnchor(yodaGroup, 93, 104, 'bottomRight');
addAnchor(yodaGroup, 0, 104, 'bottomLeft');

var imageObj1 = new Image();
imageObj1.onload = function () {
darthVaderImg.image(imageObj1);
};
imageObj1.src = '/assets/darth-vader.jpg';

var imageObj2 = new Image();
imageObj2.onload = function () {
yodaImg.image(imageObj2);
};
imageObj2.src = '/assets/yoda.jpg';
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Interactive_Building_Map.html b/docs/sandbox/Interactive_Building_Map.html new file mode 100644 index 000000000..7280e8a25 --- /dev/null +++ b/docs/sandbox/Interactive_Building_Map.html @@ -0,0 +1,678 @@ + + + + + + Interactive Building Map | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Interactive Building Map

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Instructions: hover over sections of the building to see its description

+ + +
Konva Interactive Building Map Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Interactive Building Map Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
#container {
background: black url('/assets/line-building.png') no-repeat 1px 0px;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

function getData() {
return {
'1st Floor': {
color: 'blue',
points: [366, 298, 500, 284, 499, 204, 352, 183, 72, 228, 74, 274],
},
'2nd Floor': {
color: 'red',
points: [72, 228, 73, 193, 340, 96, 498, 154, 498, 191, 341, 171],
},
'3rd Floor': {
color: 'yellow',
points: [73, 192, 73, 160, 340, 23, 500, 109, 499, 139, 342, 93],
},
Gym: {
color: 'green',
points: [
498, 283, 503, 146, 560, 136, 576, 144, 576, 278, 500, 283,
],
},
};
}
function updateTooltip(tooltip, x, y, text) {
tooltip.getText().text(text);
tooltip.position({
x: x,
y: y,
});
tooltip.show();
}
var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var shapesLayer = new Konva.Layer();
var tooltipLayer = new Konva.Layer();

var tooltip = new Konva.Label({
opacity: 0.75,
visible: false,
listening: false,
});

tooltip.add(
new Konva.Tag({
fill: 'black',
pointerDirection: 'down',
pointerWidth: 10,
pointerHeight: 10,
lineJoin: 'round',
shadowColor: 'black',
shadowBlur: 10,
shadowOffsetX: 10,
shadowOffsetY: 10,
shadowOpacity: 0.5,
})
);

tooltip.add(
new Konva.Text({
text: '',
fontFamily: 'Calibri',
fontSize: 18,
padding: 5,
fill: 'white',
})
);

tooltipLayer.add(tooltip);

// get areas data
var areas = getData();

// draw areas
for (var key in areas) {
var area = areas[key];
var points = area.points;

var shape = new Konva.Line({
points: points,
fill: area.color,
opacity: 0,
closed: true,
// custom attr
key: key,
});

shapesLayer.add(shape);
}

stage.add(shapesLayer);
stage.add(tooltipLayer);

stage.on('mouseover', function (evt) {
var shape = evt.target;
if (shape) {
shape.opacity(0.5);
}
});
stage.on('mouseout', function (evt) {
var shape = evt.target;
if (shape) {
shape.opacity(0);
tooltip.hide();
}
});
stage.on('mousemove', function (evt) {
var shape = evt.target;
if (shape) {
var mousePos = stage.getPointerPosition();
var x = mousePos.x;
var y = mousePos.y - 5;
updateTooltip(tooltip, x, y, shape.attrs.key);
}
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Jumping_Bunnies.html b/docs/sandbox/Jumping_Bunnies.html new file mode 100644 index 000000000..748517d59 --- /dev/null +++ b/docs/sandbox/Jumping_Bunnies.html @@ -0,0 +1,686 @@ + + + + + + Jumping bunnies performance stress test | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Jumping bunnies performance stress test

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

The demo shows performance of moving many Konva.Image‘s at the same time.

+

That is adopted demo from the PixiJS framework.

+

You will notice that Konva version is much slower than PixiJS version.

+

So first of all I am not hiding that other frameworks may work better in some situations. PixiJS is very optimized for such types of graphics and animations (it uses WebGL for rendering).

+

There is a work in progress for optimizing some Konva internals to make it work faster for that demo too.

+

But remember that the demo doesn’t represent the performance of typical application made with Konva. If you are doing a lot of animations like in the demo with tons of objects you may need to use other solutions like Native Canvas Access or even a different framework.

+

So choose wisely the tool for your applications.

+

Instructions: mousedown on the canvas to add more bunnies.

+ + +
Konva Bunnies Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Jumping Bunnies Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#counter {
position: absolute;
top: 50px;
background-color: white;
font-size: 12px;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="counter"></div>
<script src="https://mrdoob.github.io/stats.js/build/stats.min.js"></script>
<script defer="defer">
var lastTime = 0;

var width = window.innerWidth;
var height = window.innerHeight;

var bunnys = [];
var GRAVITY = 0.75;

var maxX = width;
var minX = 0;
var maxY = height;
var minY = 0;

var startBunnyCount = 1000;
var isAdding = false;
var count = 0;
var amount = 10;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var layer = new Konva.FastLayer();
stage.add(layer);

var wabbitTexture = new Image();
wabbitTexture.onload = function () {
_handleTextureLoaded();
};
wabbitTexture.src = 'https://konvajs.org/assets/bunny.png';

var stats = new Stats();
document.body.appendChild(stats.domElement);
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';

window.requestAnimationFrame(update);

var counter = document.getElementById('counter');

count = startBunnyCount;
counter.innerHTML = startBunnyCount + ' BUNNIES';

stage.on('mousedown', function () {
isAdding = true;
});

stage.on('mouseup', function () {
isAdding = false;
});

document.addEventListener('touchstart', onTouchStart, true);
document.addEventListener('touchend', onTouchEnd, true);

function _handleTextureLoaded(event) {
for (var i = 0; i < startBunnyCount; i++) {
var bunny = new Konva.Image({
image: wabbitTexture,
transformsEnabled: 'position',
perfectDrawEnabled: false,
x: 10,
y: 10,
});

bunny.speedX = Math.random() * 10;
bunny.speedY = Math.random() * 10 - 5;

bunnys.push(bunny);
layer.add(bunny);
}
}

function onTouchStart(event) {
isAdding = true;
}

function onTouchEnd(event) {
isAdding = false;
}

function update() {
stats.begin();
if (isAdding) {
for (var i = 0; i < amount; i++) {
var bunny = new Konva.Image({
image: wabbitTexture,
transformsEnabled: 'position',
perfectDrawEnabled: false,
x: 0,
y: 0,
});
bunny.speedX = Math.random() * 10;
bunny.speedY = Math.random() * 10 - 5;
bunnys.push(bunny);
layer.add(bunny);

count++;
}
counter.innerHTML = count + ' BUNNIES';
}

for (var i = 0; i < bunnys.length; i++) {
var bunny = bunnys[i];
var pos = {
x: bunny.x(),
y: bunny.y(),
};
pos.x = pos.x + bunny.speedX;
pos.y = pos.y + bunny.speedY;
bunny.speedY += GRAVITY;
if (pos.x > maxX - wabbitTexture.width) {
bunny.speedX *= -1;
pos.x = maxX - wabbitTexture.width;
} else if (pos.x < minX) {
bunny.speedX *= -1;
pos.x = minX;
}

if (pos.y > maxY - wabbitTexture.height) {
bunny.speedY *= -0.85;
pos.y = maxY - wabbitTexture.height;
if (Math.random() > 0.5) {
bunny.speedY -= Math.random() * 6;
}
} else if (pos.y < minY) {
bunny.speedY = 0;
pos.y = minY;
}
bunny.position({
x: pos.x,
y: pos.y,
});
}
requestAnimationFrame(update);
stats.end();
}
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Limited_Drag_And_Resize.html b/docs/sandbox/Limited_Drag_And_Resize.html new file mode 100644 index 000000000..fd7013732 --- /dev/null +++ b/docs/sandbox/Limited_Drag_And_Resize.html @@ -0,0 +1,680 @@ + + + + + + How to limit dragging and resizing of shapes by canvas stage? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to limit dragging and resizing of shapes by canvas stage?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

We can use a combination of Drag Limit Demo and Resize Limit Demo to add some restrictions to shapes changes by the user.

+

Instructions: try to rotate, drag or resize shapes out of canvas.

+ + +
Limited_Drag_And_Resize.htmlview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Drag and Drop Multiple Shapes Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
// define several math function
function getCorner(pivotX, pivotY, diffX, diffY, angle) {
const distance = Math.sqrt(diffX * diffX + diffY * diffY);

/// find angle from pivot to corner
angle += Math.atan2(diffY, diffX);

/// get new x and y and round it off to integer
const x = pivotX + distance * Math.cos(angle);
const y = pivotY + distance * Math.sin(angle);

return { x: x, y: y };
}
function getClientRect(rotatedBox) {
const { x, y, width, height } = rotatedBox;
const rad = rotatedBox.rotation;

const p1 = getCorner(x, y, 0, 0, rad);
const p2 = getCorner(x, y, width, 0, rad);
const p3 = getCorner(x, y, width, height, rad);
const p4 = getCorner(x, y, 0, height, rad);

const minX = Math.min(p1.x, p2.x, p3.x, p4.x);
const minY = Math.min(p1.y, p2.y, p3.y, p4.y);
const maxX = Math.max(p1.x, p2.x, p3.x, p4.x);
const maxY = Math.max(p1.y, p2.y, p3.y, p4.y);

return {
x: minX,
y: minY,
width: maxX - minX,
height: maxY - minY,
};
}

function getTotalBox(boxes) {
let minX = Infinity;
let minY = Infinity;
let maxX = -Infinity;
let maxY = -Infinity;

boxes.forEach((box) => {
minX = Math.min(minX, box.x);
minY = Math.min(minY, box.y);
maxX = Math.max(maxX, box.x + box.width);
maxY = Math.max(maxY, box.y + box.height);
});
return {
x: minX,
y: minY,
width: maxX - minX,
height: maxY - minY,
};
}

const stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

const layer = new Konva.Layer();
stage.add(layer);

const shape1 = new Konva.Rect({
x: stage.width() / 2 - 60,
y: stage.height() / 2 - 60,
width: 50,
height: 50,
fill: 'red',
draggable: true,
});
layer.add(shape1);

const shape2 = shape1.clone({
x: stage.width() / 2 + 10,
y: stage.height() / 2 + 10,
fill: 'green',
});
layer.add(shape2);

const tr = new Konva.Transformer({
nodes: [shape1, shape2],
boundBoxFunc: (oldBox, newBox) => {
const box = getClientRect(newBox);
const isOut =
box.x < 0 ||
box.y < 0 ||
box.x + box.width > stage.width() ||
box.y + box.height > stage.height();

// if new bounding box is out of visible viewport, let's just skip transforming
// this logic can be improved by still allow some transforming if we have small available space
if (isOut) {
return oldBox;
}
return newBox;
},
});
layer.add(tr);

// we can use transformer event
// or just shape event
tr.on('dragmove', () => {
const boxes = tr.nodes().map((node) => node.getClientRect());
const box = getTotalBox(boxes);
tr.nodes().forEach((shape) => {
const absPos = shape.getAbsolutePosition();
// where are shapes inside bounding box of all shapes?
const offsetX = box.x - absPos.x;
const offsetY = box.y - absPos.y;

// we total box goes outside of viewport, we need to move absolute position of shape
const newAbsPos = { ...absPos };
if (box.x < 0) {
newAbsPos.x = -offsetX;
}
if (box.y < 0) {
newAbsPos.y = -offsetY;
}
if (box.x + box.width > stage.width()) {
newAbsPos.x = stage.width() - box.width - offsetX;
}
if (box.y + box.height > stage.height()) {
newAbsPos.y = stage.height() - box.height - offsetY;
}
shape.setAbsolutePosition(newAbsPos);
});
});
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Mirror_Canvas_Shape.html b/docs/sandbox/Mirror_Canvas_Shape.html new file mode 100644 index 000000000..13e02baab --- /dev/null +++ b/docs/sandbox/Mirror_Canvas_Shape.html @@ -0,0 +1,682 @@ + + + + + + How to flip shapes or image on canvas? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to flip shapes or image on canvas?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Is it possible mirror shapes vertically or horizontally?

To flip any node with Konva you can use negative scaleX to flip it horizontally or scaleY to flip it vertically.

+

Remember that scale properties are working relative to origin of a node. For example for rectangle it will be top-left corner, for circle it will be its center. If you want to change origin of a node you can use offsetX and offsetY properties. To better understanding origin and offset, take a look into Position vs Offset post.

+

Depending on your use case, you may need to manually change {x, y} properties of the node to keep it on its original position after the scale.

+

Instructions: click on flip button, see how they are mirrored.

+ + +
Konva Mirror Shapeview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Transparency for several Shapes Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background: #f0f0f0;
}

#flip {
position: absolute;
top: 5px;
left: 5px;
}
</style>
</head>

<body>
<div id="container"></div>
<button id="flip">Flip horizontally</button>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var text1 = new Konva.Text({
x: 180,
y: 50,
text: 'Default text with no offset. Its origin is in top left corner.',
align: 'center',
width: 200,
});
layer.add(text1);

var text2 = new Konva.Text({
text: 'Text with the origin in its center',
width: 200,
align: 'center',
y: 100,
x: 270,
});
layer.add(text2);
// set horizontal origin in the center of the text
text2.offsetX(text2.width() / 2);

document.querySelector('#flip').addEventListener('click', () => {
layer.find('Text').forEach((text) => {
text.to({
scaleX: -text.scaleX(),
});
});
});
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Modify_Curves_with_Anchor_Points.html b/docs/sandbox/Modify_Curves_with_Anchor_Points.html new file mode 100644 index 000000000..4a73bd987 --- /dev/null +++ b/docs/sandbox/Modify_Curves_with_Anchor_Points.html @@ -0,0 +1,678 @@ + + + + + + Modify Curves with Anchor Points | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Modify Curves with Anchor Points

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to modify line points with anchors?

Instructions: Use your mouse or finger and drag and drop the anchor points to
modify the curvature of the quadratic curve and the Bezier curve.

+ + +
Konva Modify Curves with Anchor Points Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Modify Curves with Anchor Points Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

// function to build anchor point
function buildAnchor(x, y) {
var anchor = new Konva.Circle({
x: x,
y: y,
radius: 20,
stroke: '#666',
fill: '#ddd',
strokeWidth: 2,
draggable: true,
});
layer.add(anchor);

// add hover styling
anchor.on('mouseover', function () {
document.body.style.cursor = 'pointer';
this.strokeWidth(4);
});
anchor.on('mouseout', function () {
document.body.style.cursor = 'default';
this.strokeWidth(2);
});

anchor.on('dragmove', function () {
updateDottedLines();
});

return anchor;
}

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

// function to update line points from anchors
function updateDottedLines() {
var q = quad;
var b = bezier;

var quadLinePath = layer.findOne('#quadLinePath');
var bezierLinePath = layer.findOne('#bezierLinePath');

quadLinePath.points([
q.start.x(),
q.start.y(),
q.control.x(),
q.control.y(),
q.end.x(),
q.end.y(),
]);

bezierLinePath.points([
b.start.x(),
b.start.y(),
b.control1.x(),
b.control1.y(),
b.control2.x(),
b.control2.y(),
b.end.x(),
b.end.y(),
]);
}

// we will use custom shape for curve
var quadraticLine = new Konva.Shape({
stroke: 'red',
strokeWidth: 4,
sceneFunc: (ctx, shape) => {
ctx.beginPath();
ctx.moveTo(quad.start.x(), quad.start.y());
ctx.quadraticCurveTo(
quad.control.x(),
quad.control.y(),
quad.end.x(),
quad.end.y()
);
ctx.fillStrokeShape(shape);
},
});
layer.add(quadraticLine);

// we will use custom shape for curve
var bezierLine = new Konva.Shape({
stroke: 'blue',
strokeWidth: 5,
sceneFunc: (ctx, shape) => {
ctx.beginPath();
ctx.moveTo(bezier.start.x(), bezier.start.y());
ctx.bezierCurveTo(
bezier.control1.x(),
bezier.control1.y(),
bezier.control2.x(),
bezier.control2.y(),
bezier.end.x(),
bezier.end.y()
);
ctx.fillStrokeShape(shape);
},
});
layer.add(bezierLine);

var quadLinePath = new Konva.Line({
dash: [10, 10, 0, 10],
strokeWidth: 3,
stroke: 'black',
lineCap: 'round',
id: 'quadLinePath',
opacity: 0.3,
points: [0, 0],
});
layer.add(quadLinePath);

var bezierLinePath = new Konva.Line({
dash: [10, 10, 0, 10],
strokeWidth: 3,
stroke: 'black',
lineCap: 'round',
id: 'bezierLinePath',
opacity: 0.3,
points: [0, 0],
});
layer.add(bezierLinePath);

// special objects to save references to anchors
var quad = {
start: buildAnchor(60, 30),
control: buildAnchor(240, 110),
end: buildAnchor(80, 160),
};

var bezier = {
start: buildAnchor(280, 20),
control1: buildAnchor(530, 40),
control2: buildAnchor(480, 150),
end: buildAnchor(300, 150),
};

updateDottedLines();
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Modify_Shape_Color_on_Click.html b/docs/sandbox/Modify_Shape_Color_on_Click.html new file mode 100644 index 000000000..2f7f26db8 --- /dev/null +++ b/docs/sandbox/Modify_Shape_Color_on_Click.html @@ -0,0 +1,678 @@ + + + + + + Modify Shape Color on Click | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Modify Shape Color on Click

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Instructions: Click on a shape to change its color

+ + +
Konva Modify Shape Color on Clickview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Modify Shape Color on Click Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var triangle = new Konva.RegularPolygon({
x: 80,
y: 120,
sides: 3,
radius: 50,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
});

triangle.on('click', function () {
var fill = this.fill() == 'yellow' ? '#00D2FF' : 'yellow';
this.fill(fill);
});

layer.add(triangle);

var circle = new Konva.Circle({
x: 180,
y: 120,
radius: 50,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

circle.on('click', function () {
var fill = this.fill() == 'red' ? '#00d00f' : 'red';
this.fill(fill);
});

layer.add(circle);
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Multi-touch_Scale_Shape.html b/docs/sandbox/Multi-touch_Scale_Shape.html new file mode 100644 index 000000000..f59d5d637 --- /dev/null +++ b/docs/sandbox/Multi-touch_Scale_Shape.html @@ -0,0 +1,679 @@ + + + + + + Multi-touch Scale Shape | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Multi-touch Scale Shape

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Note: This lab only works on devices that support multi-touch gestures such as iOS because it makes use of multiple touch events.

+

Instructions: Using a mobile device that supports multi-touch gestures such as iOS, drag and drop a shape by touching it and then dragging your finger across the screen, activate a shape by tapping on it, and scale an active shape by pinching the screen.

+ + +
Konva Multi-touch Scale Shapeview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Multi-touch Scale Shape Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
// by default Konva prevent some events when node is dragging
// it improve the performance and work well for 95% of cases
// we need to enable all events on Konva, even when we are dragging a node
// so it triggers touchmove correctly
Konva.hitOnDragEnabled = true;

var width = window.innerWidth;
var height = window.innerHeight;

var lastDist = 0;
var startScale = 1;
var activeShape = null;

function getDistance(p1, p2) {
return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
}

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
draggable: true,
x: width / 2,
y: height / 2,
offset: {
x: width / 2,
y: height / 2,
},
});

var layer = new Konva.Layer();

var triangle = new Konva.RegularPolygon({
x: 190,
y: stage.height() / 2,
sides: 3,
radius: 80,
fill: 'green',
stroke: 'black',
strokeWidth: 4,
draggable: true,
name: 'triangle',
});

var circle = new Konva.Circle({
x: 380,
y: stage.height() / 2,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
draggable: true,
name: 'circle',
});

stage.on('tap', function (evt) {
// set active shape
var shape = evt.target;
activeShape =
activeShape && activeShape.getName() === shape.getName()
? null
: shape;

// sync scene graph
triangle.setAttrs({
fill:
activeShape && activeShape.getName() === triangle.getName()
? '#78E7FF'
: 'green',
stroke:
activeShape && activeShape.getName() === triangle.getName()
? 'blue'
: 'black',
});

circle.setAttrs({
fill:
activeShape && activeShape.getName() === circle.getName()
? '#78E7FF'
: 'red',
stroke:
activeShape && activeShape.getName() === circle.getName()
? 'blue'
: 'black',
});
});

stage.getContent().addEventListener(
'touchmove',
function (evt) {
var touch1 = evt.touches[0];
var touch2 = evt.touches[1];

if (touch1 && touch2 && activeShape) {
var dist = getDistance(
{
x: touch1.clientX,
y: touch1.clientY,
},
{
x: touch2.clientX,
y: touch2.clientY,
}
);

if (!lastDist) {
lastDist = dist;
}

var scale = (activeShape.scaleX() * dist) / lastDist;

activeShape.scaleX(scale);
activeShape.scaleY(scale);
lastDist = dist;
}
},
false
);

stage.getContent().addEventListener(
'touchend',
function () {
lastDist = 0;
},
false
);

layer.add(triangle);
layer.add(circle);
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Multi-touch_Scale_Stage.html b/docs/sandbox/Multi-touch_Scale_Stage.html new file mode 100644 index 000000000..cff89cf9a --- /dev/null +++ b/docs/sandbox/Multi-touch_Scale_Stage.html @@ -0,0 +1,680 @@ + + + + + + Multi-touch Canvas scale with pinch zoom | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Multi-touch Canvas scale with pinch zoom

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to enable pan and pinch zoom for canvas stage?

Inside touchmove callback we can get access to all native properties of touch events with e.evt.touches. So we just need to manually calculate position and scale properties of the stage, when two pointers are used in touchmove.

+

Note: This lab only works on devices that support multi-touch gestures because it makes use of multiple touch events.

+

Instructions: Using a mobile device that supports multi-touch gestures, use two fingers to zoom in or out of the stage

+ + +
Konva Multi-touch Scale Stageview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Multi-touch Scale Stage Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
// by default Konva prevent some events when node is dragging
// it improve the performance and work well for 95% of cases
// we need to enable all events on Konva, even when we are dragging a node
// so it triggers touchmove correctly
Konva.hitOnDragEnabled = true;

var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
draggable: true,
});

var layer = new Konva.Layer();

var triangle = new Konva.RegularPolygon({
x: 190,
y: stage.height() / 2,
sides: 3,
radius: 80,
fill: 'green',
stroke: 'black',
strokeWidth: 4,
});

var circle = new Konva.Circle({
x: 380,
y: stage.height() / 2,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

function getDistance(p1, p2) {
return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
}

function getCenter(p1, p2) {
return {
x: (p1.x + p2.x) / 2,
y: (p1.y + p2.y) / 2,
};
}
var lastCenter = null;
var lastDist = 0;
var dragStopped = false;

stage.on('touchmove', function (e) {
e.evt.preventDefault();
var touch1 = e.evt.touches[0];
var touch2 = e.evt.touches[1];

// we need to restore dragging, if it was cancelled by multi-touch
if (touch1 && !touch2 && !stage.isDragging() && dragStopped) {
stage.startDrag();
dragStopped = false;
}

if (touch1 && touch2) {
// if the stage was under Konva's drag&drop
// we need to stop it, and implement our own pan logic with two pointers
if (stage.isDragging()) {
dragStopped = true;
stage.stopDrag();
}

var p1 = {
x: touch1.clientX,
y: touch1.clientY,
};
var p2 = {
x: touch2.clientX,
y: touch2.clientY,
};

if (!lastCenter) {
lastCenter = getCenter(p1, p2);
return;
}
var newCenter = getCenter(p1, p2);

var dist = getDistance(p1, p2);

if (!lastDist) {
lastDist = dist;
}

// local coordinates of center point
var pointTo = {
x: (newCenter.x - stage.x()) / stage.scaleX(),
y: (newCenter.y - stage.y()) / stage.scaleX(),
};

var scale = stage.scaleX() * (dist / lastDist);

stage.scaleX(scale);
stage.scaleY(scale);

// calculate new position of the stage
var dx = newCenter.x - lastCenter.x;
var dy = newCenter.y - lastCenter.y;

var newPos = {
x: newCenter.x - pointTo.x * scale + dx,
y: newCenter.y - pointTo.y * scale + dy,
};

stage.position(newPos);

lastDist = dist;
lastCenter = newCenter;
}
});

stage.on('touchend', function (e) {
lastDist = 0;
lastCenter = null;
});

layer.add(triangle);
layer.add(circle);
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Native_Context_Access.html b/docs/sandbox/Native_Context_Access.html new file mode 100644 index 000000000..788bf8a58 --- /dev/null +++ b/docs/sandbox/Native_Context_Access.html @@ -0,0 +1,685 @@ + + + + + + How to access native 2d context | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to access native 2d context

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to access native 2d canvas context from Konva

Konva gives you object model for drawing shapes on canvas. Your app is starting from a stage (div wrapper) and then the stage have one or many layers (canvas DOM elements) inside.

+

You can hijack into Konva internals (or DOM internals) and draw into canvas directly without creating any shapes. But that is not recommended. Because Konva has full control over drawing and may reset your manual drawings or lost them on any export such as stage.toDataURL().

+

There are two recommended ways if you want to draw something manually:

+
    +
  1. Use custom shape
  2. +
  3. Create a new canvas element manually and then use it for Konva.Image.
  4. +
+ + +
Konva 20000 Nodes Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Native Context Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

// if you want to make something with native 2d canvas
//we can create it and use it for Konva.Image

var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');

var image = new Konva.Image({
image: canvas,
draggable: true,
});
layer.add(image);

// make manual drawings
ctx.fillStyle = 'blue';
ctx.fillRect(5, 5, canvas.width - 10, canvas.height / 2);
ctx.fillStyle = 'red';
ctx.beginPath();
ctx.arc(100, 75, 50, 0, 2 * Math.PI);
ctx.fill();

// such as canvas is updated we need to redraw the layer

layer.batchDraw();
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Objects_Snapping.html b/docs/sandbox/Objects_Snapping.html new file mode 100644 index 000000000..460e995e5 --- /dev/null +++ b/docs/sandbox/Objects_Snapping.html @@ -0,0 +1,685 @@ + + + + + + How to snap shapes positions on dragging with Konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to snap shapes positions on dragging with Konva?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to snap draggable shapes to each other?

This demo will demonstrate how to implement snapping of objects to all edges of the stage on to all edges of other objects.

+

Also I found another related demos on the internet that may be useful:

+
    +
  1. Post: https://medium.com/@pierrebleroux/snap-to-grid-with-konvajs-c41eae97c13f
  2. +
  3. Demo:https://codepen.io/pierrebleroux/pen/gGpvxJ
  4. +
+

Instruction: try to drag and object. See how it snaps to other objects.

+ + +
Konva Custom Fontview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Snapping of shapes Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;
var GUIDELINE_OFFSET = 5;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

// first generate random rectangles
for (var i = 0; i < 5; i++) {
layer.add(
new Konva.Rect({
x: Math.random() * stage.width(),
y: Math.random() * stage.height(),
width: 50 + Math.random() * 50,
height: 50 + Math.random() * 50,
fill: Konva.Util.getRandomColor(),
rotation: Math.random() * 360,
draggable: true,
name: 'object',
})
);
}

// were can we snap our objects?
function getLineGuideStops(skipShape) {
// we can snap to stage borders and the center of the stage
var vertical = [0, stage.width() / 2, stage.width()];
var horizontal = [0, stage.height() / 2, stage.height()];

// and we snap over edges and center of each object on the canvas
stage.find('.object').forEach((guideItem) => {
if (guideItem === skipShape) {
return;
}
var box = guideItem.getClientRect();
// and we can snap to all edges of shapes
vertical.push([box.x, box.x + box.width, box.x + box.width / 2]);
horizontal.push([box.y, box.y + box.height, box.y + box.height / 2]);
});
return {
vertical: vertical.flat(),
horizontal: horizontal.flat(),
};
}

// what points of the object will trigger to snapping?
// it can be just center of the object
// but we will enable all edges and center
function getObjectSnappingEdges(node) {
var box = node.getClientRect();
var absPos = node.absolutePosition();

return {
vertical: [
{
guide: Math.round(box.x),
offset: Math.round(absPos.x - box.x),
snap: 'start',
},
{
guide: Math.round(box.x + box.width / 2),
offset: Math.round(absPos.x - box.x - box.width / 2),
snap: 'center',
},
{
guide: Math.round(box.x + box.width),
offset: Math.round(absPos.x - box.x - box.width),
snap: 'end',
},
],
horizontal: [
{
guide: Math.round(box.y),
offset: Math.round(absPos.y - box.y),
snap: 'start',
},
{
guide: Math.round(box.y + box.height / 2),
offset: Math.round(absPos.y - box.y - box.height / 2),
snap: 'center',
},
{
guide: Math.round(box.y + box.height),
offset: Math.round(absPos.y - box.y - box.height),
snap: 'end',
},
],
};
}

// find all snapping possibilities
function getGuides(lineGuideStops, itemBounds) {
var resultV = [];
var resultH = [];

lineGuideStops.vertical.forEach((lineGuide) => {
itemBounds.vertical.forEach((itemBound) => {
var diff = Math.abs(lineGuide - itemBound.guide);
// if the distance between guild line and object snap point is close we can consider this for snapping
if (diff < GUIDELINE_OFFSET) {
resultV.push({
lineGuide: lineGuide,
diff: diff,
snap: itemBound.snap,
offset: itemBound.offset,
});
}
});
});

lineGuideStops.horizontal.forEach((lineGuide) => {
itemBounds.horizontal.forEach((itemBound) => {
var diff = Math.abs(lineGuide - itemBound.guide);
if (diff < GUIDELINE_OFFSET) {
resultH.push({
lineGuide: lineGuide,
diff: diff,
snap: itemBound.snap,
offset: itemBound.offset,
});
}
});
});

var guides = [];

// find closest snap
var minV = resultV.sort((a, b) => a.diff - b.diff)[0];
var minH = resultH.sort((a, b) => a.diff - b.diff)[0];
if (minV) {
guides.push({
lineGuide: minV.lineGuide,
offset: minV.offset,
orientation: 'V',
snap: minV.snap,
});
}
if (minH) {
guides.push({
lineGuide: minH.lineGuide,
offset: minH.offset,
orientation: 'H',
snap: minH.snap,
});
}
return guides;
}

function drawGuides(guides) {
guides.forEach((lg) => {
if (lg.orientation === 'H') {
var line = new Konva.Line({
points: [-6000, 0, 6000, 0],
stroke: 'rgb(0, 161, 255)',
strokeWidth: 1,
name: 'guid-line',
dash: [4, 6],
});
layer.add(line);
line.absolutePosition({
x: 0,
y: lg.lineGuide,
});
} else if (lg.orientation === 'V') {
var line = new Konva.Line({
points: [0, -6000, 0, 6000],
stroke: 'rgb(0, 161, 255)',
strokeWidth: 1,
name: 'guid-line',
dash: [4, 6],
});
layer.add(line);
line.absolutePosition({
x: lg.lineGuide,
y: 0,
});
}
});
}

layer.on('dragmove', function (e) {
// clear all previous lines on the screen
layer.find('.guid-line').forEach((l) => l.destroy());

// find possible snapping lines
var lineGuideStops = getLineGuideStops(e.target);
// find snapping points of current object
var itemBounds = getObjectSnappingEdges(e.target);

// now find where can we snap current object
var guides = getGuides(lineGuideStops, itemBounds);

// do nothing of no snapping
if (!guides.length) {
return;
}

drawGuides(guides);

var absPos = e.target.absolutePosition();
// now force object position
guides.forEach((lg) => {
switch (lg.orientation) {
case 'V': {
absPos.x = lg.lineGuide + lg.offset;
break;
}
case 'H': {
absPos.y = lg.lineGuide + lg.offset;
break;
}
}
});
e.target.absolutePosition(absPos);
});

layer.on('dragend', function (e) {
// clear all previous lines on the screen
layer.find('.guid-line').forEach((l) => l.destroy());
});
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Physics_Simulator.html b/docs/sandbox/Physics_Simulator.html new file mode 100644 index 000000000..ac08505e5 --- /dev/null +++ b/docs/sandbox/Physics_Simulator.html @@ -0,0 +1,678 @@ + + + + + + Physics Simulator with Curve Detection | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Physics Simulator with Curve Detection

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Instructions: Throw the ball around with your cursor.

+ + +
Konva Physics Simulator with Curve Detectionview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Physics Simulator Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

/*
* Vector math functions
*/
function dot(a, b) {
return a.x * b.x + a.y * b.y;
}
function magnitude(a) {
return Math.sqrt(a.x * a.x + a.y * a.y);
}
function normalize(a) {
var mag = magnitude(a);

if (mag === 0) {
return {
x: 0,
y: 0,
};
} else {
return {
x: a.x / mag,
y: a.y / mag,
};
}
}
function add(a, b) {
return {
x: a.x + b.x,
y: a.y + b.y,
};
}
function angleBetween(a, b) {
return Math.acos(dot(a, b) / (magnitude(a) * magnitude(b)));
}
function rotate(a, angle) {
var ca = Math.cos(angle);
var sa = Math.sin(angle);
var rx = a.x * ca - a.y * sa;
var ry = a.x * sa + a.y * ca;
return {
x: rx * -1,
y: ry * -1,
};
}
function invert(a) {
return {
x: a.x * -1,
y: a.y * -1,
};
}
/*
* this cross product function has been simplified by
* setting x and y to zero because vectors a and b
* lie in the canvas plane
*/
function cross(a, b) {
return {
x: 0,
y: 0,
z: a.x * b.y - b.x * a.y,
};
}
function getNormal(curve, ball) {
var curveLayer = curve.getLayer();
var context = curveLayer.getContext();
var testRadius = 20;
// pixels
var totalX = 0;
var totalY = 0;
var x = ball.x();
var y = ball.y();
/*
* check various points around the center point
* to determine the normal vector
*/
for (var n = 0; n < 20; n++) {
var angle = (n * 2 * Math.PI) / 20;
var offsetX = testRadius * Math.cos(angle);
var offsetY = testRadius * Math.sin(angle);
var testX = x + offsetX;
var testY = y + offsetY;
if (!context._context.isPointInPath(testX, testY)) {
totalX += offsetX;
totalY += offsetY;
}
}

var normal;

if (totalX === 0 && totalY === 0) {
normal = {
x: 0,
y: -1,
};
} else {
normal = {
x: totalX,
y: totalY,
};
}

return normalize(normal);
}
function handleCurveCollision(ball, curve) {
var curveLayer = curve.getLayer();
var x = ball.x();
var y = ball.y();

var curveDamper = 0.05;
// 5% energy loss
if (curveLayer.getIntersection({ x: x, y: y })) {
var normal = getNormal(curve, ball);
if (normal !== null) {
var angleToNormal = angleBetween(normal, invert(ball.velocity));
var crossProduct = cross(normal, ball.velocity);
var polarity = crossProduct.z > 0 ? 1 : -1;
var collisonAngle = polarity * angleToNormal * 2;
var collisionVector = rotate(ball.velocity, collisonAngle);

ball.velocity.x = collisionVector.x;
ball.velocity.y = collisionVector.y;
ball.velocity.x *= 1 - curveDamper;
ball.velocity.y *= 1 - curveDamper;

x += normal.x;
if (ball.velocity.y > 0.1) {
y += normal.y;
} else {
y += normal.y / 10;
}
ball.x(x).y(y);
}

tween.finish();
}
}
function updateBall(frame) {
var timeDiff = frame.timeDiff;
var stage = ball.getStage();
var height = stage.height();
var width = stage.width();
var x = ball.x();
var y = ball.y();
var radius = ball.radius();

tween.reverse();

// physics variables
var gravity = 10;
// px / second^2
var speedIncrementFromGravityEachFrame = (gravity * timeDiff) / 1000;
var collisionDamper = 0.2;
// 20% energy loss
var floorFriction = 5;
// px / second^2
var floorFrictionSpeedReduction = (floorFriction * timeDiff) / 1000;

// if ball is being dragged and dropped
if (ball.isDragging()) {
var mousePos = stage.getPointerPosition();

if (mousePos) {
var mouseX = mousePos.x;
var mouseY = mousePos.y;

var c = 0.06 * timeDiff;
ball.velocity = {
x: c * (mouseX - ball.lastMouseX),
y: c * (mouseY - ball.lastMouseY),
};

ball.lastMouseX = mouseX;
ball.lastMouseY = mouseY;
}
} else {
// gravity
ball.velocity.y += speedIncrementFromGravityEachFrame;
x += ball.velocity.x;
y += ball.velocity.y;

// ceiling condition
if (y < radius) {
y = radius;
ball.velocity.y *= -1;
ball.velocity.y *= 1 - collisionDamper;
}

// floor condition
if (y > height - radius) {
y = height - radius;
ball.velocity.y *= -1;
ball.velocity.y *= 1 - collisionDamper;
}

// floor friction
if (y == height - radius) {
if (ball.velocity.x > 0.1) {
ball.velocity.y -= floorFrictionSpeedReduction;
} else if (ball.velocity.x < -0.1) {
ball.velocity.x += floorFrictionSpeedReduction;
} else {
ball.velocity.x = 0;
}
}

// right wall condition
if (x > width - radius) {
x = width - radius;
ball.velocity.x *= -1;
ball.velocity.x *= 1 - collisionDamper;
}

// left wall condition
if (x < radius) {
x = radius;
ball.velocity.x *= -1;
ball.velocity.x *= 1 - collisionDamper;
}

ball.position({ x: x, y: y });

/*
* if the ball comes into contact with the
* curve, then bounce it in the direction of the
* curve's surface normal
*/
collision = handleCurveCollision(ball, curve);
}
}

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var curveLayer = new Konva.Layer();
var ballLayer = new Konva.Layer();
var radius = 20;
var anim;

var curve = new Konva.Shape({
sceneFunc: function (context) {
context.beginPath();
context.moveTo(40, height);
context.bezierCurveTo(
width * 0.2,
-1 * height * 0.5,
width * 0.7,
height * 1.3,
width,
height * 0.5
);
context.lineTo(width, height);
context.lineTo(40, height);
context.closePath();
context.fillShape(this);
},
fill: '#8dbdff',
});

curveLayer.add(curve);

// create ball
var ball = new Konva.Circle({
x: 190,
y: 20,
radius: radius,
fill: 'blue',
draggable: true,
opacity: 0.8,
});

// custom property
ball.velocity = {
x: 0,
y: 0,
};

ball.on('dragstart', function () {
ball.velocity = {
x: 0,
y: 0,
};
anim.start();
});

ball.on('mousedown', function () {
anim.stop();
});

ball.on('mouseover', function () {
document.body.style.cursor = 'pointer';
});

ball.on('mouseout', function () {
document.body.style.cursor = 'default';
});

ballLayer.add(ball);
stage.add(curveLayer);
stage.add(ballLayer);

var tween = new Konva.Tween({
node: ball,
fill: 'red',
duration: 0.3,
easing: Konva.Easings.EaseOut,
});

anim = new Konva.Animation(function (frame) {
updateBall(frame);
}, ballLayer);

anim.start();
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Planets_Image_Map.html b/docs/sandbox/Planets_Image_Map.html new file mode 100644 index 000000000..59683d387 --- /dev/null +++ b/docs/sandbox/Planets_Image_Map.html @@ -0,0 +1,678 @@ + + + + + + Planets Image Map | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Planets Image Map

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Instructions: Mouse over the planets to see their names and use the check box to show and hide the map overlay.

+ + +
Konva Planets Image Mapview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Planets Image Map Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
#controls {
position: absolute;

left: 10px;
top: 10px;
z-index: 99999;
}
label {
color: white;
vertical-align: top;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="controls">
<input type="checkbox" id="checkbox" />
<label> Show map overlay </label>
</div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

function writeMessage(message) {
text.text(message);
}

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var text = new Konva.Text({
x: 10,
y: 10,
fontFamily: 'Calibri',
fontSize: 24,
text: '',
fill: 'white',
});

var planetsLayer = new Konva.Layer();
var circlesLayer = new Konva.Layer();
var messageLayer = new Konva.Layer();

var planets = {
Mercury: {
x: 46,
y: 126,
radius: 32,
},
Venus: {
x: 179,
y: 126,
radius: 79,
},
Earth: {
x: 366,
y: 127,
radius: 85,
},
Mars: {
x: 515,
y: 127,
radius: 45,
},
};

var imageObj = new Image();
imageObj.onload = function () {
// draw shape overlays
for (var pubKey in planets) {
(function () {
var key = pubKey;
var planet = planets[key];

var planetOverlay = new Konva.Circle({
x: planet.x,
y: planet.y,
radius: planet.radius,
});

planetOverlay.on('mouseover', function () {
writeMessage(key);
});
planetOverlay.on('mouseout', function () {
writeMessage('');
});

circlesLayer.add(planetOverlay);
})();
}

var checkbox = document.getElementById('checkbox');
checkbox.addEventListener(
'click',
function () {
var shapes = circlesLayer.getChildren();

// flip show property
for (var n = 0; n < shapes.length; n++) {
var shape = shapes[n];
var f = shape.fill();
shape.fill(f == 'red' ? null : 'red');
}
},
false
);

messageLayer.add(text);
stage.add(planetsLayer);
stage.add(circlesLayer);
stage.add(messageLayer);

// draw planets
var planetsImage = new Konva.Image({
image: imageObj,
});
planetsLayer.add(planetsImage);
};
imageObj.src = '/assets/planets.png';
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Quantum_Squiggle.html b/docs/sandbox/Quantum_Squiggle.html new file mode 100644 index 000000000..8f7989f95 --- /dev/null +++ b/docs/sandbox/Quantum_Squiggle.html @@ -0,0 +1,678 @@ + + + + + + Oscillating Blobs | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Oscillating Blobs

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Instructions: Refresh the page to generate new blobs. You can also drag and drop the blobs as they animate.

+ + +
Konva Quantum Squiggle Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Quantum Squiggle Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var layer = new Konva.Layer();
var colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'];
var blobs = [];

// create 6 blobs
for (var n = 0; n < 6; n++) {
// build array of random points
var points = [];
for (var i = 0; i < 5; i++) {
points.push(stage.width() * Math.random());
points.push(height * Math.random());
}

var blob = new Konva.Line({
points: points,
fill: colors[n],
stroke: 'black',
strokeWidth: 2,
tension: 0,
opacity: Math.random(),
draggable: true,
closed: true,
});

layer.add(blob);
blobs.push(blob);
}

stage.add(layer);

var period = 2000;
var centerTension = 0;
var amplitude = 1;

var anim = new Konva.Animation(function (frame) {
for (var n = 0; n < blobs.length; n++) {
blobs[n].tension(
amplitude * Math.sin((frame.time * 2 * Math.PI) / period) +
centerTension
);
}
}, layer);

anim.start();
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Relative_Pointer_Position.html b/docs/sandbox/Relative_Pointer_Position.html new file mode 100644 index 000000000..ddecdb551 --- /dev/null +++ b/docs/sandbox/Relative_Pointer_Position.html @@ -0,0 +1,680 @@ + + + + + + How to find relative mouse position? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to find relative mouse position?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

In some cases you may need to find position of a point relative to a node. For purpose we can use mathematical Konva.Transform methods.

+

In this demo we have deep nesting transformed nodes: moved stage, scaled layer, rotated group.
Now we want to add circles into the group on click. But how to find position of that circles?
We can’t use stage.getPointerPosition() directly because that is position relative to top-left corner of the stage.

+

The idea is simple. We just need to use inverted absolute transform.

+ + +
Relative Pointer Position Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Relative Pointer Position Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
x: 20,
y: 50,
});

var layer = new Konva.Layer({
scaleX: 1.2,
scaleY: 0.8,
rotation: 5,
});
stage.add(layer);

var group = new Konva.Group({
x: 30,
rotation: 10,
scaleX: 1.5,
});
layer.add(group);

var text = new Konva.Text({
text: 'Click on the canvas to draw a circle',
fontSize: 20,
});
group.add(text);

stage.on('click', function () {
var pos = group.getRelativePointerPosition();
var shape = new Konva.Circle({
x: pos.x,
y: pos.y,
fill: 'red',
radius: 20,
});

group.add(shape);
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Resizing_Stress_Test.html b/docs/sandbox/Resizing_Stress_Test.html new file mode 100644 index 000000000..15213b5df --- /dev/null +++ b/docs/sandbox/Resizing_Stress_Test.html @@ -0,0 +1,682 @@ + + + + + + Resizing Stress Test with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Resizing Stress Test with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

This is a stress test demo to select and resize many shapes at the same time.

+

The demo is using two core Konva features to boost the performance:

+

1. Layers

Resizing shapes are moved into another layer (another canvas element). So while you resize selected shapes, we don’t need to redraw other shapes.

+

2. Caching

On select, I am moving all selected shapes into a group and cache that group. The cache action will convert group into bitmap image. It is mush faster to redraw such group on the screen.

+

Instructions: try to select several shapes and resize/rotate them.

+ + +
Konva Resizing Stress Test Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Resizing stress test Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

// layer for all shapes
var layer = new Konva.Layer();
stage.add(layer);
for (var i = 0; i < 10000; i++) {
var shape = new Konva.Circle({
x: Math.random() * window.innerWidth,
y: Math.random() * window.innerHeight,
radius: 10,
name: 'shape',
fill: Konva.Util.getRandomColor(),
draggable: true,
});
layer.add(shape);
}

// top layer for transforming group
var topLayer = new Konva.Layer();
stage.add(topLayer);

var group = new Konva.Group();
topLayer.add(group);

var tr = new Konva.Transformer();
topLayer.add(tr);

// add a new feature, lets add ability to draw selection rectangle
var selectionRectangle = new Konva.Rect({
fill: 'rgba(0,0,255,0.5)',
});
topLayer.add(selectionRectangle);

var x1, y1, x2, y2;
stage.on('mousedown touchstart', (e) => {
// do nothing if we mousedown on the transformer
if (e.target.getParent() === tr) {
return;
}
x1 = stage.getPointerPosition().x;
y1 = stage.getPointerPosition().y;
x2 = stage.getPointerPosition().x;
y2 = stage.getPointerPosition().y;

selectionRectangle.setAttrs({
x: x1,
y: y1,
width: 0,
height: 0,
visible: true,
});

// move old selection back to original layer
group.children.toArray().forEach((shape) => {
const transform = shape.getAbsoluteTransform();
shape.moveTo(layer);
shape.setAttrs(transform.decompose());
});
// reset group transforms
group.setAttrs({
x: 0,
y: 0,
scaleX: 1,
scaleY: 1,
rotation: 0,
});
group.clearCache();
});

stage.on('mousemove touchmove', () => {
// do nothing if we didn't start selection
if (!selectionRectangle.visible()) {
return;
}
x2 = stage.getPointerPosition().x;
y2 = stage.getPointerPosition().y;

selectionRectangle.setAttrs({
x: Math.min(x1, x2),
y: Math.min(y1, y2),
width: Math.abs(x2 - x1),
height: Math.abs(y2 - y1),
});
});

stage.on('mouseup touchend', () => {
// no nothing if we didn't start selection
if (!selectionRectangle.visible()) {
return;
}
// update visibility in timeout, so we can check it in click event
setTimeout(() => {
selectionRectangle.visible(false);
});

var shapes = stage.find('.shape');
var box = selectionRectangle.getClientRect();

// remove all children for better performance
layer.removeChildren();

// then check intersections and add all shape into correct container
shapes.forEach((shape) => {
var intersected = Konva.Util.haveIntersection(
box,
shape.getClientRect()
);
if (intersected) {
group.add(shape);
shape.stroke('blue');
} else {
layer.add(shape);
shape.stroke(null);
}
});

if (group.children.length) {
tr.nodes([group]);
group.cache();
}
});

// clicks should select/deselect shapes
stage.on('click tap', function (e) {
// if we are selecting with rect, do nothing
if (selectionRectangle.visible()) {
return;
}

// if click on empty area - remove all selections
if (e.target === stage) {
tr.nodes([]);
return;
}
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Responsive_Canvas.html b/docs/sandbox/Responsive_Canvas.html new file mode 100644 index 000000000..b46d23a40 --- /dev/null +++ b/docs/sandbox/Responsive_Canvas.html @@ -0,0 +1,678 @@ + + + + + + Responsive Canvas Stage Demo | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Responsive Canvas Stage Demo

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Do you need responsive/adaptive canvas for you desktop and mobile applications?

So first of all, there are many way to make your canvas stage “responsive”.
And you may need a different behavior for different applications.

+

This demo will show you the simplest solution. We will fit a canvas stage into user window with scaling.
In the demo we will care only about stage WIDTH. You may need to add extra logic if you need to fit height too.

+

Instructions: open demo on new window with this link:

Open Demo!

And try to resize a browser window.

+
Responsive Canvas Stage Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Responsive Canvas Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#stage-parent {
width: 100%;
}
</style>
</head>

<body>
<div id="stage-parent">
<div id="container"></div>
</div>
<script>
// let's think our scene virtual size will be 1000x1000px
// but the real size will be different to fit user's page
var sceneWidth = 1000;
var sceneHeight = 1000;

var stage = new Konva.Stage({
container: 'container',
// first just set set as is
width: sceneWidth,
height: sceneHeight,
});

var layer = new Konva.Layer();
stage.add(layer);

// add circle into center
var circle = new Konva.Circle({
radius: 50,
fill: 'red',
x: stage.width() / 2,
y: stage.height() / 2,
});
layer.add(circle);

// rectangle in bottom right of the stage
var rect = new Konva.Rect({
fill: 'green',
x: stage.width() - 100,
y: stage.height() - 100,
width: 100,
height: 100,
});
layer.add(rect);

function fitStageIntoParentContainer() {
var container = document.querySelector('#stage-parent');

// now we need to fit stage into parent container
var containerWidth = container.offsetWidth;

// but we also make the full scene visible
// so we need to scale all objects on canvas
var scale = containerWidth / sceneWidth;

stage.width(sceneWidth * scale);
stage.height(sceneHeight * scale);
stage.scale({ x: scale, y: scale });
}

fitStageIntoParentContainer();
// adapt the stage on any window resize
window.addEventListener('resize', fitStageIntoParentContainer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Rich_Text.html b/docs/sandbox/Rich_Text.html new file mode 100644 index 000000000..4b81e8c2e --- /dev/null +++ b/docs/sandbox/Rich_Text.html @@ -0,0 +1,686 @@ + + + + + + How to show rich html on canvas with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to show rich html on canvas with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to show complex styles (like bold) and enable rich text editing features?

Canvas’s text API is very limited. Konva.Text allows you to add many different styles, support multiline text, etc. But at the current moment it has limitations. You can’t use different styles for different parts of Konva.Text. For that case you have to use several Konva.Text instances.

+

If you want show complex styles on canvas we can do a hacky workaround. The idea is simple:

+
    +
  1. Create DOM element and put styled text in it
  2. +
  3. Convert DOM element into image with html2canvas.
  4. +
  5. Use that image for Konva.Image.
  6. +
+

Instructions: try to type a text into the editor

+ + +
Konva Rich Text Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<link
rel="stylesheet"
href="https://cdn.quilljs.com/1.3.6/quill.snow.css"
/>

<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<meta charset="utf-8" />
<title>Konva Rich text on Canvas Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#editor-container {
height: 80px;
}
</style>
</head>

<body>
<div id="editor-container">
That is <u>some</u> <span style="color: red"> styled text</span> on
<strong>canvas</strong>!
<h2>What do you think about it?</h2>
</div>
Rendered stage:
<div id="container"></div>
<script>
var quill = new Quill('#editor-container', {
modules: {
toolbar: [
[{ header: [1, 2, false] }],
['bold', 'italic', 'underline'],
['image', 'code-block'],
],
},
placeholder: 'Compose an epic...',
theme: 'snow', // or 'bubble'
});

var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

const layer = new Konva.Layer();
stage.add(layer);

const shape = new Konva.Image({
x: 10,
y: 10,
draggable: true,
stroke: 'red',
scaleX: 1 / window.devicePixelRatio,
scaleY: 1 / window.devicePixelRatio,
});
layer.add(shape);

function renderText() {
// convert DOM into image
html2canvas(document.querySelector('.ql-editor'), {
backgroundColor: 'rgba(0,0,0,0)',
}).then((canvas) => {
// show it inside Konva.Image
shape.image(canvas);
});
}

// batch updates, so we don't render text too frequently
var timeout = null;
function requestTextUpdate() {
if (timeout) {
return;
}
timeout = setTimeout(function () {
timeout = null;
renderText();
}, 500);
}

// render text on all changes
quill.on('text-change', requestTextUpdate);
// make initial rendering
renderText();
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/SVG_On_Canvas.html b/docs/sandbox/SVG_On_Canvas.html new file mode 100644 index 000000000..0c7e6755c --- /dev/null +++ b/docs/sandbox/SVG_On_Canvas.html @@ -0,0 +1,687 @@ + + + + + + How to draw SVG image on canvas with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to draw SVG image on canvas with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to show SVG image on canvas?

It has not always been possible for browsers to draw *.svg images onto the canvas. However, the situation has improved and you currently have several options available if you want to render a vector image with Konva:

+

Option 1: Use Konva.Image

In most of the cases you can use *.svg image the same way as any other image such as *.png or *.jpg. You can use Konva.Image shape.

+
Konva.Image.fromURL('/image.svg', (image) => {
layer.add(image);
});
+ +

This method works well in many cases, but is not fully cross-compatible. For example, some SVG may not be visible in the Firefox browser (there is a workaround for that case).

+

Option 2: Use Konva.Path

Use Konva.Path. This method is good for simple path shapes. If you have a large SVG with many paths you, you may need to split it manually into several Konva.Path shapes.

+

Option 3: Use an external library to render SVG to canvas

Use an external library (for example, canvg) to draw the SVG into the <canvas> element. And then use that canvas for Konva.Image.

+

This method has been tested in at least one large production app, with proven reliability and rendering accuracy.

+

Demo

Below is a demo that shows drawing natively and with a library.

+ + +
Konva GIF demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/canvg/dist/browser/canvg.min.js"></script>
<meta charset="utf-8" />
<title>Konva SVG Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var SOURCE = '/assets/tiger.svg';
// try to draw SVG natively
Konva.Image.fromURL(SOURCE, (imageNode) => {
layer.add(imageNode);
imageNode.setAttrs({
width: 150,
height: 150,
});
});

// draw svg with external library
var canvas = document.createElement('canvas');
canvg(canvas, SOURCE, {
renderCallback: function () {
var image = new Konva.Image({
image: canvas,
x: 200,
width: 150,
height: 150,
});
layer.add(image);
},
});
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Scale_Image_To_Fit.html b/docs/sandbox/Scale_Image_To_Fit.html new file mode 100644 index 000000000..090b497bb --- /dev/null +++ b/docs/sandbox/Scale_Image_To_Fit.html @@ -0,0 +1,681 @@ + + + + + + Scaling image to fit a fixed area on canvas | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Scaling image to fit a fixed area on canvas

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to scale image to fit available area without its stretching?

The demo demonstrate how to use crop property of Konva.Image to emulate object-fit: cover of CSS.

+

The crop property allows you to use only specified area of source image to draw into the canvas. If you do the correct calculations, then resulted image can be drawn without any stretching.

+

Instructions: try to resize an image or change crop strategy.

+ + +
Konva Crop Imageview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Scale to Fit Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
select {
position: absolute;
top: 4px;
left: 4px;
}
</style>
</head>

<body>
<div id="container"></div>
<select id="clip">
<option value="left-top" selected>left-top</option>
<option value="center-top">center-top</option>
<option value="right-top">right-top</option>
<option value="--">--</option>
<option value="left-middle">left-middle</option>
<option value="center-middle">center-middle</option>
<option value="right-middle">right-middle</option>
<option value="--">--</option>
<option value="left-bottom">left-bottom</option>
<option value="center-bottom">center-bottom</option>
<option value="right-bottom">right-bottom</option>
</select>
<script>
const stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

const layer = new Konva.Layer();
stage.add(layer);

// function to calculate crop values from source image, its visible size and a crop strategy
function getCrop(image, size, clipPosition = 'center-middle') {
const width = size.width;
const height = size.height;
const aspectRatio = width / height;

let newWidth;
let newHeight;

const imageRatio = image.width / image.height;

if (aspectRatio >= imageRatio) {
newWidth = image.width;
newHeight = image.width / aspectRatio;
} else {
newWidth = image.height * aspectRatio;
newHeight = image.height;
}

let x = 0;
let y = 0;
if (clipPosition === 'left-top') {
x = 0;
y = 0;
} else if (clipPosition === 'left-middle') {
x = 0;
y = (image.height - newHeight) / 2;
} else if (clipPosition === 'left-bottom') {
x = 0;
y = image.height - newHeight;
} else if (clipPosition === 'center-top') {
x = (image.width - newWidth) / 2;
y = 0;
} else if (clipPosition === 'center-middle') {
x = (image.width - newWidth) / 2;
y = (image.height - newHeight) / 2;
} else if (clipPosition === 'center-bottom') {
x = (image.width - newWidth) / 2;
y = image.height - newHeight;
} else if (clipPosition === 'right-top') {
x = image.width - newWidth;
y = 0;
} else if (clipPosition === 'right-middle') {
x = image.width - newWidth;
y = (image.height - newHeight) / 2;
} else if (clipPosition === 'right-bottom') {
x = image.width - newWidth;
y = image.height - newHeight;
} else if (clipPosition === 'scale') {
x = 0;
y = 0;
newWidth = width;
newHeight = height;
} else {
console.error(
new Error('Unknown clip position property - ' + clipPosition)
);
}

return {
cropX: x,
cropY: y,
cropWidth: newWidth,
cropHeight: newHeight,
};
}

// function to apply crop
function applyCrop(pos) {
const img = layer.findOne('.image');
img.setAttr('lastCropUsed', pos);
const crop = getCrop(
img.image(),
{ width: img.width(), height: img.height() },
pos
);
img.setAttrs(crop);
}

Konva.Image.fromURL(
'https://konvajs.org/assets/darth-vader.jpg',
(img) => {
img.setAttrs({
width: 300,
height: 100,
x: 80,
y: 100,
name: 'image',
draggable: true,
});
layer.add(img);
// apply default left-top crop
applyCrop('center-middle');

const tr = new Konva.Transformer({
nodes: [img],
keepRatio: false,
flipEnabled: false,
boundBoxFunc: (oldBox, newBox) => {
if (Math.abs(newBox.width) < 10 || Math.abs(newBox.height) < 10) {
return oldBox;
}
return newBox;
},
});

layer.add(tr);

img.on('transform', () => {
// reset scale on transform
img.setAttrs({
scaleX: 1,
scaleY: 1,
width: img.width() * img.scaleX(),
height: img.height() * img.scaleY(),
});
applyCrop(img.getAttr('lastCropUsed'));
});
}
);

document.querySelector('#clip').onchange = (e) => {
applyCrop(e.target.value);
};
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Scroll_By_Edge_Drag.html b/docs/sandbox/Scroll_By_Edge_Drag.html new file mode 100644 index 000000000..c86d4117f --- /dev/null +++ b/docs/sandbox/Scroll_By_Edge_Drag.html @@ -0,0 +1,680 @@ + + + + + + How to automatically scroll stage by edge drag? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to automatically scroll stage by edge drag?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

If you’re looking to enhance your Konva.js application’s user experience, implementing an auto-scroll feature is a great way to go. This functionality is especially useful in interactive UIs where users need to drag items or navigate large canvases. By enabling the scroll to automatically move when a user drags an item to the bottom or right edge of the viewport, you create a smoother and more intuitive interaction.

+

Instructions: Start dragging of any shape. Drag it near corder of the stage. Stage will start scrolling.

+ + +
Scroll By Edge Drag Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Canvas Scrolling Drag Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var NUMBER = 100;

function generateNode() {
return new Konva.Circle({
x: width * (Math.random() * 2 - 1),
y: height * (Math.random() * 2 - 1),
radius: 40,
fill: 'red',
stroke: 'black',
draggable: true,
});
}

for (var i = 0; i < NUMBER; i++) {
layer.add(generateNode());
}

let scrollInterval = null;

stage.on('dragstart', (e) => {
const duration = 1000 / 60;
scrollInterval = setInterval(() => {
const pos = stage.getPointerPosition();
const offset = 100;
const isNearLeft = pos.x < offset;
if (isNearLeft) {
stage.x(stage.x() + 2);
e.target.x(e.target.x() - 2);
}
const isNearRight = pos.x > stage.width() - offset;
if (isNearRight) {
stage.x(stage.x() - 2);
e.target.x(e.target.x() + 2);
}
const isNearTop = pos.y < offset;
if (isNearTop) {
stage.y(stage.y() + 2);
e.target.y(e.target.y() - 2);
}
const isNearBottom = pos.y > stage.height() - offset;
if (isNearBottom) {
stage.y(stage.y() - 2);
e.target.y(e.target.y() + 2);
}
}, duration);
});
stage.on('dragend', () => {
clearInterval(scrollInterval);
});
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Seats_Reservation.html b/docs/sandbox/Seats_Reservation.html new file mode 100644 index 000000000..719b3798a --- /dev/null +++ b/docs/sandbox/Seats_Reservation.html @@ -0,0 +1,679 @@ + + + + + + Seats bookings widget for the website with canvas | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Seats bookings widget for the website with canvas

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

This is a prototype version of seats reservation system I made for one of my clients.

+

Please read Full Blog Post about the process of making the widget.

+

The widget is made with React, Konva and react-konva libraries.

+

It is not required to use React for such widgets. But it was used here because the main application (where the widget was used) is made with React.

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Shape_Tango.html b/docs/sandbox/Shape_Tango.html new file mode 100644 index 000000000..4224f6a3b --- /dev/null +++ b/docs/sandbox/Shape_Tango.html @@ -0,0 +1,678 @@ + + + + + + HTML5 Canvas Shape Tango with Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Shape Tango with Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

HTML5 Canvas Shape Tango with Konva

Instructions: drag and drop the shapes and press the “Tango” button to make the shapes move. refresh the page to generate new random shapes.

+ + +
Konva Shape Tangoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Shape Tango Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
#tango {
position: absolute;
top: 10px;
left: 10px;
padding: 10px;
}
</style>
</head>
<body>
<div id="container"></div>
<input type="button" id="tango" value="Tango!" />
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'];

function getRandomColor() {
return colors[Math.round(Math.random() * 5)];
}

function tango(layer) {
for (var n = 0; n < layer.getChildren().length; n++) {
var color = getRandomColor();
var shape = layer.getChildren()[n];
var stage = shape.getStage();
var radius = Math.random() * 100 + 20;

new Konva.Tween({
node: shape,
duration: 1,
x: Math.random() * stage.width(),
y: Math.random() * stage.height(),
rotation: Math.random() * 360,
radius: radius,
opacity: (radius - 20) / 100,
easing: Konva.Easings.EaseInOut,
fill: color,
}).play();
}
}
var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

for (var n = 0; n < 10; n++) {
var radius = Math.random() * 100 + 20;
var color = getRandomColor();
var shape = new Konva.RegularPolygon({
x: Math.random() * stage.width(),
y: Math.random() * stage.height(),
sides: Math.ceil(Math.random() * 5 + 3),
radius: radius,
fill: color,
opacity: (radius - 20) / 100,
draggable: true,
});

layer.add(shape);
}

stage.add(layer);

document.getElementById('tango').addEventListener(
'click',
function () {
tango(layer);
},
false
);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Shape_Tooltips.html b/docs/sandbox/Shape_Tooltips.html new file mode 100644 index 000000000..f139bfe72 --- /dev/null +++ b/docs/sandbox/Shape_Tooltips.html @@ -0,0 +1,678 @@ + + + + + + Shape Tooltips | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Shape Tooltips

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

HTML5 Canvas Shape Tooltips with Konva

Instructions: Mousemove over shape to see the tooltip.

+ + +
Konva Shape Tooltipsview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Shape Tooltips Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var shapesLayer = new Konva.Layer();
var tooltipLayer = new Konva.Layer();

var triangle = new Konva.Shape({
stroke: 'black',
fill: '#00D2FF',
strokeWidth: 1,
sceneFunc: function (context) {
context.beginPath();
context.moveTo(120, 50);
context.lineTo(250, 80);
context.lineTo(150, 170);
context.closePath();
context.fillStrokeShape(this);
},
});

triangle.on('mousemove', function () {
var mousePos = stage.getPointerPosition();
tooltip.position({
x: mousePos.x + 5,
y: mousePos.y + 5,
});
tooltip.text('Cyan Triangle');
tooltip.show();
});

triangle.on('mouseout', function () {
tooltip.hide();
});

shapesLayer.add(triangle);

var circle = new Konva.Circle({
x: 250,
y: stage.height() / 2,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
radius: 70,
});

circle.on('mousemove', function () {
var mousePos = stage.getPointerPosition();
tooltip.position({
x: mousePos.x + 5,
y: mousePos.y + 5,
});
tooltip.text('Red Circle');
tooltip.show();
});

circle.on('mouseout', function () {
tooltip.hide();
});

shapesLayer.add(circle);

var tooltip = new Konva.Text({
text: '',
fontFamily: 'Calibri',
fontSize: 12,
padding: 5,
textFill: 'white',
fill: 'black',
alpha: 0.75,
visible: false,
});

tooltipLayer.add(tooltip);

stage.add(shapesLayer);
stage.add(tooltipLayer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Simple_Window_Frame.html b/docs/sandbox/Simple_Window_Frame.html new file mode 100644 index 000000000..56612aca9 --- /dev/null +++ b/docs/sandbox/Simple_Window_Frame.html @@ -0,0 +1,679 @@ + + + + + + HTML5 Canvas Simple Window Designer | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Simple Window Designer

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

HTML5 Canvas Simple Window Designer

That is a very simple demo that draw window frame.

+

Instructions: You can change its width and height

+ + +
Konva Simple Window Designerview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Simple Window drawing</title>
<style>
body {
padding: 0;
margin: 0;
overflow: hidden;
}

#container {
border: 1px solid grey;
background-color: lightgrey;
}

#controls {
position: absolute;
top: 4px;
left: 4px;
}
</style>
</head>

<body>
<div id="container"></div>

<div id="controls">
<div style="float: left; padding: 10px">
Width:
<input type="number" id="widthInput" />
</div>
<div style="float: left; padding: 10px">
Height:
<input type="number" id="heightInput" />
</div>
</div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var widthInput = document.getElementById('widthInput');
var heightInput = document.getElementById('heightInput');

function createFrame(frameWidth, frameHeight) {
var padding = 70;
var group = new Konva.Group();
var top = new Konva.Line({
points: [
0,
0,
frameWidth,
0,
frameWidth - padding,
padding,
padding,
padding,
],
fill: 'white',
});

var left = new Konva.Line({
points: [
0,
0,
padding,
padding,
padding,
frameHeight - padding,
0,
frameHeight,
],
fill: 'white',
});

var bottom = new Konva.Line({
points: [
0,
frameHeight,
padding,
frameHeight - padding,
frameWidth - padding,
frameHeight - padding,
frameWidth,
frameHeight,
],
fill: 'white',
});

var right = new Konva.Line({
points: [
frameWidth,
0,
frameWidth,
frameHeight,
frameWidth - padding,
frameHeight - padding,
frameWidth - padding,
padding,
],
fill: 'white',
});

var glass = new Konva.Rect({
x: padding,
y: padding,
width: frameWidth - padding * 2,
height: frameHeight - padding * 2,
fill: 'lightblue',
});

group.add(glass, top, left, bottom, right);

group.find('Line').forEach((line) => {
line.closed(true);
line.stroke('black');
line.strokeWidth(1);
});

return group;
}

function createInfo(frameWidth, frameHeight) {
var offset = 20;

var arrowOffset = offset / 2;
var arrowSize = 5;

var group = new Konva.Group();
var lines = new Konva.Shape({
sceneFunc: function (ctx) {
ctx.fillStyle = 'grey';
ctx.lineWidth = 0.5;

ctx.moveTo(0, 0);
ctx.lineTo(-offset, 0);

ctx.moveTo(0, frameHeight);
ctx.lineTo(-offset, frameHeight);

ctx.moveTo(0, frameHeight);
ctx.lineTo(0, frameHeight + offset);

ctx.moveTo(frameWidth, frameHeight);
ctx.lineTo(frameWidth, frameHeight + offset);

ctx.stroke();
},
});

var leftArrow = new Konva.Shape({
sceneFunc: function (ctx) {
// top pointer
ctx.moveTo(-arrowOffset - arrowSize, arrowSize);
ctx.lineTo(-arrowOffset, 0);
ctx.lineTo(-arrowOffset + arrowSize, arrowSize);

// line
ctx.moveTo(-arrowOffset, 0);
ctx.lineTo(-arrowOffset, frameHeight);

// bottom pointer
ctx.moveTo(-arrowOffset - arrowSize, frameHeight - arrowSize);
ctx.lineTo(-arrowOffset, frameHeight);
ctx.lineTo(-arrowOffset + arrowSize, frameHeight - arrowSize);

ctx.strokeShape(this);
},
stroke: 'grey',
strokeWidth: 0.5,
});

var bottomArrow = new Konva.Shape({
sceneFunc: function (ctx) {
// top pointer
ctx.translate(0, frameHeight + arrowOffset);
ctx.moveTo(arrowSize, -arrowSize);
ctx.lineTo(0, 0);
ctx.lineTo(arrowSize, arrowSize);

// line
ctx.moveTo(0, 0);
ctx.lineTo(frameWidth, 0);

// bottom pointer
ctx.moveTo(frameWidth - arrowSize, -arrowSize);
ctx.lineTo(frameWidth, 0);
ctx.lineTo(frameWidth - arrowSize, arrowSize);

ctx.strokeShape(this);
},
stroke: 'grey',
strokeWidth: 0.5,
});

// left text
var leftLabel = new Konva.Label();

leftLabel.add(
new Konva.Tag({
fill: 'white',
stroke: 'grey',
})
);
var leftText = new Konva.Text({
text: heightInput.value + 'mm',
padding: 2,
fill: 'black',
});

leftLabel.add(leftText);
leftLabel.position({
x: -arrowOffset - leftText.width(),
y: frameHeight / 2 - leftText.height() / 2,
});

leftLabel.on('click tap', function () {
createInput('height', this.getAbsolutePosition(), leftText.size());
});

// bottom text
var bottomLabel = new Konva.Label();

bottomLabel.add(
new Konva.Tag({
fill: 'white',
stroke: 'grey',
})
);
var bottomText = new Konva.Text({
text: widthInput.value + 'mm',
padding: 2,
fill: 'black',
});

bottomLabel.add(bottomText);
bottomLabel.position({
x: frameWidth / 2 - bottomText.width() / 2,
y: frameHeight + arrowOffset,
});

bottomLabel.on('click tap', function () {
createInput('width', this.getAbsolutePosition(), bottomText.size());
});

group.add(lines, leftArrow, bottomArrow, leftLabel, bottomLabel);

return group;
}

function createInput(metric, pos, size) {
var wrap = document.createElement('div');
wrap.style.position = 'absolute';
wrap.style.backgroundColor = 'rgba(0,0,0,0.1)';
wrap.style.top = 0;
wrap.style.left = 0;
wrap.style.width = '100%';
wrap.style.height = '100%';

document.body.appendChild(wrap);

var input = document.createElement('input');
input.type = 'number';

var similarInput = metric === 'width' ? widthInput : heightInput;
input.value = similarInput.value;

input.style.position = 'absolute';
input.style.top = pos.y + 3 + 'px';
input.style.left = pos.x + 'px';

input.style.height = size.height + 3 + 'px';
input.style.width = size.width + 3 + 'px';

wrap.appendChild(input);

input.addEventListener('change', function () {
similarInput.value = input.value;
updateCanvas();
});

input.addEventListener('input', function () {
similarInput.value = input.value;
updateCanvas();
});

wrap.addEventListener('click', function (e) {
if (e.target === wrap) {
document.body.removeChild(wrap);
}
});

input.addEventListener('keyup', function (e) {
if (e.keyCode === 13) {
document.body.removeChild(wrap);
}
});
}

function updateCanvas() {
layer.children.forEach((child) => child.destroy());

var frameWidth = parseInt(widthInput.value, 10);
var frameHeight = parseInt(heightInput.value, 10);

var wr = stage.width() / frameWidth;
var hr = stage.height() / frameHeight;

var ratio = Math.min(wr, hr) * 0.8;

var frameOnScreenWidth = frameWidth * ratio;
var frameOnScreenHeight = frameHeight * ratio;

var group = new Konva.Group({});

group.x(Math.round(stage.width() / 2 - frameOnScreenWidth / 2) + 0.5);
group.y(Math.round(stage.height() / 2 - frameOnScreenHeight / 2) + 0.5);

layer.add(group);

var frameGroup = createFrame(frameWidth, frameHeight);
frameGroup.scale({ x: ratio, y: ratio });
group.add(frameGroup);

var infoGroup = createInfo(frameOnScreenWidth, frameOnScreenHeight);
group.add(infoGroup);
}

widthInput.addEventListener('change', updateCanvas);
widthInput.addEventListener('input', updateCanvas);

heightInput.addEventListener('change', updateCanvas);
heightInput.addEventListener('input', updateCanvas);

// set default value
widthInput.value = 1000;
heightInput.value = 2000;

updateCanvas();
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Stage_Preview.html b/docs/sandbox/Stage_Preview.html new file mode 100644 index 000000000..f9c7419e8 --- /dev/null +++ b/docs/sandbox/Stage_Preview.html @@ -0,0 +1,689 @@ + + + + + + How to preview large stage on canvas with Konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to preview large stage on canvas with Konva?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Need to generate a small preview of the canvas?

There are many ways to generate small preview. Konva doesn’t provide any methods to do this automatically.
But we can use Konva methods to generate preview area manually.

+

We will show two options - cloning and using images. In large applications it is better to generate preview from the state of the app.

+

Clone nodes from the main stage.

So we can just clone the stage or the layer and update its internal nodes from the state of the main canvas area.

+

Also it will make sense to simplify shapes on the preview. Like hide texts, remove strokes and shadows, etc.

+

Instructions: try to drag a circle. See how the preview is updating. Double click to add a new shape.

+ + +
Stage_Preview_Clone.htmlview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Canvas Stage Preview Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#preview {
position: absolute;
top: 2px;
right: 2px;
border: 1px solid grey;
background-color: lightgrey;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="preview"></div>
<script>
const stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

const layer = new Konva.Layer();
stage.add(layer);

// generate random shapes
for (var i = 0; i < 10; i++) {
const shape = new Konva.Circle({
x: Math.random() * stage.width(),
y: Math.random() * stage.height(),
radius: Math.random() * 30 + 5,
fill: Konva.Util.getRandomColor(),
draggable: true,
// each shape MUSH have uniq name
// so we can easily update the preview clone by name
name: 'shape-' + i,
});
layer.add(shape);
}

// create smaller preview stage
const previewStage = new Konva.Stage({
container: 'preview',
width: window.innerWidth / 4,
height: window.innerHeight / 4,
scaleX: 1 / 4,
scaleY: 1 / 4,
});

// clone original layer, and disable all events on it
// we will use "let" here, because we can redefine layer later
let previewLayer = layer.clone({ listening: false });
previewStage.add(previewLayer);

function updatePreview() {
// we just need to update ALL nodes in the preview
layer.children.forEach((shape) => {
// find cloned node
const clone = previewLayer.findOne('.' + shape.name());
// update its position from the original
clone.position(shape.position());
});
}

stage.on('dragmove', updatePreview);

// add new shapes on double click or double tap
stage.on('dblclick dbltap', () => {
const shape = new Konva.Circle({
x: stage.getPointerPosition().x,
y: stage.getPointerPosition().y,
radius: Math.random() * 30 + 5,
fill: Konva.Util.getRandomColor(),
draggable: true,
// each shape MUSH have uniq name
// so we can easily update the preview clone by name
name: 'shape-' + layer.children.length,
});
layer.add(shape);

// remove all layer
previewLayer.destroy();
// generate new one
previewLayer = layer.clone({ listening: false });
previewStage.add(previewLayer);
});
</script>
</body>
</html>
+ + +

Use image preview

Or we can export the stage to an image and use it as a preview.

+

For performance reasons we are not updating the preview on every dragmove events.

+ + +
Stage_Preview_Image.htmlview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Canvas Stage Preview Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#preview {
position: absolute;
top: 2px;
right: 2px;
border: 1px solid grey;
background-color: lightgrey;
}
</style>
</head>

<body>
<div id="container"></div>
<img id="preview" />
<script>
const stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

const layer = new Konva.Layer();
stage.add(layer);

// generate random shapes
for (var i = 0; i < 10; i++) {
const shape = new Konva.Circle({
x: Math.random() * stage.width(),
y: Math.random() * stage.height(),
radius: Math.random() * 30 + 5,
fill: Konva.Util.getRandomColor(),
draggable: true,
// each shape MUSH have uniq name
// so we can easily update the preview clone by name
name: 'shape-' + i,
});
layer.add(shape);
}

function updatePreview() {
const scale = 1 / 4;
// use pixelRatio to generate smaller preview
const url = stage.toDataURL({ pixelRatio: scale });
document.getElementById('preview').src = url;
}

// update preview only on dragend for performance
stage.on('dragend', updatePreview);

// add new shapes on double click or double tap
stage.on('dblclick dbltap', () => {
const shape = new Konva.Circle({
x: stage.getPointerPosition().x,
y: stage.getPointerPosition().y,
radius: Math.random() * 30 + 5,
fill: Konva.Util.getRandomColor(),
draggable: true,
// each shape MUSH have uniq name
// so we can easily update the preview clone by name
name: 'shape-' + layer.children.length,
});
layer.add(shape);

updatePreview();
});

// show initial preview
updatePreview();
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Star_Spinner.html b/docs/sandbox/Star_Spinner.html new file mode 100644 index 000000000..e23ad2ac0 --- /dev/null +++ b/docs/sandbox/Star_Spinner.html @@ -0,0 +1,678 @@ + + + + + + Star Spinner | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Star Spinner

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Instructions: Spin the star with your mouse.

+ + +
Konva Star Spinnerview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Star Spinner Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

Konva.angleDeg = false;
function animate(animatedLayer, star, frame) {
// 20% slow down per second
var angularFriction = 0.2;
var angularVelocityChange =
(star.angularVelocity * frame.timeDiff * (1 - angularFriction)) /
1000;
star.angularVelocity -= angularVelocityChange;

if (star.controlled) {
star.angularVelocity =
((star.rotation() - star.lastRotation) * 1000) / frame.timeDiff;
} else {
star.rotate((frame.timeDiff * star.angularVelocity) / 1000);
}

star.lastRotation = star.rotation();
}

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var animatedLayer = new Konva.Layer();

var star = new Konva.Star({
x: stage.width() / 2,
y: stage.height() / 2,
outerRadius: 80,
innerRadius: 40,
stroke: '#005500',
fill: '#b5ff88',
strokeWidth: 4,
numPoints: 5,
lineJoin: 'round',
shadowOffsetX: 5,
shadowOffsetY: 5,
shadowBlur: 10,
shadowColor: 'black',
shadowOpacity: 0.5,
opacity: 0.8,
});

// custom properties
star.lastRotation = 0;
star.angularVelocity = 6;
star.controlled = false;

star.on('mousedown touchstart', function (evt) {
this.angularVelocity = 0;
this.controlled = true;
});

animatedLayer.add(star);

var center = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2,
radius: 3,
fill: '#555',
});

animatedLayer.add(center);

// add listeners to container
stage.on('mouseup touchend', function () {
star.controlled = false;
});

stage.on('mousemove touchmove', function () {
if (star.controlled) {
var mousePos = stage.getPointerPosition();
var x = star.x() - mousePos.x;
var y = star.y() - mousePos.y;
star.rotation(0.5 * Math.PI + Math.atan(y / x));

if (mousePos.x <= stage.width() / 2) {
star.rotate(Math.PI);
}
}
});

stage.add(animatedLayer);

var anim = new Konva.Animation(function (frame) {
animate(animatedLayer, star, frame);
}, animatedLayer);

// wait one second and then spin the star
setTimeout(function () {
anim.start();
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Transparent_Group.html b/docs/sandbox/Transparent_Group.html new file mode 100644 index 000000000..b8bdf8082 --- /dev/null +++ b/docs/sandbox/Transparent_Group.html @@ -0,0 +1,684 @@ + + + + + + How to apply transparency for several shapes at once? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to apply transparency for several shapes at once?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Is it possible to use opacity for several shapes in the same time?

You can use opacity attribute to change alpha channel of any Konva node. In the way the canvas works, all shapes have its own independent opacity values.

+

That mean if you have a group with several shapes inside and that group have group.opacity(0.5). It will look exactly the same as if each shape inside the group has shape.opacity(0.5) and the group have group.opacity(1). That means you will see overlapping areas of that shapes.

+

What if we don’t want to see overlapping areas of transparent shapes?

There is a way to fix such default behavior. You just need to cache the group with group.cache(). Caching the group will convert it into bitmap and draw into external canvas. On the next draw call, Konva will use that resulted canvas to draw whole group with opacity applied to whole image.

+

So while Konva is making a bitmap cache for such group it will draw internal shapes ignoring transparency of the group.

+

Remember that if a group is cached, it has some limitations of cached nodes. Like if you are doing any internal changes (like changing shapes attributes) you have to recache the group. And that is expensive operation, so it is not recommended to do it frequently like inside animations or on every mousemove.

+

Instructions: on the left you see default behavior, on the right you see fixed behavior with cached group.

+ + +
Konva transparent groupview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Transparency for several Shapes Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background: #f0f0f0;
background: linear-gradient(
115deg,
transparent 75%,
rgba(255, 255, 255, 0.8) 75%
)
0 0,
linear-gradient(245deg, transparent 75%, rgba(255, 255, 255, 0.8) 75%)
0 0,
linear-gradient(115deg, transparent 75%, rgba(255, 255, 255, 0.8) 75%)
7px -15px,
linear-gradient(245deg, transparent 75%, rgba(255, 255, 255, 0.8) 75%)
7px -15px,
#f0f0f0;
background-size: 15px 30px;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

// lets create default group with two overlapping shapes
var group1 = new Konva.Group({
opacity: 0.5,
x: 50,
y: 50,
draggable: true,
});
group1.add(
new Konva.Rect({
width: 100,
height: 100,
fill: 'red',
})
);
group1.add(
new Konva.Circle({
x: 100,
y: 100,
radius: 70,
fill: 'greed',
})
);
layer.add(group1);

// lets create the second group
var group2 = group1.clone({ x: 250 });
layer.add(group2);

// to change opacity behavior we have to fix whole group
group2.cache();
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Video_On_Canvas.html b/docs/sandbox/Video_On_Canvas.html new file mode 100644 index 000000000..5f74637d2 --- /dev/null +++ b/docs/sandbox/Video_On_Canvas.html @@ -0,0 +1,683 @@ + + + + + + How to display video on Canvas | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to display video on Canvas

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

To draw a video on a canvas we can use <video> DOM element similar to <img> element, but we have to frequently redraw the layer. For the purpose we can use Konva.Animation. As alternative you can use requestAnimationFrame and just call layer.draw().

+
+

Also take a look into this post for additional information: https://lavrton.com/case-study-video-editor-for-stream/

+
+

Instructions: click “play” button. You can drag&drop the image.

+ + +
Konva Video Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva GIF Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<button id="play">Play</button><button id="pause">Pause</button>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var video = document.createElement('video');
video.src =
'https://upload.wikimedia.org/wikipedia/commons/transcoded/c/c4/Physicsworks.ogv/Physicsworks.ogv.240p.vp9.webm';

var image = new Konva.Image({
image: video,
draggable: true,
x: 50,
y: 20,
});
layer.add(image);

var text = new Konva.Text({
text: 'Loading video...',
width: stage.width(),
height: stage.height(),
align: 'center',
verticalAlign: 'middle',
});
layer.add(text);

var anim = new Konva.Animation(function () {
// do nothing, animation just need to update the layer
}, layer);

// update Konva.Image size when meta is loaded
video.addEventListener('loadedmetadata', function (e) {
text.text('Press PLAY...');
image.width(video.videoWidth);
image.height(video.videoHeight);
});

document.getElementById('play').addEventListener('click', function () {
text.destroy();
video.play();
anim.start();
});
document.getElementById('pause').addEventListener('click', function () {
video.pause();
anim.stop();
});
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Web_Worker.html b/docs/sandbox/Web_Worker.html new file mode 100644 index 000000000..fe7092d07 --- /dev/null +++ b/docs/sandbox/Web_Worker.html @@ -0,0 +1,689 @@ + + + + + + Offscreen canvas inside Web Worker | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Offscreen canvas inside Web Worker

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to run Konva in a Web Worker?

Warning! This demo is VERY EXPERIMENTAL! It may not work in many browsers. Check Offscreen canvas capability tabletv.

+

With some extra work we can render Konva stage inside a Web Worker using Offscreen Canvas for performance reasons or for some crazy ideas.

+

You can use a webworker to make some visualizations with Konva.

+

But one of the main features of Konva is its interactivity (full events support for canvas shapes). And there are no DOM events inside a web worker. So we have to write some kind of “proxy” to pass all DOM events inside Konva engine. That way we can have interactive objects inside web worker too.

+

This demo is adopted from Jumping bunnies performance stress test.

+

You may need to write more code to cover more functions and different edge cases (such as HDPI screen support).

+

Instructions: there are two interactive objects on the stage. “Add buttons” and a draggable red circle. Try to add more bunnies or drag the circle.

+

All you see on that screen is rendered inside another javascript thread!. So it should not block main JS thread of the current page.

+ + +
Web_Worker.htmlview raw
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Konva Offscreen Canvas Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<canvas id="canvas"></canvas>
<script>
var htmlCanvas = document.getElementById('canvas');
htmlCanvas.width = window.innerWidth;
htmlCanvas.height = window.innerHeight;

var hasOffscreenSupport = !!htmlCanvas.transferControlToOffscreen;
if (hasOffscreenSupport) {
var offscreen = htmlCanvas.transferControlToOffscreen();

var w = new Worker('./Web_Worker.js');
// pass canvas into webworker, so we can do all rendering inside it
w.postMessage({ canvas: offscreen }, [offscreen]);

// "proxy" all DOM events from canvas into Konva engine
var EVENTS = [
'mouseenter',
'mousedown',
'mousemove',
'mouseup',
'mouseout',
'wheel',
'contextmenu',
'pointerdown',
'pointermove',
'pointerup',
'pointercancel',
'lostpointercapture',
];
EVENTS.forEach((eventName) => {
htmlCanvas.addEventListener(eventName, (e) => {
w.postMessage({
eventName,
event: {
clientX: e.clientX,
clientY: e.clientY,
type: e.type,
},
});
});
});
} else {
htmlCanvas
.getContext('2d')
.fillText(
'🛑 Sorry, your browser does not support Offscreen rendering...',
20,
20
);
}
</script>
</body>
</html>
+ +

And the code of the worker:

+
Worker Codeview raw
// load konva framework
importScripts('https://unpkg.com/konva@9/konva.min.js');

// monkeypatch Konva for offscreen canvas usage
Konva.Util.createCanvasElement = () => {
const canvas = new OffscreenCanvas(1, 1);
canvas.style = {};
return canvas;
};

// now we can create our canvas content
var stage = new Konva.Stage({
width: 200,
height: 200,
});

var layer = new Konva.Layer();
stage.add(layer);

var topGroup = new Konva.Group();
layer.add(topGroup);

// counter will show number of bunnies
var counter = new Konva.Text({
x: 5,
y: 35,
});
topGroup.add(counter);

// "add more bunnies" button
var button = new Konva.Label({
x: 5,
y: 5,
opacity: 0.75,
});
topGroup.add(button);

button.add(
new Konva.Tag({
fill: 'black',
})
);

button.add(
new Konva.Text({
text: 'Push me to add bunnies',
fontFamily: 'Calibri',
fontSize: 18,
padding: 5,
fill: 'white',
})
);

// draggable circle to show interactivity
var circle = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2,
radius: 20,
fill: 'red',
draggable: true,
});
topGroup.add(circle);

self.onmessage = function (evt) {
// when canvas is passes we can start our worker
// we can try to use that canvas for the layer with some manual replacement (and probably better performance)
// but for simplicity we will just copy layer content into passed canvas
if (evt.data.canvas) {
var canvas = evt.data.canvas;
// adapt stage size
// we may need to add extra event to resize stage on a fly
stage.setSize({
width: canvas.width,
height: canvas.height,
});

const ctx = canvas.getContext('2d');

// Konva.Layer has support for "draw" event
// so every time the layer is re-rendered we need to update the canvas
layer.on('draw', () => {
// clear content
ctx.clearRect(0, 0, canvas.width, canvas.height);
// draw layer content
ctx.drawImage(layer.getCanvas()._canvas, 0, 0);
});
}
// emulate some drag&drop events
if (evt.data.eventName === 'mouseup') {
Konva.DD._endDragBefore(evt.data.event);
}
if (evt.data.eventName === 'touchend') {
Konva.DD._endDragBefore(evt.data.event);
}
if (evt.data.eventName === 'mousemove') {
Konva.DD._drag(evt.data.event);
}
if (evt.data.eventName === 'touchmove') {
Konva.DD._drag(evt.data.event);
}
if (evt.data.eventName === 'mouseup') {
Konva.DD._endDragAfter(evt.data.event);
}
if (evt.data.eventName === 'touchend') {
Konva.DD._endDragAfter(evt.data.event);
}

// pass incoming events into the stage
if (evt.data.eventName) {
const event = evt.data.eventName.replace('mouse', 'pointer');
stage['_' + event](evt.data.event);
}
};

function requestAnimationFrame(cb) {
setTimeout(cb, 16);
}

// that function is large and adapted from bunnies demo
// the only interesting part here is how to load images to use for Konva.Image
async function runBunnies() {
const imgBlob = await fetch('https://konvajs.org/assets/bunny.png').then(
(r) => r.blob()
);
// use "createImageBitmap" instead of "new window.Image()"
const img = await createImageBitmap(imgBlob);

var bunnys = [];
var gravity = 0.75;

var startBunnyCount = 100;
var isAdding = false;
var count = 0;
var amount = 10;

button.on('mousedown', function () {
isAdding = true;
});

button.on('mouseup', function () {
isAdding = false;
});

for (var i = 0; i < startBunnyCount; i++) {
var bunny = new Konva.Image({
image: img,
transformsEnabled: 'position',
x: 10,
y: 10,
listening: false,
});

bunny.speedX = Math.random() * 10;
bunny.speedY = Math.random() * 10 - 5;

bunnys.push(bunny);
counter.text('Bunnies number: ' + bunnys.length);
layer.add(bunny);
}
topGroup.moveToTop();

function update() {
var maxX = stage.width() - 10;
var minX = 0;
var maxY = stage.height() - 10;
var minY = 0;
if (isAdding) {
for (var i = 0; i < amount; i++) {
var bunny = new Konva.Image({
image: img,
transformsEnabled: 'position',
x: 0,
y: 0,
listening: false,
});
bunny.speedX = Math.random() * 10;
bunny.speedY = Math.random() * 10 - 5;
bunnys.push(bunny);
layer.add(bunny);
counter.text('Bunnies number: ' + bunnys.length);
count++;
}
topGroup.moveToTop();
}

for (var i = 0; i < bunnys.length; i++) {
var bunny = bunnys[i];
bunny.setX(bunny.getX() + bunny.speedX);
bunny.setY(bunny.getY() + bunny.speedY);
bunny.speedY += gravity;
if (bunny.getX() > maxX - img.width) {
bunny.speedX *= -1;
bunny.setX(maxX - img.width);
} else if (bunny.getX() < minX) {
bunny.speedX *= -1;
bunny.setX(minX);
}

if (bunny.getY() > maxY - img.height) {
bunny.speedY *= -0.85;
bunny.setY(maxY - img.height);
if (Math.random() > 0.5) {
bunny.speedY -= Math.random() * 6;
}
} else if (bunny.getY() < minY) {
bunny.speedY = 0;
bunny.setY(minY);
}
}
layer.drawScene();
requestAnimationFrame(update);
}
update();
}

runBunnies();
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Wheel_of_Fortune.html b/docs/sandbox/Wheel_of_Fortune.html new file mode 100644 index 000000000..925732b90 --- /dev/null +++ b/docs/sandbox/Wheel_of_Fortune.html @@ -0,0 +1,678 @@ + + + + + + Wheel of Fortune HTML5 Canvas Game | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Wheel of Fortune HTML5 Canvas Game

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Instructions: Spin the wheel and make a fortune!

+ + +
Konva Wheel of Fortuneview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Wheel of Fortune Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

Konva.angleDeg = false;
var angularVelocity = 6;
var angularVelocities = [];
var lastRotation = 0;
var controlled = false;
var numWedges = 25;
var angularFriction = 0.2;
var target, activeWedge, stage, layer, wheel, pointer;
var finished = false;

function getAverageAngularVelocity() {
var total = 0;
var len = angularVelocities.length;

if (len === 0) {
return 0;
}

for (var n = 0; n < len; n++) {
total += angularVelocities[n];
}

return total / len;
}
function purifyColor(color) {
var randIndex = Math.round(Math.random() * 3);
color[randIndex] = 0;
return color;
}
function getRandomColor() {
var r = 100 + Math.round(Math.random() * 55);
var g = 100 + Math.round(Math.random() * 55);
var b = 100 + Math.round(Math.random() * 55);
return purifyColor([r, g, b]);
}

function getRandomReward() {
var mainDigit = Math.round(Math.random() * 9);
return mainDigit + '\n0\n0';
}
function addWedge(n) {
var s = getRandomColor();
var reward = getRandomReward();
var r = s[0];
var g = s[1];
var b = s[2];
var angle = (2 * Math.PI) / numWedges;

var endColor = 'rgb(' + r + ',' + g + ',' + b + ')';
r += 100;
g += 100;
b += 100;

var startColor = 'rgb(' + r + ',' + g + ',' + b + ')';

var wedge = new Konva.Group({
rotation: (2 * n * Math.PI) / numWedges,
});

var wedgeBackground = new Konva.Wedge({
radius: 400,
angle: angle,
fillRadialGradientStartPoint: 0,
fillRadialGradientStartRadius: 0,
fillRadialGradientEndPoint: 0,
fillRadialGradientEndRadius: 400,
fillRadialGradientColorStops: [0, startColor, 1, endColor],
fill: '#64e9f8',
fillPriority: 'radial-gradient',
stroke: '#ccc',
strokeWidth: 2,
});

wedge.add(wedgeBackground);

var text = new Konva.Text({
text: reward,
fontFamily: 'Calibri',
fontSize: 50,
fill: 'white',
align: 'center',
stroke: 'yellow',
strokeWidth: 1,
rotation: (Math.PI + angle) / 2,
x: 380,
y: 30,
listening: false,
});

wedge.add(text);
text.cache();

wedge.startRotation = wedge.rotation();

wheel.add(wedge);
}
function animate(frame) {
// handle wheel spin
var angularVelocityChange =
(angularVelocity * frame.timeDiff * (1 - angularFriction)) / 1000;
angularVelocity -= angularVelocityChange;

// activate / deactivate wedges based on point intersection
var shape = stage.getIntersection({
x: stage.width() / 2,
y: 100,
});

if (controlled) {
if (angularVelocities.length > 10) {
angularVelocities.shift();
}

angularVelocities.push(
((wheel.rotation() - lastRotation) * 1000) / frame.timeDiff
);
} else {
var diff = (frame.timeDiff * angularVelocity) / 1000;
if (diff > 0.0001) {
wheel.rotate(diff);
} else if (!finished && !controlled) {
if (shape) {
var text = shape.getParent().findOne('Text').text();
var price = text.split('\n').join('');
alert('Your price is ' + price);
}
finished = true;
}
}
lastRotation = wheel.rotation();

if (shape) {
if (shape && (!activeWedge || shape._id !== activeWedge._id)) {
pointer.y(20);

new Konva.Tween({
node: pointer,
duration: 0.3,
y: 30,
easing: Konva.Easings.ElasticEaseOut,
}).play();

if (activeWedge) {
activeWedge.fillPriority('radial-gradient');
}
shape.fillPriority('fill');
activeWedge = shape;
}
}
}
function init() {
stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
layer = new Konva.Layer();
wheel = new Konva.Group({
x: stage.width() / 2,
y: 410,
});

for (var n = 0; n < numWedges; n++) {
addWedge(n);
}
pointer = new Konva.Wedge({
fillRadialGradientStartPoint: 0,
fillRadialGradientStartRadius: 0,
fillRadialGradientEndPoint: 0,
fillRadialGradientEndRadius: 30,
fillRadialGradientColorStops: [0, 'white', 1, 'red'],
stroke: 'white',
strokeWidth: 2,
lineJoin: 'round',
angle: 1,
radius: 30,
x: stage.width() / 2,
y: 33,
rotation: -90,
shadowColor: 'black',
shadowOffsetX: 3,
shadowOffsetY: 3,
shadowBlur: 2,
shadowOpacity: 0.5,
});

// add components to the stage
layer.add(wheel);
layer.add(pointer);
stage.add(layer);

// bind events
wheel.on('mousedown touchstart', function (evt) {
angularVelocity = 0;
controlled = true;
target = evt.target;
finished = false;
});
// add listeners to container
stage.addEventListener(
'mouseup touchend',
function () {
controlled = false;
angularVelocity = getAverageAngularVelocity() * 5;

if (angularVelocity > 20) {
angularVelocity = 20;
} else if (angularVelocity < -20) {
angularVelocity = -20;
}

angularVelocities = [];
},
false
);

stage.addEventListener(
'mousemove touchmove',
function (evt) {
var mousePos = stage.getPointerPosition();
if (controlled && mousePos && target) {
var x = mousePos.x - wheel.getX();
var y = mousePos.y - wheel.getY();
var atan = Math.atan(y / x);
var rotation = x >= 0 ? atan : atan + Math.PI;
var targetGroup = target.getParent();

wheel.rotation(
rotation - targetGroup.startRotation - target.angle() / 2
);
}
},
false
);

var anim = new Konva.Animation(animate, layer);

// wait one second and then spin the wheel
setTimeout(function () {
anim.start();
}, 1000);
}
init();
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Window_Frame_Designer.html b/docs/sandbox/Window_Frame_Designer.html new file mode 100644 index 000000000..9139e7fd5 --- /dev/null +++ b/docs/sandbox/Window_Frame_Designer.html @@ -0,0 +1,679 @@ + + + + + + HTML5 Canvas Window Frame Designer | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Window Frame Designer

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

HTML5 Canvas Window Frame Designer

That is a demo of window frame constructor. It was made as a prototype of a large CAD system.

+

The demo is made with react, konva, and react-konva.

+

If you are interested in similar product for your company - get in touch.

+

Instructions: You can select section and split it into several child sections. Also you can set sash type of a section.

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Zoom_Layer_On_hover.html b/docs/sandbox/Zoom_Layer_On_hover.html new file mode 100644 index 000000000..edfedffa9 --- /dev/null +++ b/docs/sandbox/Zoom_Layer_On_hover.html @@ -0,0 +1,678 @@ + + + + + + Zoom Image on Hover | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Zoom Image on Hover

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Instructions: Hover over an Image.

+ + +
Konva Zoom Image on Hover Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Zoom Image on Hover Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

stage.add(layer);

var imageObj = new Image();
imageObj.onload = function () {
var backgroundImage = new Konva.Image({
x: 0,
y: 0,
width: width,
height: height,
image: imageObj,
});
layer.add(backgroundImage);
};

imageObj.src = '/assets/space.jpg';

var zoomLevel = 2;
layer.on('mouseenter', function () {
layer.scale({
x: zoomLevel,
y: zoomLevel,
});
});

layer.on('mousemove', function (e) {
var pos = stage.getPointerPosition();
layer.x(-pos.x);
layer.y(-pos.y);
});

layer.on('mouseleave', function () {
layer.x(0);
layer.y(0);
layer.scale({
x: 1,
y: 1,
});
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/Zooming_Relative_To_Pointer.html b/docs/sandbox/Zooming_Relative_To_Pointer.html new file mode 100644 index 000000000..298a21a98 --- /dev/null +++ b/docs/sandbox/Zooming_Relative_To_Pointer.html @@ -0,0 +1,678 @@ + + + + + + Zooming stage relative to pointer position | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Zooming stage relative to pointer position

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Instructions: Mousewheel over canvas.

+ + +
Konva Zoom Image on Hover Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Zoom Relative to Stage Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var circle = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2,
radius: 50,
fill: 'green',
});
layer.add(circle);

var scaleBy = 1.01;
stage.on('wheel', (e) => {
// stop default scrolling
e.evt.preventDefault();

var oldScale = stage.scaleX();
var pointer = stage.getPointerPosition();

var mousePointTo = {
x: (pointer.x - stage.x()) / oldScale,
y: (pointer.y - stage.y()) / oldScale,
};

// how to scale? Zoom in? Or zoom out?
let direction = e.evt.deltaY > 0 ? 1 : -1;

// when we zoom on trackpad, e.evt.ctrlKey is true
// in that case lets revert direction
if (e.evt.ctrlKey) {
direction = -direction;
}

var newScale = direction > 0 ? oldScale * scaleBy : oldScale / scaleBy;

stage.scale({ x: newScale, y: newScale });

var newPos = {
x: pointer.x - mousePointTo.x * newScale,
y: pointer.y - mousePointTo.y * newScale,
};
stage.position(newPos);
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/sandbox/index.html b/docs/sandbox/index.html new file mode 100644 index 000000000..be271bb6a --- /dev/null +++ b/docs/sandbox/index.html @@ -0,0 +1,1055 @@ + + + + + + Framework Demos | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+

Framework Demos

+ +
+ + + + + + + + +
+
+ +
There are some demos of the Konva Framework. But also we have a lot of tutorials for almost every aspect of the framework.
+
+ +

+ CAD Systems +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ Games and Apps +

+
+ + + + + + + + + + + + + + + + + + + + + + + +

+ Common use cases +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ Performance tests +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ Other random demos +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/select_and_transform/Basic_demo.html b/docs/select_and_transform/Basic_demo.html new file mode 100644 index 000000000..5b5713f3b --- /dev/null +++ b/docs/select_and_transform/Basic_demo.html @@ -0,0 +1,731 @@ + + + + + + HTML5 Canvas Shape select, resize and rotate | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Shape select, resize and rotate

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

Transformer is a special kind of Konva.Group. It allows you easily resize and rotate any node or set of nodes.

+

To enable it you need to:

+
    +
  1. Create new instance with new Konva.Transformer()
  2. +
  3. Add it to layer
  4. +
  5. attach to node with transformer.nodes([shape]);
  6. +
  7. Update the layer with layer.batchDraw()
  8. +
+

Note: Transforming tool is not changing width and height properties of nodes when you resize them. Instead it changes scaleX and scaleY properties.

+

Instructions: Try to resize and rotate shapes. Click on empty area to remove selection. Use SHIFT or CTRL to add/remove shapes into/from selection. Try to select area on a canvas.

+ + +
Konva Shape transform and selection Demoview raw
<!DOCTYPE html>
<html>
<head>
<!-- USE DEVELOPMENT VERSION -->
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Select and Transform Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var rect1 = new Konva.Rect({
x: 60,
y: 60,
width: 100,
height: 90,
fill: 'red',
name: 'rect',
draggable: true,
});
layer.add(rect1);

var rect2 = new Konva.Rect({
x: 250,
y: 100,
width: 150,
height: 90,
fill: 'green',
name: 'rect',
draggable: true,
});
layer.add(rect2);

var tr = new Konva.Transformer();
layer.add(tr);

// by default select all shapes
tr.nodes([rect1, rect2]);

// add a new feature, lets add ability to draw selection rectangle
var selectionRectangle = new Konva.Rect({
fill: 'rgba(0,0,255,0.5)',
visible: false,
// disable events to not interrupt with events
listening: false,
});
layer.add(selectionRectangle);

var x1, y1, x2, y2;
var selecting = false;
stage.on('mousedown touchstart', (e) => {
// do nothing if we mousedown on any shape
if (e.target !== stage) {
return;
}
e.evt.preventDefault();
x1 = stage.getPointerPosition().x;
y1 = stage.getPointerPosition().y;
x2 = stage.getPointerPosition().x;
y2 = stage.getPointerPosition().y;

selectionRectangle.width(0);
selectionRectangle.height(0);
selecting = true;
});

stage.on('mousemove touchmove', (e) => {
// do nothing if we didn't start selection
if (!selecting) {
return;
}
e.evt.preventDefault();
x2 = stage.getPointerPosition().x;
y2 = stage.getPointerPosition().y;

selectionRectangle.setAttrs({
visible: true,
x: Math.min(x1, x2),
y: Math.min(y1, y2),
width: Math.abs(x2 - x1),
height: Math.abs(y2 - y1),
});
});

stage.on('mouseup touchend', (e) => {
// do nothing if we didn't start selection
selecting = false;
if (!selectionRectangle.visible()) {
return;
}
e.evt.preventDefault();
// update visibility in timeout, so we can check it in click event
selectionRectangle.visible(false);
var shapes = stage.find('.rect');
var box = selectionRectangle.getClientRect();
var selected = shapes.filter((shape) =>
Konva.Util.haveIntersection(box, shape.getClientRect())
);
tr.nodes(selected);
});

// clicks should select/deselect shapes
stage.on('click tap', function (e) {
// if we are selecting with rect, do nothing
if (selectionRectangle.visible()) {
return;
}

// if click on empty area - remove all selections
if (e.target === stage) {
tr.nodes([]);
return;
}

// do nothing if clicked NOT on our rectangles
if (!e.target.hasName('rect')) {
return;
}

// do we pressed shift or ctrl?
const metaPressed = e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey;
const isSelected = tr.nodes().indexOf(e.target) >= 0;

if (!metaPressed && !isSelected) {
// if no key pressed and the node is not selected
// select just one
tr.nodes([e.target]);
} else if (metaPressed && isSelected) {
// if we pressed keys and node was selected
// we need to remove it from selection:
const nodes = tr.nodes().slice(); // use slice to have new copy of array
// remove node from array
nodes.splice(nodes.indexOf(e.target), 1);
tr.nodes(nodes);
} else if (metaPressed && !isSelected) {
// add the node into selection
const nodes = tr.nodes().concat([e.target]);
tr.nodes(nodes);
}
});
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/select_and_transform/Centered_Scaling.html b/docs/select_and_transform/Centered_Scaling.html new file mode 100644 index 000000000..187eaa70e --- /dev/null +++ b/docs/select_and_transform/Centered_Scaling.html @@ -0,0 +1,723 @@ + + + + + + HTML5 Canvas Shape Resize Relative to Center | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Shape Resize Relative to Center

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

How to resize shape in both sides simultaneously?

To resize a node into both sides at the same time you can set centeredScaling to true or hold ALT key while moving an anchor (even if centeredScaling is false).

+

Instructions: Try to resize texts.

+ + +
Konva Shape transform and selection Demoview raw
<!DOCTYPE html>
<html>
<head>
<!-- USE DEVELOPMENT VERSION -->
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Centered Scaling Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var text1 = new Konva.Text({
x: 50,
y: 70,
fontSize: 30,
text: 'centeredScaling = true',
draggable: true,
});
layer.add(text1);

var tr1 = new Konva.Transformer({
nodes: [text1],
centeredScaling: true,
});
layer.add(tr1);

var text2 = new Konva.Text({
x: 50,
y: 200,
fontSize: 30,
text: 'centeredScaling = false',
draggable: true,
});
layer.add(text2);

var tr2 = new Konva.Transformer({
nodes: [text2],
centeredScaling: false,
});
layer.add(tr2);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/select_and_transform/Force_Update.html b/docs/select_and_transform/Force_Update.html new file mode 100644 index 000000000..3380d68bf --- /dev/null +++ b/docs/select_and_transform/Force_Update.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Force Update Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Force Update Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

Konva.Transformer automatically track properties of attached nodes.
So it will adopt its own properties automatically.

+

But in some cases Konva.Transformer can’t do this. Currently Konva.Transformer can not track deep changes inside Konva.Group node. In this case you will need to use forceUpdate method to reset transforming tools

+

Instructions: Click the button. See how transformer is changed.

+ + +
Transformer Force Update Demoview raw
<!DOCTYPE html>
<html>
<head>
<!-- USE DEVELOPMENT VERSION -->
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Transform Events Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#button {
position: absolute;
top: 5px;
left: 10px;
}
</style>
</head>

<body>
<div id="container"></div>
<input type="button" id="button" value="Add random shape" />
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var group = new Konva.Group({
x: 50,
y: 50,
draggable: true,
});
layer.add(group);

// create new transformer
var tr = new Konva.Transformer();
layer.add(tr);
tr.nodes([group]);

document.getElementById('button').addEventListener('click', addShape);
addShape();

function addShape() {
group.add(
new Konva.Circle({
x: Math.random() * 100,
y: Math.random() * 100,
radius: Math.random() * 100,
fill: Konva.Util.getRandomColor(),
stroke: 'black',
strokeWidth: Math.random() * 10,
})
);
// force update manually
tr.forceUpdate();
}
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/select_and_transform/Ignore_Stroke_On_Transform.html b/docs/select_and_transform/Ignore_Stroke_On_Transform.html new file mode 100644 index 000000000..60ebe6bf1 --- /dev/null +++ b/docs/select_and_transform/Ignore_Stroke_On_Transform.html @@ -0,0 +1,724 @@ + + + + + + How to resize shape on canvas without changing its stroke size? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to resize shape on canvas without changing its stroke size?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

Do you want to change size of a shape without changing its stroke size?

Remember, that Konva.Transformer is changing scaleX and scaleY properties of a node.
By default, if you are transforming a shape, its stroke will be scaled too. It some cases that is not a good behavior.

+

There are two ways to prevent stroke scaling: (1) reset scale of a shape or (2) use combination of shape.strokeScaleEnabled(false) and transformer.ignoreStroke(false).

+

Instructions: there are two rectangles to resize. The green one will reset it scale. The red one will just disable stroke scaling.

+ + +
Konva ignore strokeview raw
<!DOCTYPE html>
<html>
<head>
<!-- USE DEVELOPMENT VERSION -->
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Resize Text Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var rect1 = new Konva.Rect({
x: 50,
y: 60,
width: 100,
height: 100,
draggable: true,
fill: 'green',
stroke: 'black',
strokeWidth: 5,
});
layer.add(rect1);

var tr1 = new Konva.Transformer({
nodes: [rect1],
// ignore stroke in size calculations
ignoreStroke: true,
// manually adjust size of transformer
padding: 5,
});
layer.add(tr1);

// first way to skip stroke resize, is just by resetting scale
// and setting width/height instead
rect1.on('transform', () => {
rect1.setAttrs({
width: Math.max(rect1.width() * rect1.scaleX(), 5),
height: Math.max(rect1.height() * rect1.scaleY(), 5),
scaleX: 1,
scaleY: 1,
});
});

// another solution is to use combination of strokeScaleEnabled and ignoreStroke
var rect2 = new Konva.Rect({
x: 250,
y: 60,
width: 100,
height: 100,
draggable: true,
fill: 'red',
stroke: 'black',
strokeWidth: 5,
// do not scale strokes
strokeScaleEnabled: false,
});
layer.add(rect2);

var tr2 = new Konva.Transformer({
nodes: [rect2],
// ignore stroke in size calculations
ignoreStroke: true,
// manually adjust size of transformer
padding: 5,
});
layer.add(tr2);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/select_and_transform/Keep_Ratio.html b/docs/select_and_transform/Keep_Ratio.html new file mode 100644 index 000000000..f28f7ba77 --- /dev/null +++ b/docs/select_and_transform/Keep_Ratio.html @@ -0,0 +1,726 @@ + + + + + + Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

title: HTML5 Canvas Shape Resize With Ratio Preserved

How to resize shape with savings its proportion?

By default when you resize with corner anchors (top-left, top-right, bottom-left or bottom-right) Transformer will save ratio of a node.

+

You can set keepRatio to false if you don’t need that behavior.

+

Even if you set keepRatio to false you can hold SHIFT to still keep ratio.

+

Instructions: Try to resize texts.

+ + +
Konva Shape transform and selection Demoview raw
<!DOCTYPE html>
<html>
<head>
<!-- USE DEVELOPMENT VERSION -->
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Keep Ratio Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var text1 = new Konva.Text({
x: 50,
y: 70,
fontSize: 30,
text: 'keepRatio = true',
draggable: true,
});
layer.add(text1);

var tr1 = new Konva.Transformer({
nodes: [text1],
keepRatio: true,
enabledAnchors: [
'top-left',
'top-right',
'bottom-left',
'bottom-right',
],
});
layer.add(tr1);

var text2 = new Konva.Text({
x: 50,
y: 200,
fontSize: 30,
text: 'keepRatio = false',
draggable: true,
});
layer.add(text2);

var tr2 = new Konva.Transformer({
nodes: [text2],
keepRatio: false,
enabledAnchors: [
'top-left',
'top-right',
'bottom-left',
'bottom-right',
],
});
layer.add(tr2);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/select_and_transform/Resize_Limits.html b/docs/select_and_transform/Resize_Limits.html new file mode 100644 index 000000000..bae7e2375 --- /dev/null +++ b/docs/select_and_transform/Resize_Limits.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Shape Resize and Transform Limits | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Shape Resize and Transform Limits

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

How to limit size changes of a shape?

To limit or change resize and transform behavior you can use boundBoxFunc property.
It works a bit similar to dragBoundFunc.

+

Instructions: Try to resize a shape. You will see that its width is limited to 200.

+

Also you can control movement of every anchors individually. See Resize Snap Demo.

+ + +
Konva Shape transform and selection Demoview raw
<!DOCTYPE html>
<html>
<head>
<!-- USE DEVELOPMENT VERSION -->
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Transform Limits Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var rect = new Konva.Rect({
x: 160,
y: 60,
width: 100,
height: 90,
fill: 'red',
name: 'rect',
stroke: 'black',
draggable: true,
});
layer.add(rect);

var MAX_WIDTH = 200;
// create new transformer
var tr = new Konva.Transformer({
boundBoxFunc: function (oldBoundBox, newBoundBox) {
// "boundBox" is an object with
// x, y, width, height and rotation properties
// transformer tool will try to fit nodes into that box

// the logic is simple, if new width is too big
// we will return previous state
if (Math.abs(newBoundBox.width) > MAX_WIDTH) {
return oldBoundBox;
}

return newBoundBox;
},
});
layer.add(tr);
tr.nodes([rect]);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/select_and_transform/Resize_Snaps.html b/docs/select_and_transform/Resize_Snaps.html new file mode 100644 index 000000000..65903fe73 --- /dev/null +++ b/docs/select_and_transform/Resize_Snaps.html @@ -0,0 +1,727 @@ + + + + + + HTML5 Canvas Shape Resize Snapping | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Shape Resize Snapping

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

In some application, you may want to snap rotation near some values. Snapping makes a shape “sticky” near provided values and works like rounding.
You can control anchor position behavior with anchorDragBoundFunc method.

+
transformer.anchorDragBoundFunc(function (oldAbsPos, newAbsPos, event) {
// limit any another position on the x axis
return {
x: 0,
y: newAbsolutePosition.y,
};
});
+ +

In the demo we will try to implement snapping for resizing. There are many implementations possible.

+

Instructions: Try to resize a shape. You will see how transformer is trying to snap to guide lines.

+ + +
Konva Shape transform and selection Demoview raw
<!DOCTYPE html>
<html>
<head>
<!-- USE DEVELOPMENT VERSION -->
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Resize Snap Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

const layer = new Konva.Layer();
stage.add(layer);

const xSnaps = Math.round(stage.width() / 100);
const ySnaps = Math.round(stage.height() / 100);
const cellWidth = stage.width() / xSnaps;
const cellHeight = stage.height() / ySnaps;

for (var i = 0; i < xSnaps; i++) {
layer.add(
new Konva.Line({
x: i * cellWidth,
points: [0, 0, 0, stage.height()],
stroke: 'rgba(0, 0, 0, 0.2)',
strokeWidth: 1,
})
);
}

for (var i = 0; i < ySnaps; i++) {
layer.add(
new Konva.Line({
y: i * cellHeight,
points: [0, 0, stage.width(), 0],
stroke: 'rgba(0, 0, 0, 0.2)',
strokeWidth: 1,
})
);
}

const rect = new Konva.Rect({
x: 90,
y: 90,
width: 100,
height: 100,
fill: 'red',
draggable: true,
});
layer.add(rect);

const tr = new Konva.Transformer({
nodes: [rect],
anchorDragBoundFunc: function (oldPos, newPos, event) {
// oldPos - is old absolute position of the anchor
// newPos - is a new (possible) absolute position of the anchor based on pointer position
// it is possible that anchor will have a different absolute position after this function
// because every anchor has its own limits on position, based on resizing logic

// do not snap rotating point
if (tr.getActiveAnchor() === 'rotater') {
return newPos;
}

const dist = Math.sqrt(
Math.pow(newPos.x - oldPos.x, 2) + Math.pow(newPos.y - oldPos.y, 2)
);

// do not do any snapping with new absolute position (pointer position)
// is too far away from old position
if (dist > 10) {
return newPos;
}

const closestX = Math.round(newPos.x / cellWidth) * cellWidth;
const diffX = Math.abs(newPos.x - closestX);

const closestY = Math.round(newPos.y / cellHeight) * cellHeight;
const diffY = Math.abs(newPos.y - closestY);

const snappedX = diffX < 10;
const snappedY = diffY < 10;

// a bit different snap strategies based on snap direction
// we need to reuse old position for better UX
if (snappedX && !snappedY) {
return {
x: closestX,
y: oldPos.y,
};
} else if (snappedY && !snappedX) {
return {
x: oldPos.x,
y: closestY,
};
} else if (snappedX && snappedY) {
return {
x: closestX,
y: closestY,
};
}
return newPos;
},
});
layer.add(tr);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/select_and_transform/Resize_Text.html b/docs/select_and_transform/Resize_Text.html new file mode 100644 index 000000000..47ef749f4 --- /dev/null +++ b/docs/select_and_transform/Resize_Text.html @@ -0,0 +1,724 @@ + + + + + + How to resize text on canvas? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to resize text on canvas?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

How to change width of the text with transforming tool?

Remember, that Konva.Transformer is changing scaleX and scaleY properties of a node.
If you want to change width of the text, without changing its size, you should reset scale of a text back to 1 and adjust width accordantly.

+

You can use transform event to update text’s properties as you need it.

+

Instructions: Try to resize a text.

+ + +
Konva Text resize Demoview raw
<!DOCTYPE html>
<html>
<head>
<!-- USE DEVELOPMENT VERSION -->
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Resize Text Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var text = new Konva.Text({
x: 50,
y: 60,
fontSize: 20,
text: 'Hello from the Konva framework. Try to resize me.',
draggable: true,
});
layer.add(text);

var MIN_WIDTH = 20;
var tr = new Konva.Transformer({
nodes: [text],
padding: 5,
flipEnabled: false,
// enable only side anchors
enabledAnchors: ['middle-left', 'middle-right'],
// limit transformer size
boundBoxFunc: (oldBox, newBox) => {
if (Math.abs(newBox.width) < MIN_WIDTH) {
return oldBox;
}
return newBox;
},
});
layer.add(tr);
text.on('transform', () => {
// with enabled anchors we can only change scaleX
// so we don't need to reset height
// just width
text.setAttrs({
width: Math.max(text.width() * text.scaleX(), MIN_WIDTH),
scaleX: 1,
scaleY: 1,
});
});
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/select_and_transform/Rotation_Snaps.html b/docs/select_and_transform/Rotation_Snaps.html new file mode 100644 index 000000000..ac4ec4c1a --- /dev/null +++ b/docs/select_and_transform/Rotation_Snaps.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Shape Snap Rotation | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Shape Snap Rotation

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

In some application, you may want to snap rotation near some values. Snapping makes a shape “sticky” near provided values and works like rounding.

+

Most common snaps are 0, 45, 90, 135, 180, etc decreases. Snaps we allow to simpler set rotation it exactly these values.

+

For instance, if you have snap point at 45 deg, a user will be not able to set rotation to 43 deg. It will be rounded to 45 deg. But a user still will be able to set rotation to 35 deg, as it is too far from 45 so it will be not snapped.

+

Instructions: Try to rotate a shape. See snapping at 0, 90, 180 and 270 deg.

+ + +
Konva Shape transform and selection Demoview raw
<!DOCTYPE html>
<html>
<head>
<!-- USE DEVELOPMENT VERSION -->
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Rotation snap Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var text = new Konva.Text({
x: 50,
y: 70,
fontSize: 30,
text: 'Rotate me',
draggable: true,
});
layer.add(text);

var tr1 = new Konva.Transformer({
nodes: [text],
centeredScaling: true,
rotationSnaps: [0, 90, 180, 270],
resizeEnabled: false,
});
layer.add(tr1);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/select_and_transform/Stop_Transform.html b/docs/select_and_transform/Stop_Transform.html new file mode 100644 index 000000000..d8c722670 --- /dev/null +++ b/docs/select_and_transform/Stop_Transform.html @@ -0,0 +1,723 @@ + + + + + + HTML5 Canvas Stop Shape Transform | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Stop Shape Transform

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

If you need to stop transforming immediately you can use stopTransform methods of Konva.Transformer instance.

+

Instructions: Try to resize a shape. If width of the shape is bigger then 200 transforming will be stopped.

+ + +
Konva Stop Transform Demoview raw
<!DOCTYPE html>
<html>
<head>
<!-- USE DEVELOPMENT VERSION -->
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Stop Transform Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var rect = new Konva.Rect({
x: 160,
y: 60,
width: 100,
height: 90,
fill: 'red',
name: 'rect',
stroke: 'black',
draggable: true,
});
layer.add(rect);

// create new transformer
var tr = new Konva.Transformer();
layer.add(tr);
tr.nodes([rect]);
tr.on('transform', function () {
var width = rect.width() * rect.scaleX();
if (width > 200) {
tr.stopTransform();
// reset visible width to 200
// so future transform is possible
var scaleX = 200 / rect.width();
rect.scaleX(scaleX);
}
});
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/select_and_transform/Transform_Events.html b/docs/select_and_transform/Transform_Events.html new file mode 100644 index 000000000..dbb1803ba --- /dev/null +++ b/docs/select_and_transform/Transform_Events.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Transform and Resize events | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Transform and Resize events

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

Konva.Transformer object has special transform events that you can use in your app: transformstart, transform and transformend.

+

These events also will be triggered on attached node.

+

Instructions: Open console, try to transform, see logs

+ + +
Transform Events Demoview raw
<!DOCTYPE html>
<html>
<head>
<!-- USE DEVELOPMENT VERSION -->
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Transform Events Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var rect = new Konva.Rect({
x: 160,
y: 60,
width: 100,
height: 90,
fill: 'red',
name: 'rect',
stroke: 'black',
draggable: true,
});
layer.add(rect);

var text = new Konva.Text({
x: 5,
y: 5,
});
layer.add(text);
updateText();

// create new transformer
var tr = new Konva.Transformer();
layer.add(tr);
tr.nodes([rect]);

rect.on('transformstart', function () {
console.log('transform start');
});

rect.on('dragmove', function () {
updateText();
});
rect.on('transform', function () {
updateText();
console.log('transform');
});

rect.on('transformend', function () {
console.log('transform end');
});

function updateText() {
var lines = [
'x: ' + rect.x(),
'y: ' + rect.y(),
'rotation: ' + rect.rotation(),
'width: ' + rect.width(),
'height: ' + rect.height(),
'scaleX: ' + rect.scaleX(),
'scaleY: ' + rect.scaleY(),
];
text.text(lines.join('\n'));
}
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/select_and_transform/Transformer_Complex_Styling.html b/docs/select_and_transform/Transformer_Complex_Styling.html new file mode 100644 index 000000000..7dd6ab69f --- /dev/null +++ b/docs/select_and_transform/Transformer_Complex_Styling.html @@ -0,0 +1,724 @@ + + + + + + Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

title: Deep Style Konva Transformer

You can use anchorStyleFunc property of Konva.Transformer to have deeper control on styling of anchors.

+

Also take a look into Transformer Styling for simpler use cases.

+ + +
Konva Shape transform and selection styling Demoview raw
<!DOCTYPE html>
<html>
<head>
<!-- USE DEVELOPMENT VERSION -->
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Select and Transform Complex Styling Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var circle = new Konva.Circle({
x: 150,
y: 150,
radius: 70,
fill: 'red',
draggable: true,
});
layer.add(circle);

// create new transformer
var tr = new Konva.Transformer({
anchorStyleFunc: (anchor) => {
// anchor is Konva.Rect instance
// you manually change its styling
anchor.cornerRadius(10);
if (anchor.hasName('top-center') || anchor.hasName('bottom-center')) {
anchor.height(6);
anchor.offsetY(3);
anchor.width(30);
anchor.offsetX(15);
}
if (anchor.hasName('middle-left') || anchor.hasName('middle-right')) {
anchor.height(30);
anchor.offsetY(15);
anchor.width(6);
anchor.offsetX(3);
}
// you also can set other properties
// e.g. you can set fillPatternImage to set icon to the anchor
},
nodes: [circle],
});
layer.add(tr);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/select_and_transform/Transformer_Styling.html b/docs/select_and_transform/Transformer_Styling.html new file mode 100644 index 000000000..0cfd5500e --- /dev/null +++ b/docs/select_and_transform/Transformer_Styling.html @@ -0,0 +1,724 @@ + + + + + + Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

title: Style Konva Transformer

You can adjust styles of Konva.Transformer for your web app. You can change stroke, size and fill of all anchors.
Also you can change stroke color and size of border.

+

Also take a look into Complex Transformer Styling for fine tuning.

+ + +
Konva Shape transform and selection styling Demoview raw
<!DOCTYPE html>
<html>
<head>
<!-- USE DEVELOPMENT VERSION -->
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Select and Transform Styling Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

var circle = new Konva.Circle({
x: 150,
y: 150,
radius: 70,
fill: 'red',
draggable: true,
});
layer.add(circle);

// create new transformer
var tr = new Konva.Transformer({
anchorStroke: 'red',
anchorFill: 'yellow',
anchorSize: 20,
borderStroke: 'green',
borderDash: [3, 3],
nodes: [circle],
});
layer.add(tr);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/selectors/Select_by_Name.html b/docs/selectors/Select_by_Name.html new file mode 100644 index 000000000..d488c1dd2 --- /dev/null +++ b/docs/selectors/Select_by_Name.html @@ -0,0 +1,722 @@ + + + + + + HTML5 Canvas Select Shape by Name Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Select Shape by Name Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To select shapes by name with Konva, we can use the find() method using the . selector.
The find() method returns an array of nodes that match the selector string.

+ + +
Konva Select Shape by Name Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Select Shape by Name Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
#buttons {
position: absolute;
top: 5px;
left: 10px;
}
#buttons > input {
padding: 10px;
display: block;
margin-top: 5px;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="buttons">
<input type="button" id="activate" value="Activate rectangle" />
</div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
for (var n = 0; n < 10; n++) {
var circle = new Konva.Circle({
x: Math.random() * stage.width(),
y: Math.random() * stage.height(),
radius: Math.random() * 50 + 25,
fill: 'red',
strokeWidth: 3,
stroke: 'black',
});

layer.add(circle);
}

var rect1 = new Konva.Rect({
x: 250,
y: 90,
width: 100,
height: 50,
fill: 'green',
strokeWidth: 3,
stroke: 'black',
offset: {
x: 50,
y: 25,
},
draggable: true,
name: 'rectangle',
});

var rect2 = new Konva.Rect({
x: 70,
y: 90,
width: 100,
height: 50,
fill: 'green',
strokeWidth: 3,
stroke: 'black',
offset: {
x: 50,
y: 25,
},
draggable: true,
name: 'rectangle',
});
layer.add(rect1);
layer.add(rect2);
stage.add(layer);

var tweens = [];

document.getElementById('activate').addEventListener(
'click',
function () {
// select shapes by name
var shapes = stage.find('.rectangle');

// if there are currently any active tweens, destroy them
// before creating new ones
for (var n = 0; n < tweens.length; n++) {
tweens[n].destroy();
}

// apply transition to all nodes in the array
shapes.forEach(function (shape) {
tweens.push(
new Konva.Tween({
node: shape,
duration: 1,
scaleX: Math.random() * 2,
scaleY: Math.random() * 2,
easing: Konva.Easings.ElasticEaseOut,
}).play()
);
});
},
false
);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/selectors/Select_by_Type.html b/docs/selectors/Select_by_Type.html new file mode 100644 index 000000000..873ffa639 --- /dev/null +++ b/docs/selectors/Select_by_Type.html @@ -0,0 +1,722 @@ + + + + + + HTML5 Canvas Select Shape by Type Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Select Shape by Type Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To select shapes by type with Konva, we can use the find() method with the name of the type or class name.
The find() method returns an array of nodes that match the selector string.

+ + +
Konva Select Shape by Type Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Select Shape by Type Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
#buttons {
position: absolute;
top: 5px;
left: 10px;
}
#buttons > input {
padding: 10px;
display: block;
margin-top: 5px;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="buttons">
<input type="button" id="activate" value="Activate rectangle" />
</div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
for (var n = 0; n < 10; n++) {
var circle = new Konva.Circle({
x: Math.random() * stage.width(),
y: Math.random() * stage.height(),
radius: Math.random() * 50 + 25,
fill: 'red',
strokeWidth: 3,
stroke: 'black',
});

layer.add(circle);
}

var rect1 = new Konva.Rect({
x: 250,
y: 90,
width: 100,
height: 50,
fill: 'green',
strokeWidth: 3,
stroke: 'black',
offset: {
x: 50,
y: 25,
},
draggable: true,
});

var rect2 = new Konva.Rect({
x: 70,
y: 90,
width: 100,
height: 50,
fill: 'green',
strokeWidth: 3,
stroke: 'black',
offset: {
x: 50,
y: 25,
},
draggable: true,
});
layer.add(rect1);
layer.add(rect2);
stage.add(layer);

var tweens = [];

document.getElementById('activate').addEventListener(
'click',
function () {
// select shapes by name
var shapes = stage.find('Rect');

// if there are currently any active tweens, destroy them
// before creating new ones
for (var n = 0; n < tweens.length; n++) {
tweens[n].destroy();
}

// apply transition to all nodes in the array
shapes.forEach(function (shape) {
tweens.push(
new Konva.Tween({
node: shape,
duration: 1,
scaleX: Math.random() * 2,
scaleY: Math.random() * 2,
easing: Konva.Easings.ElasticEaseOut,
}).play()
);
});
},
false
);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/selectors/Select_by_id.html b/docs/selectors/Select_by_id.html new file mode 100644 index 000000000..c49b6b397 --- /dev/null +++ b/docs/selectors/Select_by_id.html @@ -0,0 +1,723 @@ + + + + + + HTML5 Canvas Select Shape by id Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Select Shape by id Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To select a shape by id with Konva, we can use the find() method using the # selector.
The find() method always returns an array of elements, even if we are expecting it to return one element.
if you need only one element you can use findOne() method.
The find() method works for any node, including the stage, layers, groups, and shapes.

+

Instructions: press the “Activate Rectangle” button to select the rectangle by id and perform a transition. You can also drag and drop the rectangle.

+ + +
Konva Select Shape by id Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Select Shape by id Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}

#buttons {
position: absolute;
top: 5px;
left: 10px;
}

#buttons > input {
padding: 10px;
display: block;
margin-top: 5px;
}
</style>
</head>

<body>
<div id="container"></div>
<div id="buttons">
<input type="button" id="activate" value="Activate rectangle" />
</div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
for (var n = 0; n < 10; n++) {
var circle = new Konva.Circle({
x: Math.random() * stage.width(),
y: Math.random() * stage.height(),
radius: Math.random() * 50 + 25,
fill: 'red',
strokeWidth: 3,
stroke: 'black',
});

layer.add(circle);
}

var rect = new Konva.Rect({
x: 300,
y: 90,
width: 100,
height: 50,
fill: 'green',
strokeWidth: 3,
offset: {
x: 50,
y: 25,
},
draggable: true,
id: 'myRect',
});

layer.add(rect);
stage.add(layer);

var tween;

document.getElementById('activate').addEventListener(
'click',
function () {
// or var shape = stage.findOne('#myRect');
var shape = stage.find('#myRect')[0];

if (tween) {
tween.destroy();
}

tween = new Konva.Tween({
node: shape,
duration: 1,
scaleX: Math.random() * 2,
scaleY: Math.random() * 2,
easing: Konva.Easings.ElasticEaseOut,
}).play();
},
false
);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Arc.html b/docs/shapes/Arc.html new file mode 100644 index 000000000..a1873c98f --- /dev/null +++ b/docs/shapes/Arc.html @@ -0,0 +1,724 @@ + + + + + + HTML5 canvas Arc Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Arc Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create an arc shape with Konva, we can instantiate a Konva.Arc() object.

+

For a full list of attributes and methods, check out the Konva.Arc documentation.

+ + +
Konva Arc Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Arc Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var arc = new Konva.Arc({
x: stage.width() / 2,
y: stage.height() / 2,
innerRadius: 40,
outerRadius: 70,
angle: 60,
fill: 'yellow',
stroke: 'black',
strokeWidth: 4,
});

// add the shape to the layer
layer.add(arc);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Arrow.html b/docs/shapes/Arrow.html new file mode 100644 index 000000000..56730d3d5 --- /dev/null +++ b/docs/shapes/Arrow.html @@ -0,0 +1,723 @@ + + + + + + HTML5 canvas Arrow Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Arrow Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create an arrow with Konva, we can instantiate a Konva.Arrow() object.

+

For a full list of attributes and methods, check out the Konva.Arrow documentation.

+ + +
Konva Arrow Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Arrow Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var arrow = new Konva.Arrow({
x: stage.width() / 4,
y: stage.height() / 4,
points: [0, 0, width / 2, height / 2],
pointerLength: 20,
pointerWidth: 20,
fill: 'black',
stroke: 'black',
strokeWidth: 4,
});

// add the shape to the layer
layer.add(arrow);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Circle.html b/docs/shapes/Circle.html new file mode 100644 index 000000000..de439abfa --- /dev/null +++ b/docs/shapes/Circle.html @@ -0,0 +1,723 @@ + + + + + + HTML5 canvas Circle Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Circle Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create a circle with Konva, we can instantiate a Konva.Circle() object.

+

For a full list of attributes and methods, check out the Konva.Circle documentation.

+ + +
Konva Circle Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Circle Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var circle = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

// add the shape to the layer
layer.add(circle);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Custom.html b/docs/shapes/Custom.html new file mode 100644 index 000000000..5a350a3ba --- /dev/null +++ b/docs/shapes/Custom.html @@ -0,0 +1,745 @@ + + + + + + HTML5 canvas Custom Shape Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Custom Shape Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create a custom shape with Konva, we can instantiate a Konva.Shape() object.

+

When creating a custom shape, we need to define a drawing function that is passed a Konva.Context renderer and a shape instance:

+
var rect = new Konva.Shape({
x: 10,
y: 20,
fill: '#00D2FF',
width: 100,
height: 50,
sceneFunc: function (context, shape) {
context.beginPath();
// don't need to set position of rect, Konva will handle it
context.rect(0, 0, shape.getAttr('width'), shape.getAttr('height'));
// (!) Konva specific method, it is very important
// it will apply are required styles
context.fillStrokeShape(shape);
}
});
+ +

Konva.Context is a wrapper around native 2d canvas context that have the same properties and methods with some additional API.

+

We can use the renderer to access the HTML5 Canvas context, and to use special methods like context.fillStrokeShape(shape) which automatically handles filling, stroking, and applying shadows.

+

There are two properties that can be used for drawing custom shapes: sceneFunc and hitFunc.

+

sceneFunc should be used to define visual appearance of a shape. Konva will use sceneFunc for drawing its hit graph for events detecting. So in many cases you just need to define sceneFunc only. If you want to overwrite hit testing, take a look into Custom Hit Region demo.

+

Some best practices for writing sceneFunc and hitFunc:

    +
  1. Make it as optimal, as possible because that function can be called many times per second. It is not ok to create images (document.createElement('image') or new window.Image()) or other large objects here.

    +
  2. +
  3. The function should not have any side effects like moving shapes, attaching events or changing state of your app.

    +
  4. +
  5. If you want to apply complex styles to the canvas manually or draw images, remember to define custom hitFunc.

    +
  6. +
  7. Do not apply position and scaling in sceneFunc manually. Konva can handle it automatically if you set that properties into shape instance directly. Example: shape.x(10).

    +
  8. +
  9. If possible do not apply styles in sceneFunc manually. Just draw a shape with some paths. context.fillStrokeShape(shape) function at the and will do all styling work.

    +
  10. +
  11. If you need more demos take a look into Konva core shapes implementations in the repo.

    +
  12. +
+

For a full list of attributes and methods, check out the Konva.Shape documentation

+ + +
Konva Custom Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Custom Shape Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

/*
* create a triangle shape by defining a
* drawing function which draws a triangle
*/
var triangle = new Konva.Shape({
width: 260,
height: 170,
sceneFunc: function (context, shape) {
const width = shape.width();
const height = shape.height();
context.beginPath();
context.moveTo(0, 0);
context.lineTo(width - 40, height - 90);
context.quadraticCurveTo(width - 110, height - 70, width, height);
context.closePath();

// (!) Konva specific method, it is very important
context.fillStrokeShape(shape);
},
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
});

// add the triangle shape to the layer
layer.add(triangle);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Ellipse.html b/docs/shapes/Ellipse.html new file mode 100644 index 000000000..108b04fa1 --- /dev/null +++ b/docs/shapes/Ellipse.html @@ -0,0 +1,725 @@ + + + + + + HTML5 canvas Ellipse Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Ellipse Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create a ellipse with Konva, we can instantiate a Konva.Ellipse() object.

+

For a full list of attributes and methods, check out the Konva.Ellipse documentation.

+ + +
Konva Ellipse Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Ellipse Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var oval = new Konva.Ellipse({
x: stage.width() / 2,
y: stage.height() / 2,
radiusX: 100,
radiusY: 50,
fill: 'yellow',
stroke: 'black',
strokeWidth: 4,
});

// add the shape to the layer
layer.add(oval);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Image.html b/docs/shapes/Image.html new file mode 100644 index 000000000..a7058e362 --- /dev/null +++ b/docs/shapes/Image.html @@ -0,0 +1,730 @@ + + + + + + HTML5 canvas Image Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Image Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create an image with Konva, we can instantiate a Konva.Image() object with image property.

+

For image property you can use:

+
    +
  1. instance of window.Image or document.createElement('image')
  2. +
  3. canvas element
  4. +
  5. video element
  6. +
+

For a full list of attributes and methods, check out the Konva.Image documentation.

+

If you want to draw SVG image into the canvas take a look into How to draw SVG image post.

+ + +
Konva Image Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Image Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
stage.add(layer);

// main API:
var imageObj = new Image();
imageObj.onload = function () {
var yoda = new Konva.Image({
x: 50,
y: 50,
image: imageObj,
width: 106,
height: 118,
});

// add the shape to the layer
layer.add(yoda);
};
imageObj.src = '/assets/yoda.jpg';

// alternative API:
Konva.Image.fromURL('/assets/darth-vader.jpg', function (darthNode) {
darthNode.setAttrs({
x: 200,
y: 50,
scaleX: 0.5,
scaleY: 0.5,
cornerRadius: 20,
});
layer.add(darthNode);
});
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Label.html b/docs/shapes/Label.html new file mode 100644 index 000000000..15ee509da --- /dev/null +++ b/docs/shapes/Label.html @@ -0,0 +1,723 @@ + + + + + + HTML5 canvas Label Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Label Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create a text label with Konva, which can be used for creating text with backgrounds, simple tooltips, or tooltips with pointers, we can instantiate a Konva.Label() object.

+

For a full list of attributes and methods, check out the Konva.Label documentation.

+ + +
Konva Label Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Label Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

// tooltip
var tooltip = new Konva.Label({
x: 170,
y: 75,
opacity: 0.75,
});

tooltip.add(
new Konva.Tag({
fill: 'black',
pointerDirection: 'down',
pointerWidth: 10,
pointerHeight: 10,
lineJoin: 'round',
shadowColor: 'black',
shadowBlur: 10,
shadowOffsetX: 10,
shadowOffsetY: 10,
shadowOpacity: 0.5,
})
);

tooltip.add(
new Konva.Text({
text: 'Tooltip pointing down',
fontFamily: 'Calibri',
fontSize: 18,
padding: 5,
fill: 'white',
})
);

// label with left pointer
var labelLeft = new Konva.Label({
x: 20,
y: 130,
opacity: 0.75,
});

labelLeft.add(
new Konva.Tag({
fill: 'green',
pointerDirection: 'left',
pointerWidth: 20,
pointerHeight: 28,
lineJoin: 'round',
})
);

labelLeft.add(
new Konva.Text({
text: 'Label pointing left',
fontFamily: 'Calibri',
fontSize: 18,
padding: 5,
fill: 'white',
})
);

// simple label
var simpleLabel = new Konva.Label({
x: 180,
y: 150,
opacity: 0.75,
});

simpleLabel.add(
new Konva.Tag({
fill: 'yellow',
})
);

simpleLabel.add(
new Konva.Text({
text: 'Simple label',
fontFamily: 'Calibri',
fontSize: 18,
padding: 5,
fill: 'black',
})
);

// add the labels to layer
layer.add(tooltip).add(labelLeft).add(simpleLabel);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Line_-_Blob.html b/docs/shapes/Line_-_Blob.html new file mode 100644 index 000000000..564fddaef --- /dev/null +++ b/docs/shapes/Line_-_Blob.html @@ -0,0 +1,726 @@ + + + + + + HTML5 canvas Blob Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Blob Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create a blob with Konva, we can instantiate a Konva.Line() object with closed = true and tension attributes.

+

To define the path of the line you should use points property. If you have three points with x and y coordinates you should define points property as: [x1, y1, x2, y2, x3, y3].

+

Flat array of numbers should work faster and use less memory than array of objects.

+

For a full list of attributes and methods, check out the Konva.Line documentation.

+ + +
Konva Blob Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Line Blob Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var blob = new Konva.Line({
points: [23, 20, 23, 160, 70, 93, 150, 109, 290, 139, 270, 93],
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 5,
closed: true,
tension: 0.3,
});

// add the shape to the layer
layer.add(blob);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Line_-_Polygon.html b/docs/shapes/Line_-_Polygon.html new file mode 100644 index 000000000..2f005c371 --- /dev/null +++ b/docs/shapes/Line_-_Polygon.html @@ -0,0 +1,726 @@ + + + + + + HTML5 canvas Polygon Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Polygon Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create a polygon with Konva, we can instantiate a Konva.Line() object with closed = true attribute.

+

To define the path of the line you should use points property. If you have three points with x and y coordinates you should define points property as: [x1, y1, x2, y2, x3, y3].

+

Flat array of numbers should work faster and use less memory than array of objects.

+

For a full list of attributes and methods, check out the Konva.Line documentation.

+ + +
Konva Polygon Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Line Polygon Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var poly = new Konva.Line({
points: [23, 20, 23, 160, 70, 93, 150, 109, 290, 139, 270, 93],
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 5,
closed: true,
});

// add the shape to the layer
layer.add(poly);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Line_-_Simple_Line.html b/docs/shapes/Line_-_Simple_Line.html new file mode 100644 index 000000000..9de278375 --- /dev/null +++ b/docs/shapes/Line_-_Simple_Line.html @@ -0,0 +1,726 @@ + + + + + + HTML5 canvas Line Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Line Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create a line with Konva, we can instantiate a Konva.Line() object.

+

To define the path of the line you should use points property. If you have three points with x and y coordinates you should define points property as: [x1, y1, x2, y2, x3, y3].

+

Flat array of numbers should work faster and use less memory than array of objects.

+

For a full list of attributes and methods, check out the Konva.Line documentation.

+ + +
Konva Line Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Simple Line Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var redLine = new Konva.Line({
points: [5, 70, 140, 23, 250, 60, 300, 20],
stroke: 'red',
strokeWidth: 15,
lineCap: 'round',
lineJoin: 'round',
});

// dashed line
var greenLine = new Konva.Line({
points: [5, 70, 140, 23, 250, 60, 300, 20],
stroke: 'green',
strokeWidth: 2,
lineJoin: 'round',
/*
* line segments with a length of 33px
* with a gap of 10px
*/
dash: [33, 10],
});

// complex dashed and dotted line
var blueLine = new Konva.Line({
points: [5, 70, 140, 23, 250, 60, 300, 20],
stroke: 'blue',
strokeWidth: 10,
lineCap: 'round',
lineJoin: 'round',
/*
* line segments with a length of 29px with a gap
* of 20px followed by a line segment of 0.001px (a dot)
* followed by a gap of 20px
*/
dash: [29, 20, 0.001, 20],
});

/*
* since each line has the same point array, we can
* adjust the position of each one using the
* move() method
*/
redLine.move({
x: 0,
y: 5,
});
greenLine.move({
x: 0,
y: 55,
});
blueLine.move({
x: 0,
y: 105,
});

layer.add(redLine);
layer.add(greenLine);
layer.add(blueLine);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Line_-_Spline.html b/docs/shapes/Line_-_Spline.html new file mode 100644 index 000000000..eb2310b1f --- /dev/null +++ b/docs/shapes/Line_-_Spline.html @@ -0,0 +1,726 @@ + + + + + + HTML5 canvas Spline Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Spline Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create a spline with Konva, we can instantiate a Konva.Line() object with tension attribute.

+

To define the path of the line you should use points property. If you have three points with x and y coordinates you should define points property as: [x1, y1, x2, y2, x3, y3].

+

Flat array of numbers should work faster and use less memory than array of objects.

+

For a full list of attributes and methods, check out the Konva.Line documentation.

+ + +
Konva Spline Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Line Spline Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var redLine = new Konva.Line({
points: [5, 70, 140, 23, 250, 60, 300, 20],
stroke: 'red',
strokeWidth: 15,
lineCap: 'round',
lineJoin: 'round',
tension: 1,
});

// dashed line
var greenLine = new Konva.Line({
points: [5, 70, 140, 23, 250, 60, 300, 20],
stroke: 'green',
strokeWidth: 2,
lineJoin: 'round',
/*
* line segments with a length of 33px
* with a gap of 10px
*/
dash: [33, 10],
lineCap: 'round',
tension: 0.5,
});

// complex dashed and dotted line
var blueLine = new Konva.Line({
points: [5, 70, 140, 23, 250, 60, 300, 20],
stroke: 'blue',
strokeWidth: 10,
lineCap: 'round',
lineJoin: 'round',
/*
* line segments with a length of 29px with a gap
* of 20px followed by a line segment of 0.001px (a dot)
* followed by a gap of 20px
*/
dash: [29, 20, 0.001, 20],
tension: 0.7,
});

/*
* since each line has the same point array, we can
* adjust the position of each one using the
* move() method
*/
redLine.move({
x: 20,
y: 5,
});
greenLine.move({
x: 20,
y: 55,
});
blueLine.move({
x: 20,
y: 105,
});

layer.add(redLine);
layer.add(greenLine);
layer.add(blueLine);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Path.html b/docs/shapes/Path.html new file mode 100644 index 000000000..e099f37d3 --- /dev/null +++ b/docs/shapes/Path.html @@ -0,0 +1,725 @@ + + + + + + HTML5 canvas SVG Path Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas SVG Path Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create an SVG path with Konva, we can instantiate a Konva.Path() object.

+

Paths are most commonly used when we want to export an SVG Path into an HTML5 Canvas path, or if we want to manifest complex drawings as a data string rather than creating a custom shape.

+

For a full list of attributes and methods, check out the Konva.Path documentation.

+

If you want to draw full SVG image into the canvas take a look into How to draw SVG image post.

+ + +
Konva Path Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Path Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var path = new Konva.Path({
x: 50,
y: 40,
data: 'M213.1,6.7c-32.4-14.4-73.7,0-88.1,30.6C110.6,4.9,67.5-9.5,36.9,6.7C2.8,22.9-13.4,62.4,13.5,110.9C33.3,145.1,67.5,170.3,125,217c59.3.156.7,93.5-71.9,111.5-106.1C263.4,64.2,247.2,22.9.3.15.1,6.7z',
fill: 'green',
scaleX: 0.5,
scaleY: 0.5,
});

// add the shape to the layer
layer.add(path);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Rect.html b/docs/shapes/Rect.html new file mode 100644 index 000000000..c30fabce2 --- /dev/null +++ b/docs/shapes/Rect.html @@ -0,0 +1,725 @@ + + + + + + HTML5 canvas Rect Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Rect Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create a rectangle with Konva, we can instantiate a Konva.Rect() object.

+

For a full list of attributes and methods, check out the Konva.Rect documentation.

+

You can define corner radius for Konva.Rect. It can be simple number or array of numbers [topLeft, topRight, bottomRight, bottomLeft].

+ + +
Konva Rect Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Rect Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var rect1 = new Konva.Rect({
x: 20,
y: 20,
width: 100,
height: 50,
fill: 'green',
stroke: 'black',
strokeWidth: 4,
});
// add the shape to the layer
layer.add(rect1);

var rect2 = new Konva.Rect({
x: 150,
y: 40,
width: 100,
height: 50,
fill: 'red',
shadowBlur: 10,
cornerRadius: 10,
});
layer.add(rect2);

var rect3 = new Konva.Rect({
x: 50,
y: 120,
width: 100,
height: 100,
fill: 'blue',
cornerRadius: [0, 10, 20, 30],
});
layer.add(rect3);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/RegularPolygon.html b/docs/shapes/RegularPolygon.html new file mode 100644 index 000000000..3a1fea376 --- /dev/null +++ b/docs/shapes/RegularPolygon.html @@ -0,0 +1,723 @@ + + + + + + HTML5 canvas Regular Polygon Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Regular Polygon Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create a regular polygon with Konva, we can instantiate a Konva.RegularPolygon() object.

+

For a full list of attributes and methods, check out the Konva.RegularPolygon documentation.

+ + +
Konva RegularPolygon Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva RegularPolygon Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var hexagon = new Konva.RegularPolygon({
x: 100,
y: 150,
sides: 6,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

layer.add(hexagon);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Ring.html b/docs/shapes/Ring.html new file mode 100644 index 000000000..64e9f8917 --- /dev/null +++ b/docs/shapes/Ring.html @@ -0,0 +1,724 @@ + + + + + + HTML5 canvas Ring Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Ring Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create a ring shape with Konva, we can instantiate a Konva.Ring() object.

+

For a full list of attributes and methods, check out the Konva.Ring documentation.

+ + +
Konva Ring Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Ring Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var ring = new Konva.Ring({
x: stage.width() / 2,
y: stage.height() / 2,
innerRadius: 40,
outerRadius: 70,
fill: 'yellow',
stroke: 'black',
strokeWidth: 4,
});

// add the shape to the layer
layer.add(ring);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Sprite.html b/docs/shapes/Sprite.html new file mode 100644 index 000000000..3569cd473 --- /dev/null +++ b/docs/shapes/Sprite.html @@ -0,0 +1,724 @@ + + + + + + HTML5 canvas Sprite Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Sprite Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create a sprite with Konva, we can instantiate a Konva.Sprite() object.

+

For a full list of attributes and methods, check out the Konva.Sprite documentation.

+ + +
Konva Sprite Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Sprite Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
#punch {
position: absolute;
top: 0;
left: 0;
}
</style>
</head>
<body>
<div id="container"></div>
<button id="punch">Punch</button>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
var animations = {
idle: [
// x, y, width, height (4 frames)
2, 2, 70, 119, 71, 2, 74, 119, 146, 2, 81, 119, 226, 2, 76, 119,
],
punch: [
// x, y, width, height (4 frames)
2, 138, 74, 122, 76, 138, 84, 122, 346, 138, 120, 122,
],
};

var imageObj = new Image();
imageObj.onload = function () {
var blob = new Konva.Sprite({
x: 50,
y: 50,
image: imageObj,
animation: 'idle',
animations: animations,
frameRate: 7,
frameIndex: 0,
});

// add the shape to the layer
layer.add(blob);

// add the layer to the stage
stage.add(layer);

// start sprite animation
blob.start();

// resume transition
document.getElementById('punch').addEventListener(
'click',
function () {
blob.animation('punch');
blob.on('frameIndexChange.button', function () {
if (this.frameIndex() === 2) {
setTimeout(function () {
blob.animation('idle');
blob.off('.button');
}, 1000 / blob.frameRate());
}
});
},
false
);
};
imageObj.src = '/assets/blob-sprite.png';
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Star.html b/docs/shapes/Star.html new file mode 100644 index 000000000..a024cf403 --- /dev/null +++ b/docs/shapes/Star.html @@ -0,0 +1,724 @@ + + + + + + HTML5 canvas Star Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Star Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create a star with Konva, we can instantiate a Konva.Star() object.

+

For a full list of attributes and methods, check out the Konva.Star documentation.

+ + +
Konva Star Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Star Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
});

var layer = new Konva.Layer();

var star = new Konva.Star({
x: stage.width() / 2,
y: stage.height() / 2,
numPoints: 6,
innerRadius: 40,
outerRadius: 70,
fill: 'yellow',
stroke: 'black',
strokeWidth: 4,
});

// add the shape to the layer
layer.add(star);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Text.html b/docs/shapes/Text.html new file mode 100644 index 000000000..493c1c47d --- /dev/null +++ b/docs/shapes/Text.html @@ -0,0 +1,725 @@ + + + + + + HTML5 canvas Text Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Text Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create text with Konva, we can instantiate a Konva.Text() object.

+

For a full list of attributes and methods, check out the Konva.Text documentation.

+

If you want to enable full rich text rendering features see Rich Text Demo.

+ + +
Konva Text Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Text Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var stage = new Konva.Stage({
container: 'container',
width: 340,
height: 300,
});

var layer = new Konva.Layer();

var simpleText = new Konva.Text({
x: stage.width() / 2,
y: 15,
text: 'Simple Text',
fontSize: 30,
fontFamily: 'Calibri',
fill: 'green',
});

// to align text in the middle of the screen, we can set the
// shape offset to the center of the text shape after instantiating it
simpleText.offsetX(simpleText.width() / 2);

// since this text is inside of a defined area, we can center it using
// align: 'center'
var complexText = new Konva.Text({
x: 20,
y: 60,
text: "COMPLEX TEXT\n\nAll the world's a stage, and all the men and women merely players. They have their exits and their entrances.",
fontSize: 18,
fontFamily: 'Calibri',
fill: '#555',
width: 300,
padding: 20,
align: 'center',
});

var rect = new Konva.Rect({
x: 20,
y: 60,
stroke: '#555',
strokeWidth: 5,
fill: '#ddd',
width: 300,
height: complexText.height(),
shadowColor: 'black',
shadowBlur: 10,
shadowOffsetX: 10,
shadowOffsetY: 10,
shadowOpacity: 0.2,
cornerRadius: 10,
});

// add the shapes to the layer
layer.add(simpleText);
layer.add(rect);
layer.add(complexText);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/TextPath.html b/docs/shapes/TextPath.html new file mode 100644 index 000000000..76939b5bb --- /dev/null +++ b/docs/shapes/TextPath.html @@ -0,0 +1,724 @@ + + + + + + HTML5 canvas TextPath Tutorial. Text follows path | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas TextPath Tutorial. Text follows path

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

How to draw a Text along path with HTML 5 Canvas?

To create a text path with Konva, we can instantiate a Konva.TextPath() object.

+

For a full list of attributes and methods, check out the Konva.TextPath documentation.

+ + +
Konva TextPath Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva TextPath Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var textpath = new Konva.TextPath({
x: 0,
y: 50,
fill: '#333',
fontSize: 16,
fontFamily: 'Arial',
text: "All the world's a stage, and all the men and women merely players.",
data: 'M10,10 C0,0 10,150 100,100 S300,150 5.0.300',
});

layer.add(textpath);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/shapes/Wedge.html b/docs/shapes/Wedge.html new file mode 100644 index 000000000..395ad7408 --- /dev/null +++ b/docs/shapes/Wedge.html @@ -0,0 +1,724 @@ + + + + + + HTML5 canvas Wedge Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 canvas Wedge Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To create a wedge with Konva, we can instantiate a Konva.Wedge() object.

+

For a full list of attributes and methods, check out the Konva.Wedge documentation.

+ + +
Konva Wedge Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Wedge Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var wedge = new Konva.Wedge({
x: stage.width() / 2,
y: stage.height() / 2,
radius: 70,
angle: 60,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
rotation: -120,
});

// add the shape to the layer
layer.add(wedge);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/styling/Blend_Mode.html b/docs/styling/Blend_Mode.html new file mode 100644 index 000000000..3a10009f1 --- /dev/null +++ b/docs/styling/Blend_Mode.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Blend mode with globalCompositeOperation Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Blend mode with globalCompositeOperation Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

globalCompositeOperation Documentation.

+

With Konva framework you can set globalCompositeOperation or blending mode operations with globalCompositeOperation property.

+

Instructions: drag red rectangle over text and see how they will be drawing together.

+ + +
Konva Blend_Mode Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Blend Mode Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var layer = new Konva.Layer();

var text = new Konva.Text({
text: 'Text Shadow!',
fontFamily: 'Calibri',
fontSize: 40,
x: 20,
y: 20,
fill: 'green',
// stroke: 'red',
strokeWidth: 2,
shadowColor: 'white',
// shadowBlur: 0,
shadowOffset: { x: 10, y: 10 },
// shadowOpacity: 0.5
});
layer.add(text);

var rect = new Konva.Rect({
x: 50,
y: 50,
// stroke: 'red',
width: 100,
height: 100,
fill: 'red',
draggable: true,
globalCompositeOperation: 'xor',
});

layer.add(rect);
stage.add(layer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/styling/Fill.html b/docs/styling/Fill.html new file mode 100644 index 000000000..79a1ddd65 --- /dev/null +++ b/docs/styling/Fill.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Set Fill Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Set Fill Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To fill a shape with Konva, we can set the fill property when we instantiate a shape, or we can use the fill() method.

+

Konva supports colors, patterns, linear gradients, and radial gradients.

+

Instructions: Mouseover each pentagon to change its fill. You can also drag and drop the shapes.

+ + +
Konva Fill Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Fill Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
function loadImages(sources, callback) {
var images = {};
var loadedImages = 0;
var numImages = 0;
// get num of sources
for (var src in sources) {
numImages++;
}
for (var src in sources) {
images[src] = new Image();
images[src].onload = function () {
if (++loadedImages >= numImages) {
callback(images);
}
};
images[src].src = sources[src];
}
}
function draw(images) {
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var layer = new Konva.Layer();

var colorPentagon = new Konva.RegularPolygon({
x: 80,
y: stage.height() / 2,
sides: 5,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
draggable: true,
});

var patternPentagon = new Konva.RegularPolygon({
x: 220,
y: stage.height() / 2,
sides: 5,
radius: 70,
fillPatternImage: images.darthVader,
fillPatternOffset: { x: -220, y: 70 },
stroke: 'black',
strokeWidth: 4,
draggable: true,
});

var linearGradPentagon = new Konva.RegularPolygon({
x: 360,
y: stage.height() / 2,
sides: 5,
radius: 70,
fillLinearGradientStartPoint: { x: -50, y: -50 },
fillLinearGradientEndPoint: { x: 50, y: 50 },
fillLinearGradientColorStops: [0, 'red', 1, 'yellow'],
stroke: 'black',
strokeWidth: 4,
draggable: true,
});

var radialGradPentagon = new Konva.RegularPolygon({
x: 500,
y: stage.height() / 2,
sides: 5,
radius: 70,
fillRadialGradientStartPoint: { x: 0, y: 0 },
fillRadialGradientStartRadius: 0,
fillRadialGradientEndPoint: { x: 0, y: 0 },
fillRadialGradientEndRadius: 70,
fillRadialGradientColorStops: [0, 'red', 0.5, 'yellow', 1, 'blue'],
stroke: 'black',
strokeWidth: 4,
draggable: true,
});

/*
* bind listeners
*/
colorPentagon.on('mouseover touchstart', function () {
this.fill('blue');
});

colorPentagon.on('mouseout touchend', function () {
this.fill('red');
});

patternPentagon.on('mouseover touchstart', function () {
this.fillPatternImage(images.yoda);
this.fillPatternOffset({ x: -100, y: 70 });
});

patternPentagon.on('mouseout touchend', function () {
this.fillPatternImage(images.darthVader);
this.fillPatternOffset({ x: -220, y: 70 });
});

linearGradPentagon.on('mouseover touchstart', function () {
this.fillLinearGradientStartPoint({ x: -50 });
this.fillLinearGradientEndPoint({ x: 50 });
this.fillLinearGradientColorStops([0, 'green', 1, 'yellow']);
});

linearGradPentagon.on('mouseout touchend', function () {
// set multiple properties at once with setAttrs
this.setAttrs({
fillLinearGradientStartPoint: { x: -50, y: -50 },
fillLinearGradientEndPoint: { x: 50, y: 50 },
fillLinearGradientColorStops: [0, 'red', 1, 'yellow'],
});
});

radialGradPentagon.on('mouseover touchstart', function () {
this.fillRadialGradientColorStops([
0,
'red',
0.5,
'yellow',
1,
'green',
]);
});

radialGradPentagon.on('mouseout touchend', function () {
// set multiple properties at once with setAttrs
this.setAttrs({
fillRadialGradientStartPoint: 0,
fillRadialGradientStartRadius: 0,
fillRadialGradientEndPoint: 0,
fillRadialGradientEndRadius: 70,
fillRadialGradientColorStops: [0, 'red', 0.5, 'yellow', 1, 'blue'],
});
});

layer.add(colorPentagon);
layer.add(patternPentagon);
layer.add(linearGradPentagon);
layer.add(radialGradPentagon);
stage.add(layer);
}
var sources = {
darthVader: '/assets/darth-vader.jpg',
yoda: '/assets/yoda.jpg',
};

loadImages(sources, function (images) {
draw(images);
});
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/styling/Fill_Stroke_Order.html b/docs/styling/Fill_Stroke_Order.html new file mode 100644 index 000000000..2256b8e63 --- /dev/null +++ b/docs/styling/Fill_Stroke_Order.html @@ -0,0 +1,726 @@ + + + + + + Fill and stroke order demo | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Fill and stroke order demo

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

If a shape has both fill and stroke, by default, Konva will draw filling first then stroke on top of it. That is the best behavior for most of the applications.

+

How to draw fill part on top of the stroke?

In some rare cases you may need a shape that has stroke first, then a fill on top of it. For that use case you may use fillAfterStrokeEnabled property.

+
shape.fillAfterStrokeEnabled(true);
+ +

Instructions: Take a look into two examples of different fill&stroke order.

+ + +
Konva Fill Stroke Order Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Fill Stroke Order Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();
// add the layer to the stage
stage.add(layer);

var text1 = new Konva.Text({
text: 'Default shape rendering.\nfillAfterStrokeEnabled = false',
x: 50,
y: 50,
fontSize: 40,
stroke: 'green',
fill: 'yellow',
strokeWidth: 3,
});
layer.add(text1);

var text2 = new Konva.Text({
text: 'Reversed rendering order.\nfillAfterStrokeEnabled = true',
x: 50,
y: 150,
fontSize: 40,
stroke: 'green',
fill: 'yellow',
strokeWidth: 3,
fillAfterStrokeEnabled: true,
});
layer.add(text2);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/styling/Hide_and_Show.html b/docs/styling/Hide_and_Show.html new file mode 100644 index 000000000..6481de73b --- /dev/null +++ b/docs/styling/Hide_and_Show.html @@ -0,0 +1,723 @@ + + + + + + HTML5 Canvas Hide and Show Shape Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Hide and Show Shape Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To hide and show a shape with Konva, we can set the visible property when we instantiate a shape, or we can use the hide() and show() methods.

+

Instructions: Click on the buttons to show and hide the shape.

+ + +
Konva Hide and Show Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Hide and Show Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
#buttons {
position: absolute;
left: 10px;
top: 0px;
}
button {
margin-top: 10px;
display: block;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="buttons">
<button id="show">show</button>
<button id="hide">hide</button>
</div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var layer = new Konva.Layer();

var pentagon = new Konva.RegularPolygon({
x: stage.width() / 2,
y: stage.height() / 2,
sides: 5,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
visible: false,
});

// add the shape to the layer
layer.add(pentagon);

// add the layer to the stage
stage.add(layer);

// add button event bindings
document.getElementById('show').addEventListener(
'click',
function () {
pentagon.show();
},
false
);

document.getElementById('hide').addEventListener(
'click',
function () {
pentagon.hide();
},
false
);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/styling/Line_Join.html b/docs/styling/Line_Join.html new file mode 100644 index 000000000..6f98f3670 --- /dev/null +++ b/docs/styling/Line_Join.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Line Join Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Line Join Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To set the line join for a shape with Konva, we can set the lineJoin property when we instantiate a shape, or we can use the lineJoin() method.

+

The lineJoin property can be set to miter, bevel, or round. Unless otherwise specified, the default line join is miter.

+

Instructions: Mouseover the triangle to change the line join style.

+ + +
Konva Line Join Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Line Join Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var layer = new Konva.Layer();

var triangle = new Konva.RegularPolygon({
x: stage.width() / 2,
y: stage.height() / 2,
sides: 3,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 20,
lineJoin: 'bevel',
});

triangle.on('mouseover', function () {
this.lineJoin('round');
});

triangle.on('mouseout', function () {
this.lineJoin('bevel');
});

// add the shape to the layer
layer.add(triangle);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/styling/Mouse_Cursor.html b/docs/styling/Mouse_Cursor.html new file mode 100644 index 000000000..cb87e52ae --- /dev/null +++ b/docs/styling/Mouse_Cursor.html @@ -0,0 +1,723 @@ + + + + + + HTML5 Canvas Change Mouse Cursor Style | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Change Mouse Cursor Style

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To change mouse cursor with Konva framework you just need to listen events, where do you need to change the cursor, and apply new styles manually for Stage container.

+

Instructions: Mouseover each pentagon and see how cursor is changing

+ + +
Konva Mouse Cursor Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Mouse Cursor Styles Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var layer = new Konva.Layer();

var shape1 = new Konva.RegularPolygon({
x: 80,
y: stage.height() / 2,
sides: 5,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
draggable: true,
});

var shape2 = new Konva.RegularPolygon({
x: 220,
y: stage.height() / 2,
sides: 5,
radius: 70,
fill: 'green',
stroke: 'black',
strokeWidth: 4,
draggable: true,
});

var shape3 = new Konva.RegularPolygon({
x: 360,
y: stage.height() / 2,
sides: 5,
radius: 70,
fillLinearGradientStartPoint: { x: -50, y: -50 },
fillLinearGradientEndPoint: { x: 50, y: 50 },
fillLinearGradientColorStops: [0, 'red', 1, 'yellow'],
stroke: 'black',
strokeWidth: 4,
draggable: true,
});

shape1.on('mouseenter', function () {
stage.container().style.cursor = 'pointer';
});

shape1.on('mouseleave', function () {
stage.container().style.cursor = 'default';
});

shape2.on('mouseenter', function () {
stage.container().style.cursor = 'move';
});

shape2.on('mouseleave', function () {
stage.container().style.cursor = 'default';
});

shape3.on('mouseenter', function () {
stage.container().style.cursor = 'crosshair';
});

shape3.on('mouseleave', function () {
stage.container().style.cursor = 'default';
});

layer.add(shape1);
layer.add(shape2);
layer.add(shape3);
stage.add(layer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/styling/Opacity.html b/docs/styling/Opacity.html new file mode 100644 index 000000000..782a09017 --- /dev/null +++ b/docs/styling/Opacity.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Opacity Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Opacity Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To set a shape opacity with Konva, we can set the opacity property when we instantiate the node, or we can use the opacity() method.

+

Shapes can have an opacity value between 0 and 1, where 0 is fully transparent, and 1 is fully opaque. Unless otherwise specified, all shapes are defaulted with an opacity value of 1.

+

If you want to apply transparency for several shapes without seen overlapping areas, take a look into Transparent Group Demo

+

Instructions: Mouseover the pentagon to change its opacity.

+ + +
Konva Opacity Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Opacity Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var layer = new Konva.Layer();

var pentagon = new Konva.RegularPolygon({
x: stage.width() / 2,
y: stage.height() / 2,
sides: 5,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
opacity: 0.5,
});

pentagon.on('mouseover', function () {
this.opacity(1);
});

pentagon.on('mouseout', function () {
this.opacity(0.5);
});

// add the shape to the layer
layer.add(pentagon);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/styling/Shadow.html b/docs/styling/Shadow.html new file mode 100644 index 000000000..a87279899 --- /dev/null +++ b/docs/styling/Shadow.html @@ -0,0 +1,723 @@ + + + + + + HTML5 Canvas Shadows Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Shadows Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To apply shadows with Konva, we can set the shadowColor, shadowOffset, shadowBlur, and shadowOpacity properties when we instantiate a shape.

+

We can adjust the shadow properties after instantiation by using the shadowColor(), shadowOffset(), shadowBlur(), and shadowOpacity() methods.

+ + +
Konva Shadows Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Shadow Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var layer = new Konva.Layer();

var text = new Konva.Text({
text: 'Text Shadow!',
fontFamily: 'Calibri',
fontSize: 40,
x: 20,
y: 20,
stroke: 'red',
strokeWidth: 2,
shadowColor: 'black',
shadowBlur: 0,
shadowOffset: { x: 10, y: 10 },
shadowOpacity: 0.5,
});

var line = new Konva.Line({
stroke: 'green',
strokeWidth: 10,
lineJoin: 'round',
lineCap: 'round',
points: [50, 140, 250, 160],
shadowColor: 'black',
shadowBlur: 10,
shadowOffset: { x: 10, y: 10 },
shadowOpacity: 0.5,
});

var rect = new Konva.Rect({
x: 100,
y: 120,
width: 100,
height: 50,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
shadowColor: 'black',
shadowBlur: 10,
shadowOffset: { x: 10, y: 10 },
shadowOpacity: 0.5,
});

layer.add(text);
layer.add(line);
layer.add(rect);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/styling/Stroke.html b/docs/styling/Stroke.html new file mode 100644 index 000000000..b9e93524b --- /dev/null +++ b/docs/styling/Stroke.html @@ -0,0 +1,723 @@ + + + + + + HTML5 Canvas Set Shape Stroke Color and Width Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Set Shape Stroke Color and Width Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To set a shape stroke and stroke width with Konva, we can set the stroke and strokeWidth properties when we instantiate a shape, or we can use the stroke() and strokeWidth() methods.

+

Instructions: Mouseover the pentagon to change its stroke color and width.

+ + +
Konva Stroke Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Stroke Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var layer = new Konva.Layer();

var pentagon = new Konva.RegularPolygon({
x: stage.width() / 2,
y: stage.height() / 2,
sides: 5,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

pentagon.on('mouseover', function () {
this.stroke('blue');
this.strokeWidth(20);
});

pentagon.on('mouseout', function () {
this.stroke('black');
this.strokeWidth(4);
});
// add the shape to the layer
layer.add(pentagon);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/support.html b/docs/support.html new file mode 100644 index 000000000..cc5df976e --- /dev/null +++ b/docs/support.html @@ -0,0 +1,729 @@ + + + + + + Need help with Konva library? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Need help with Konva library?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

Looking for a help with Konva framework?

Here is what you should do:

+
    +
  1. First try to find solutions online. Try to search your question. You can use google, or built-in search on top of that page.
  2. +
  3. The best place to ask questions is StackOverflow. You will have more chances to have a good answer if you create hight quality question with online demo, code samples, correct tags, etc.
  4. +
  5. If you found a bug or you want to request a feature go to Issues Page.
  6. +
  7. If you just want to discuss Konva you can join discord Chat
  8. +
  9. If you have something interesting to share use Twitter #konvajs hashtag
  10. +
  11. Visit Changelog to see what is changing.
  12. +
  13. Need a consulting or strategy review? Go to Consulting Page
  14. +
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/svelte/Bindings.html b/docs/svelte/Bindings.html new file mode 100644 index 000000000..3f68a4396 --- /dev/null +++ b/docs/svelte/Bindings.html @@ -0,0 +1,540 @@ + + + + + + Binding the config prop | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Binding the config prop

+ +
+ + + + + + + + +
+
+ +
+
+ + +
+ + + + +

By default svelte-konva keeps the provided config prop object in sync with the internal state of Konva. This means that the supplied config object will be updated to the correct values (position, rotation, scale, …) after dragend and transformend events. svelte-konva will only update the keys you provided in your config object and not add any additional keys which might have changed.

+

Binding the config prop

By binding the config prop any reactive statements depending on your config object will be triggered once svelte-konva updates the config values. If not bound the values of the config object will still be updated by svelte-konva but not trigger any reactive blocks depending on it. Generally, you should bind the config prop if possible, not only to keep reactivity but to also make it more explicit that the passed config object can be changed by svelte-konva.

+

Disabling automatic syncing

In most cases this default behavior is what you want as you usually want to keep your Svelte state consistent with the actual state of the canvas. In some cases this might not be beneficial though. In such cases you can opt out of this behavior by passing the staticConfig prop to the component:

+
<script>
import { Stage, Layer, Rect } from 'svelte-konva';

// x and y values will not be synced with actual position after dragend
const config = { x: 100, y: 100, width: 400, height: 200, fill: 'blue', draggable: true };
</script>

<Stage config={{ width: window.innerWidth, height: window.innerHeight }}>
<Layer>
<Rect {config} staticConfig />
</Layer>
</Stage>
+

Keep in mind that svelte-konva will evaluate the staticConfig prop only once during component mounting. Changing the staticConfig prop after the component has mounted will not have any effect.

+

Drag the different rings and observe the reactive changes triggered by Svelte. Note how dragging the red ring does not trigger a reactive change but still changes the actual value of the config due to not being bound.

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/svelte/Cache.html b/docs/svelte/Cache.html new file mode 100644 index 000000000..0ee64fb73 --- /dev/null +++ b/docs/svelte/Cache.html @@ -0,0 +1,538 @@ + + + + + + How to cache canvas shapes with Svelte | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to cache canvas shapes with Svelte

+ +
+ + + + + + + + +
+
+ +
+
+ + +
+ + + + +

If you want to cache a node in a Svelte app, you need to have an access to Konva node and use node.cache() function.

+

To get access to a node you can use the handle prop. See Konva Node for more information.

+

Instruction: try to drag whole stage. Then try again with cached group.

+

You should see much better performance.

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/svelte/Custom_Shape.html b/docs/svelte/Custom_Shape.html new file mode 100644 index 000000000..c77d963f6 --- /dev/null +++ b/docs/svelte/Custom_Shape.html @@ -0,0 +1,537 @@ + + + + + + How to draw custom canvas shape with Svelte? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to draw custom canvas shape with Svelte?

+ +
+ + + + + + + + +
+
+ +
+
+ + +
+ + + + +

To create a custom shape with svelte-konva, we should use Shape component.

+

When creating a custom shape, we need to define a drawing function that is passed a Konva.Canvas renderer.

+

We can use the renderer to access the HTML5 Canvas context, and to use special methods like context.fillStrokeShape(shape) which automatically handles filling, stroking, and applying shadows.

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/svelte/Drag_And_Drop.html b/docs/svelte/Drag_And_Drop.html new file mode 100644 index 000000000..c6bae2939 --- /dev/null +++ b/docs/svelte/Drag_And_Drop.html @@ -0,0 +1,536 @@ + + + + + + Drag and drop canvas shapes with Svelte | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Drag and drop canvas shapes with Svelte

+ +
+ + + + + + + + +
+
+ +
+
+ + +
+ + + + +

To enable drag&drop for any node on canvas you just need to pass draggable: true property into the component’s config prop.

+

svelte-konva automatically keeps your config in sync with the Konva node on dragend. See the bindings doc page for more details.

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/svelte/Events.html b/docs/svelte/Events.html new file mode 100644 index 000000000..d5641fc65 --- /dev/null +++ b/docs/svelte/Events.html @@ -0,0 +1,542 @@ + + + + + + How to listen to an event on a canvas shape with Svelte and Konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to listen to an event on a canvas shape with Svelte and Konva?

+ +
+ + + + + + + + +
+
+ +
+
+ + +
+ + + + +

With svelte-konva you can easily listen to user input events (click, dblclick, mouseover, tap, dbltap, touchstart, etc…) and drag&drop events (dragstart, dragmove, dragend).

+
<script>
import { Stage, Layer, Rect } from 'svelte-konva';

function handleClick(e) {
const konvaEvent = e.detail;
window.alert(`Clicked on rectangle: ${konvaEvent.type}`);
}
</script>

<Stage config={{ width: window.innerWidth, height: window.innerHeight }}>
<Layer>
<Rect
config={{ x: 100, y: 100, width: 400, height: 200, fill: 'blue' }}
on:pointerclick={handleClick}
/>
</Layer>
</Stage>
+ +

For the full list of events take a look into on() method documentation.

+

Bubbling

Konva events bubble up by default. To prevent this you can call preventDefault() on the event object or set the cancelBubble property of the Konva event to false:

+
function handleClick(e) {
const konvaEvent = e.detail;

// Cancel bubbling
e.preventDefault();

// or alternatively
konvaEvent.cancelBubble = true;
}
+ + +``` +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/svelte/Filters.html b/docs/svelte/Filters.html new file mode 100644 index 000000000..fe724aedb --- /dev/null +++ b/docs/svelte/Filters.html @@ -0,0 +1,537 @@ + + + + + + How to apply canvas filters with Svelte and Konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to apply canvas filters with Svelte and Konva?

+ +
+ + + + + + + + +
+
+ +
+
+ + +
+ + + + +

To apply filters you need to cache Konva.Node manually. You can do this initially in the onMount() method.

+

In case you dynamically change the style of the nodes you need to recache them manually for the changes to take effect on the canvas. This can be done by calling the cache() method on the affected nodes directly after a change (like in the demo) or in the afterUpdate() method to automatically recache the node on each state change in the component.

+

Instructions: hover over the rectangle to see the changes

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/svelte/Images.html b/docs/svelte/Images.html new file mode 100644 index 000000000..c9bc25d8b --- /dev/null +++ b/docs/svelte/Images.html @@ -0,0 +1,535 @@ + + + + + + How to draw image on canvas with Svelte? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to draw image on canvas with Svelte?

+ +
+ + + + + + + + +
+
+ +
+
+ + +
+ + + + +

For images you need to manually create a native window.Image instance or canvas element and use it as image attribute of Image component.

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/svelte/Konva_Node.html b/docs/svelte/Konva_Node.html new file mode 100644 index 000000000..6696b16a8 --- /dev/null +++ b/docs/svelte/Konva_Node.html @@ -0,0 +1,536 @@ + + + + + + Accessing the Konva node | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Accessing the Konva node

+ +
+ + + + + + + + +
+
+ +
+
+ + +
+ + + + +

In some cases you might need to access the underlying Konva node of the svelte-konva component directly. You can do this by binding the handle prop of the component or by accessing it in the payload of a Konva event.

+

Caution: The node is initially undefined and becomes defined one tick after the component has been mounted. If you want to access the node directly after component mounting you need to await a Svelte tick() before the handle prop becomes defined.

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/svelte/Labels.html b/docs/svelte/Labels.html new file mode 100644 index 000000000..d747ae918 --- /dev/null +++ b/docs/svelte/Labels.html @@ -0,0 +1,536 @@ + + + + + + Using labels with Svelte | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Using labels with Svelte

+ +
+ + + + + + + + +
+
+ +
+
+ + +
+ + + + +

Creating a label is a multi-step process in Konva, as a Label instance needs to contain a Tag and Text instance to function. In svelte-konva the Tag and Text components can be easily nested inside the Label component to automatically create a correct Label without having to wire things up manually.

+

Hover over the circles to show the tooltips,

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/svelte/Save_Load.html b/docs/svelte/Save_Load.html new file mode 100644 index 000000000..8e6c7d0df --- /dev/null +++ b/docs/svelte/Save_Load.html @@ -0,0 +1,537 @@ + + + + + + Saving and loading canvas with Svelte and Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Saving and loading canvas with Svelte and Konva

+ +
+ + + + + + + + +
+
+ +
+
+ + +
+ + + + +

Native Konva has special mechanizm to save/load a full canvas stage with node.toJSON() and node.create(json) functions (see demo).

+

This approach is not recommended when using svelte-konva. In svelte-konva you should instead save the state of your app which also resembles the full stage data required. So there is no need to save any Konva internals and nodes.

+

The demo saves and retrieves the data from localstorage as JSON but you’re free to use any way of saving you’d like.

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/svelte/Shapes.html b/docs/svelte/Shapes.html new file mode 100644 index 000000000..9ac522a8c --- /dev/null +++ b/docs/svelte/Shapes.html @@ -0,0 +1,537 @@ + + + + + + Drawing canvas shapes with Svelte | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Drawing canvas shapes with Svelte

+ +
+ + + + + + + + +
+
+ +
+
+ + +
+ + + + +

All svelte-konva components correspond to Konva components of the same name.
All the parameters available for Konva objects are valid props for
corresponding svelte-konva components, unless noted otherwise.

+

Core shapes are: Rect, Circle, Ellipse, Line, Image, Text, TextPath, Star,
Label, SVG Path, RegularPolygon. You can also create custom shapes.

+

To get more info about Konva you can read Konva Overview.

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/svelte/Simple_Animations.html b/docs/svelte/Simple_Animations.html new file mode 100644 index 000000000..79b79a106 --- /dev/null +++ b/docs/svelte/Simple_Animations.html @@ -0,0 +1,537 @@ + + + + + + How to apply canvas animations with Svelte and Konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to apply canvas animations with Svelte and Konva?

+ +
+ + + + + + + + +
+
+ +
+
+ + +
+ + + + +

Konva itself has two methods for animations Tween and Animation. You can apply both of them to nodes manually.

+

For simple use cases we recommend to use node.to() method.

+

Instructions: Try to move a rectangle.

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/svelte/SvelteKit.html b/docs/svelte/SvelteKit.html new file mode 100644 index 000000000..567185c45 --- /dev/null +++ b/docs/svelte/SvelteKit.html @@ -0,0 +1,557 @@ + + + + + + How to use svelte-konva with SvelteKit? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to use svelte-konva with SvelteKit?

+ +
+ + + + + + + + +
+
+ +
+
+ + +
+ + + + +

Generally, svelte-konva is a client-side only library. When using SvelteKit, special care needs to be taken if svelte-konva/Konva functionality is used on prerendered and server side rendered (SSR) components. Prerendering and SSR happens in a Node.js environment which causes Konva to require the canvas library as Konva can also be used in Node.js environments. When you use svelte-konva in such conditions you’ll likely run into the following error:

+
+

Error: Cannot find module ‘canvas’

+
+

There are multiple solutions to this problem:

+

Installing canvas:

Simplest solution is to install canvas:

+
npm i canvas
+ +

This will satisfy the canvas dependency of Konva and you can use svelte-konva components in prerendered and SSR SvelteKit pages. The solution is a bit messy though, as you now have installed a package you don’t really need which adds unnecessary overhead. Alternatively use one of the following solutions:

+

Dynamically import your svelte-konva stage:

A better approach is to dynamically import your svelte-konva canvas on the client-side only. Suppose you have a Svelte component containing your stage with various svelte-konva components:

+

MyCanvas.svelte

+
<script>
import { Stage, Layer, Rect } from 'svelte-konva';
import OtherComponentUsingSvelteKonva from './OtherComponentUsingSvelteKonva.svelte';

const rectangleConfig = {
/*...*/
};
</script>

<Stage config={{ width: 1000, height: 1000 }}>
<Layer>
<Rect bind:config={rectangleConfig} />

<OtherComponentUsingSvelteKonva />
</Layer>
</Stage>
+ +

To use this component inside a SvelteKit prerendered/SSR page you can dynamically import it inside onMount() and render it using <svelte:component>:

+

+page.svelte

+
<script>
import { onMount } from 'svelte';
// typescript:
// import type MyCanvasComponent from '$lib/MyCanvas.svelte';

let MyCanvas;
// typescript:
// let MyCanvas: typeof MyCanvasComponent;

onMount(async () => {
// Dynamically import your canvas component encapsulating all svelte-konva functionality inside onMount()
MyCanvas = (await import('$lib/MyCanvas.svelte')).default;
});
</script>

<div>
<p>This is my fancy server side rendered (or prerendered) page.</p>

<!-- Use your dynamically imported svelte-konva canvas component with a svelte:component block, you can pass any component props as usual -->
<svelte:component this={MyCanvas} someProp="SomeString" />
</div>
+ +

Dynamically import svelte-konva using vite:

The vite-plugin-iso-import allows you to make client-side only imports without needing the manual approach in onMount() described above. Please follow the installation instructions in the README then you can dynamically import your component like so:

+

+page.svelte

+
<script>
import MyCanvasComponent from '$lib/MyCanvas.svelte?client'; // Client-side only import

// Set component variable to null if page is rendered in SSR, otherwise use client-side only import
let MyCanvas = import.meta.env.SSR ? null : MyCanvasComponent;
</script>

<div>
<p>This is my fancy server side rendered (or prerendered) page.</p>

<!-- Use your dynamically imported svelte-konva canvas component with a svelte:component block, you can pass any component props as usual -->
<svelte:component this={MyCanvas} someProp="SomeString" />
</div>
+ +

Currently vite-plugin-iso-import cannot automatically fix intellisense inside .svelte files with TypeScript. Consult the README for a workaround to this problem. Or have a look at the demo below.

+

Instructions: Each page available in this SvelteKit App is rendered differently containing a svelte-konva canvas. Both dynamic import approaches are shown. Dynamic loading using onMount() on the prerendered page and dynamic loading with vite-plugin-iso-import on the SSR page. Try to inspect the network requests made on each navigation to understand the different approaches of rendering in SvelteKit.

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/svelte/Transformer.html b/docs/svelte/Transformer.html new file mode 100644 index 000000000..a6caa0bec --- /dev/null +++ b/docs/svelte/Transformer.html @@ -0,0 +1,537 @@ + + + + + + How to resize and rotate canvas shapes with Svelte and Konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to resize and rotate canvas shapes with Svelte and Konva?

+ +
+ + + + + + + + +
+
+ +
+
+ + +
+ + + + +

You can use the transformer tool by using the svelte-konva transformer component. Generally this approach requires some interfacing with the native Konva API. You can attach shapes to the transformer by manually attaching their handles to the transformer using the nodes() function. svelte-konva also automatically keeps your config in sync with the Konva node on transformend. See the bindings doc page for more details.

+

For a more detailed example with select & transform functionality see the example in the svelte-konva repo.

+

Instructions: click on shape to select it.

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/svelte/index.html b/docs/svelte/index.html new file mode 100644 index 000000000..8c35b334e --- /dev/null +++ b/docs/svelte/index.html @@ -0,0 +1,543 @@ + + + + + + Getting started with Svelte and canvas via Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Getting started with Svelte and canvas via Konva

+ +
+ + + + + + + + +
+
+ +
+
+ + +
+ + + + +

How to use canvas with Svelte?

svelte-konva is a JavaScript library for drawing complex canvas graphics using Svelte.

+

GitHub: https://github.com/konvajs/svelte-konva

+

It provides declarative and reactive bindings to the Konva Framework.

+

All svelte-konva components correspond to Konva components of the same name. All the parameters available for Konva objects can be added as config prop for corresponding svalte-konva components.

+

To get more info about Konva you can read Konva Overview.

+

Quick Start

1 Install via npm

npm i svelte-konva konva
+ +

2 Import and use svelte konva components

<script>
import { Stage, Layer, Rect } from 'svelte-konva';
</script>

<Stage config={{ width: window.innerWidth, height: window.innerHeight }}>
<Layer>
<Rect config={{ x: 100, y: 100, width: 400, height: 200, fill: 'blue' }} />
</Layer>
</Stage>
+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/svelte/zIndex.html b/docs/svelte/zIndex.html new file mode 100644 index 000000000..146dedebc --- /dev/null +++ b/docs/svelte/zIndex.html @@ -0,0 +1,540 @@ + + + + + + How to change the zIndex of nodes with svelte-konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to change the zIndex of nodes with svelte-konva?

+ +
+ + + + + + + + +
+
+ +
+
+ + +
+ + + + +

When working with other Konva-Wrappers like vue-konva or react-konva you might be used to the data order representing the drawing order of the components on the canvas. In svelte-konva such a functionality is currently not implemented as it is not possible to implement in Svelte 3 right now.

+

Instead you should use the Konva native functions to perform dynamic reordering of components on the canvas like node.zIndex(5), node.moveToTop(), etc. Tutorial.

+

Using if-blocks

svelte-konva will follow the initial ordering of the components to draw the shapes on the canvas. This works fine in cases where you do not need to change the ordering dynamically during runtime. When using Svelte if-blocks to show/hide certain components you should know the following caveat. Consider the following example:

+
<Stage bind:config={stageConfig}>
<Layer>
<Rect bind:config={rectConfig} />
{#if showRing}
<Ring bind:config={ringConfig}/>
{/if}
<Circle bind:config={circleConfig} />
</Layer>
</Stage>
+

Based on the ordering one would expect to see the circle drawn on the top of the canvas, followed by the ring and then the rect shapes. However, due to the if-block the ring might end up at the top of the canvas depending on the initial value and changes of showRing. This is caused by Svelte mounting/unmounting components inside if-blocks and svelte-konva drawing the shapes during mounting at the top of the canvas. If you want to avoid this behavior you should avoid Svelte if-blocks and use the visible config property to control whether a shape is visible or not. This way the component is not mounted/unmounted and maintains its initial drawing order on the canvas.

+

Instructions: Try to drag a circle. See how it goes to the top. This is done by calling moveToTop() on the dragged shape handle.

+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/tools.html b/docs/tools.html new file mode 100644 index 000000000..912299ae0 --- /dev/null +++ b/docs/tools.html @@ -0,0 +1,727 @@ + + + + + + Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

title: Konva.js Tools and Plugins

+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/tweens/All_Controls.html b/docs/tweens/All_Controls.html new file mode 100644 index 000000000..ca8c4a139 --- /dev/null +++ b/docs/tweens/All_Controls.html @@ -0,0 +1,723 @@ + + + + + + HTML5 Canvas All Tween Controls Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas All Tween Controls Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To play, pause, reverse, reset, finish, and seek tweens with Konva,
we can use the play(), pause(), reverse(), reset(), finish(), and seek() methods.
This tutorial demonstrates each control.

+ + +
All Tween Controlsview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva All Controls Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
#buttons {
position: absolute;
top: 5px;
left: 10px;
}
#buttons > input {
padding: 10px;
display: inline-block;
margin-right: 5px;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="buttons">
<input type="button" id="play" value="Play" />
<input type="button" id="pause" value="Pause" />
<input type="button" id="reverse" value="Reverse" />
<input type="button" id="reset" value="Reset" />
<input type="button" id="seek" value="Seek 3" />
<input type="button" id="finish" value="Finish" />
</div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var rect = new Konva.Rect({
x: 50,
y: 130,
width: 100,
height: 50,
fill: 'green',
stroke: 'black',
strokeWidth: 2,
opacity: 0.2,
});

layer.add(rect);
stage.add(layer);

// the tween has to be created after the node has been added to the layer
var tween = new Konva.Tween({
node: rect,
duration: 6,
x: 220,
y: 75,
rotation: Math.PI * 10,
opacity: 1,
strokeWidth: 6,
scaleX: 1.3,
scaleY: 1.3,
easing: Konva.Easings.Linear,
fillR: 0,
fillG: 0,
fillB: 255,
});

// pause tween
document.getElementById('pause').addEventListener(
'click',
function () {
tween.pause();
},
false
);

// reverse tween
document.getElementById('reverse').addEventListener(
'click',
function () {
tween.reverse();
},
false
);

// play tween forward
document.getElementById('play').addEventListener(
'click',
function () {
tween.play();
},
false
);

// reset tween
document.getElementById('reset').addEventListener(
'click',
function () {
tween.reset();
},
false
);

// force tween to finish
document.getElementById('finish').addEventListener(
'click',
function () {
tween.finish();
},
false
);

// seek to 3 seconds
document.getElementById('seek').addEventListener(
'click',
function () {
tween.seek(3);
},
false
);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/tweens/All_Easings.html b/docs/tweens/All_Easings.html new file mode 100644 index 000000000..f905a4a98 --- /dev/null +++ b/docs/tweens/All_Easings.html @@ -0,0 +1,725 @@ + + + + + + More Easing Functions Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

More Easing Functions Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

This tutorial demonstrates all of the easing function sets provided by Konva,
including Linear, Ease, Back, Elastic, Bounce, and Strong.

+

For all available easings go to Easings Documentation.

+

Instructions: Press “Play” to transition all of the text nodes.

+ + +
More Easing Functions Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva All Easings Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
#buttons {
position: absolute;
top: 10px;
left: 10px;
}
#buttons > input {
padding: 10px;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="buttons">
<input type="button" id="play" value="Play" />
<input type="button" id="pause" value="Pause" />
<input type="button" id="reverse" value="Reverse" />
</div>
<script>
var width = window.innerWidth;
var height = 707;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var easings = [
{ name: 'Linear', color: 'blue' },
{ name: 'EaseIn', color: 'green' },
{ name: 'EaseOut', color: 'green' },
{ name: 'EaseInOut', color: 'green' },
{ name: 'BackEaseIn', color: 'blue' },
{ name: 'BackEaseOut', color: 'blue' },
{ name: 'BackEaseInOut', color: 'blue' },
{ name: 'ElasticEaseIn', color: 'green' },
{ name: 'ElasticEaseOut', color: 'green' },
{ name: 'ElasticEaseInOut', color: 'green' },
{ name: 'BounceEaseIn', color: 'blue' },
{ name: 'BounceEaseOut', color: 'blue' },
{ name: 'BounceEaseInOut', color: 'blue' },
{ name: 'StrongEaseIn', color: 'green' },
{ name: 'StrongEaseOut', color: 'green' },
{ name: 'StrongEaseInOut', color: 'green' },
];

var tweens = [];

for (var n = 0; n < easings.length; n++) {
var num = n + 1;
var ease = easings[n];
var text = new Konva.Text({
x: 10,
y: 60 + (n * 400) / easings.length,
padding: 4,
text: num + ') ' + ease.name,
fontSize: 18,
fontFamily: 'Calibri',
fill: ease.color,
});

layer.add(text);

// the tween has to be created after the node has been added to the layer
var tween = new Konva.Tween({
node: text,
x: 280,
easing: Konva.Easings[ease.name],
duration: 2,
});

// add tween to tweens array
tweens.push(tween);
}

stage.add(layer);

// play
document.getElementById('play').addEventListener(
'click',
function () {
for (var n = 0; n < tweens.length; n++) {
tweens[n].play();
}
},
false
);

// pause
document.getElementById('pause').addEventListener(
'click',
function () {
for (var n = 0; n < tweens.length; n++) {
tweens[n].pause();
}
},
false
);

// reverse
document.getElementById('reverse').addEventListener(
'click',
function () {
for (var n = 0; n < tweens.length; n++) {
tweens[n].reverse();
}
},
false
);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/tweens/Common_Easings.html b/docs/tweens/Common_Easings.html new file mode 100644 index 000000000..66d8eb0f4 --- /dev/null +++ b/docs/tweens/Common_Easings.html @@ -0,0 +1,725 @@ + + + + + + Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

title: HTML5 Canvas Simple Easings Tutorial

To create a non linear easing tween with Konva, we can set the easing
property to an easing function. Other than Konva.Easings.Linear,
the other most common easings are Konva.Easings.EaseIn,
Konva.Easings.EaseInOut, and Konva.Easings.EaseOut.

+

For all available easings go to Easings Documentation.

+

Instructions: Mouseover or touchstart the boxes to tween them with different easing functions

+ + +
Konva Simple Easings Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Common Easing Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var greenBox = new Konva.Rect({
x: 70,
y: stage.height() / 2,
width: 100,
height: 50,
fill: 'green',
stroke: 'black',
strokeWidth: 4,
offset: {
x: 50,
y: 25,
},
});

var blueBox = new Konva.Rect({
x: 190,
y: stage.height() / 2,
width: 100,
height: 50,
fill: 'blue',
stroke: 'black',
strokeWidth: 4,
offset: {
x: 50,
y: 25,
},
});

var redBox = new Konva.Rect({
x: 310,
y: stage.height() / 2,
width: 100,
height: 50,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
offset: {
x: 50,
y: 25,
},
});

layer.add(greenBox);
layer.add(blueBox);
layer.add(redBox);
stage.add(layer);

// the tween has to be created after the node has been added to the layer
greenBox.tween = new Konva.Tween({
node: greenBox,
scaleX: 2,
scaleY: 1.5,
easing: Konva.Easings.EaseIn,
duration: 1,
});

blueBox.tween = new Konva.Tween({
node: blueBox,
scaleX: 2,
scaleY: 1.5,
easing: Konva.Easings.EaseInOut,
duration: 1,
});

redBox.tween = new Konva.Tween({
node: redBox,
scaleX: 2,
scaleY: 1.5,
easing: Konva.Easings.EaseOut,
duration: 1,
});

// use event delegation
layer.on('mouseover touchstart', function (evt) {
evt.target.tween.play();
});

layer.on('mouseout touchend', function (evt) {
evt.target.tween.reverse();
});
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/tweens/Complex_Tweening.html b/docs/tweens/Complex_Tweening.html new file mode 100644 index 000000000..b96d1d334 --- /dev/null +++ b/docs/tweens/Complex_Tweening.html @@ -0,0 +1,725 @@ + + + + + + HTML5 Canvas Complex Tweening Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Complex Tweening Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

Also you can use GreenSock Konva Plugin for tweens.

+

GreenSock tweens are more powerfull than Konva’s tween.

+

Also demo demonstrate tweening fillLinearGradientColorStops property with usual GreenSock usage.

+ + +
Konva Complex Tweening Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<script src="https://rawgit.com/konvajs/greensock-plugin/master/KonvaPlugin.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenLite.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TimelineLite.min.js"></script>
<script src="https://www.snorkl.tv/dev/libs/greensock/plugins/ColorPropsPlugin.min.js"></script>
<meta charset="utf-8" />
<title>Konva Complex Tweening Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>

<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var star = new Konva.Star({
x: 100,
y: 250,
numPoints: 5,
innerRadius: 40,
outerRadius: 70,
fill: 'red',
});

layer.add(star);
stage.add(layer);

var tl = new TimelineLite();

// plugin example
tl.to(star, 2, {
konva: {
x: 300,
y: 130,
innerRadius: 15,
rotation: 360,
},
ease: Power4.easeOut,
})
.to(star, 2, {
konva: {
fill: 'rgb(0,0,255)',
scaleX: 1.5,
scaleY: 1.5,
},
})
.to(star, 1, {
konva: {
fill: '#0F0',
scaleX: 3,
scaleY: 1,
shadowOffsetX: 10,
shadowOffsetY: 10,
shadowBlur: 10,
shadowColor: 'black',
rotation: 0,
},
});

var linearGradPentagon = new Konva.RegularPolygon({
x: 70,
y: 70,
sides: 5,
radius: 70,
fillLinearGradientStartPoint: {
x: -50,
y: -50,
},
fillLinearGradientEndPoint: {
x: 50,
y: 50,
},
fillLinearGradientColorStops: [0, 'red', 1, 'yellow'],
stroke: 'black',
strokeWidth: 4,
draggable: true,
});

layer.add(linearGradPentagon);
linearGradPentagon.moveToBottom();

//activate ColorPropsPlugin
TweenPlugin.activate([ColorPropsPlugin]);

//object to store color values
var tmpColors = {
color0: 'white',
color1: 'black',
};

//tween the color values in myObject
TweenLite.to(tmpColors, 5, {
colorProps: {
color0: 'black',
color1: 'red',
},
yoyo: true,
repeat: 5,
ease: Linear.easeNone,
onUpdate: applyProps,
});

//apply new color values to gradient css of target
function applyProps() {
linearGradPentagon.setAttrs({
fillLinearGradientColorStops: [
0,
tmpColors.color0,
1,
tmpColors.color1,
],
});
}
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/tweens/Finish_Event.html b/docs/tweens/Finish_Event.html new file mode 100644 index 000000000..167d9d705 --- /dev/null +++ b/docs/tweens/Finish_Event.html @@ -0,0 +1,723 @@ + + + + + + HTML5 Canvas Tween Finish Event Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Tween Finish Event Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To trigger a user defined function when the tween finishes with Konva, we can set the onFinish property.

+ + +
Konva Tween Finish Event Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Finish Event Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
function writeMessage(message) {
text.text(message);
}

var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var text = new Konva.Text({
x: 10,
y: 10,
fontFamily: 'Calibri',
fontSize: 24,
text: '',
fill: 'black',
});

var wheel = new Konva.Star({
x: stage.width() / 2,
y: stage.height() / 2,
numPoints: 8,
outerRadius: 70,
innerRadius: 50,
fill: 'purple',
stroke: 'black',
strokeWidth: 5,
lineJoin: 'bevel',
});

layer.add(wheel);
layer.add(text);
stage.add(layer);

// the tween has to be created after the node has been added to the layer
var tween = new Konva.Tween({
node: wheel,
duration: 4,
rotation: 360,
easing: Konva.Easings.BackEaseOut,
onFinish: function () {
writeMessage('tween finished!');
},
});

setTimeout(function () {
tween.play();
}, 1000);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/tweens/Linear_Easing.html b/docs/tweens/Linear_Easing.html new file mode 100644 index 000000000..f63896fd0 --- /dev/null +++ b/docs/tweens/Linear_Easing.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Tweening Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Tweening Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To tween properties with Konva, we can instantiate a Konva.Tween object
and then start the tween by calling play(). Any numeric property of a Shape,
Group, Layer, or Stage can be transitioned, such as x, y, rotation,
width, height, radius, strokeWidth, opacity, scaleX, offsetX, etc.

+

For a full list of attributes and methods, check out the Konva.Tween documentation.

+ + +
Konva Tweening Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Linear Easing Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var rect = new Konva.Rect({
x: 50,
y: 20,
width: 100,
height: 50,
fill: 'green',
stroke: 'black',
strokeWidth: 2,
opacity: 0.2,
});

layer.add(rect);
stage.add(layer);

// the tween has to be created after the node has been added to the layer
var tween = new Konva.Tween({
node: rect,
duration: 1,
x: 140,
y: 90,
fill: 'red',
rotation: Math.PI * 2,
opacity: 1,
strokeWidth: 6,
scaleX: 1.5,
});

// start tween after 2 seconds
setTimeout(function () {
tween.play();
}, 2000);
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/tweens/Tween_Filter.html b/docs/tweens/Tween_Filter.html new file mode 100644 index 000000000..69bab0847 --- /dev/null +++ b/docs/tweens/Tween_Filter.html @@ -0,0 +1,724 @@ + + + + + + HTML5 Canvas Tween Blur Filter Tutorial | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

HTML5 Canvas Tween Blur Filter Tutorial

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +

To tween a filter using Konva, we can simply tween the properties associated with the filter.
In this tutorial, we’ll tween the blurRadius property, which controls the amount of blur applied to the image.

+

Instructions: mouseover the image to focus it.

+ + +
Konva Tween Blur Filter Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@9.3.15/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Tween Filter Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

var layer = new Konva.Layer();

var lion = new Konva.Image({
x: 80,
y: 30,
draggable: true,
});
layer.add(lion);
stage.add(layer);

var image = new Image();
image.onload = function () {
lion.image(image);
lion.cache();
lion.filters([Konva.Filters.Blur]);
lion.blurRadius(10);

// the tween has to be created after the node has been added to the layer
var tween = new Konva.Tween({
node: lion,
duration: 0.6,
blurRadius: 0,
easing: Konva.Easings.EaseInOut,
});

lion.on('mouseover', function () {
tween.play();
});

lion.on('mouseout', function () {
tween.reverse();
});
};
image.src = '/assets/lion.png';
</script>
</body>
</html>
+
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/vue/Cache.html b/docs/vue/Cache.html new file mode 100644 index 000000000..ea7ff11d0 --- /dev/null +++ b/docs/vue/Cache.html @@ -0,0 +1,482 @@ + + + + + + How to cache canvas shapes with Vue | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to cache canvas shapes with Vue

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

If you want to cache a node in vue app, you need to have an access to Konva node and use node.cache() function.

+

To get an access to a node you can use references and component.getNode() method:

+

Instruction: try to drag whole stage. Then try again with cached group.

+

You should see much better performance.

+
// in template:
<v-group ref="group">
// later in the code:
this.$refs.group.getNode().cache();
+ + + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/vue/Custom_Shape.html b/docs/vue/Custom_Shape.html new file mode 100644 index 000000000..05b4ea803 --- /dev/null +++ b/docs/vue/Custom_Shape.html @@ -0,0 +1,479 @@ + + + + + + How to draw custom canvas shape with Vue? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to draw custom canvas shape with Vue?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

To create a custom shape with vue-konva, we should use v-shape component.

+

When creating a custom shape, we need to define a drawing function that is passed a Konva.Canvas renderer.

+

We can use the renderer to access the HTML5 Canvas context, and to use special methods like context.fillStrokeShape(shape) which automatically handles filling, stroking, and applying shadows.

+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/vue/Drag_And_Drop.html b/docs/vue/Drag_And_Drop.html new file mode 100644 index 000000000..f9d9e81b5 --- /dev/null +++ b/docs/vue/Drag_And_Drop.html @@ -0,0 +1,478 @@ + + + + + + Drag and drop canvas shapes with vue | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Drag and drop canvas shapes with vue

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

To enable drag&drop for any node on canvas you just need to pass draggable: true property into the component.

+

When you drag&drop shape it is recommended to save its position into you app store. You can use dragmove and dragend events for that purpose.

+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/vue/Events.html b/docs/vue/Events.html new file mode 100644 index 000000000..0b59f8dde --- /dev/null +++ b/docs/vue/Events.html @@ -0,0 +1,478 @@ + + + + + + How to listen to an event on a canvas shape with Vue and Konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to listen to an event on a canvas shape with Vue and Konva?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

With vue-konva you can easily listen to user input events (click, dblclick, mouseover, tap, dbltap, touchstart, etc…) and drag&drop events (dragstart, dragmove, dragend).

+

For the full list of events take a look into on() method documentation.

+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/vue/Filters.html b/docs/vue/Filters.html new file mode 100644 index 000000000..9e4c78628 --- /dev/null +++ b/docs/vue/Filters.html @@ -0,0 +1,478 @@ + + + + + + How to apply canvas filters with vue and konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to apply canvas filters with vue and konva?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

To apply filters you need to cache Konva.Node manually. You can do it created() method.
Probably you will need to recache nodes every time you update their styles in updated().

+

Instructions: click on the rectangle to see changes

+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/vue/Images.html b/docs/vue/Images.html new file mode 100644 index 000000000..dc37701a9 --- /dev/null +++ b/docs/vue/Images.html @@ -0,0 +1,477 @@ + + + + + + How to draw image on canvas with Vue? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to draw image on canvas with Vue?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

For images you need manually create native window.Image instance or canvas element and use it as image attribute of v-image component.

+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/vue/Save-Load.html b/docs/vue/Save-Load.html new file mode 100644 index 000000000..addac2329 --- /dev/null +++ b/docs/vue/Save-Load.html @@ -0,0 +1,478 @@ + + + + + + Saving and loading canvas with Vue and Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Saving and loading canvas with Vue and Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to serialize and deserialize Konva stage with Vue?

Pure Konva has special mechanizm to save/load full canvas stage with node.toJSON() and Node.create(json) functions.
See demo.

+

But we don’t recommend to use these methods if you are using vue-konva. In vue-konva you should have a state of the app defined in your vue components. That state maps into nodes with templates. To save/load full stage you just need to save/load state of the app and you don’t need to save Konva internals and nodes.

+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/vue/Shapes.html b/docs/vue/Shapes.html new file mode 100644 index 000000000..f92584692 --- /dev/null +++ b/docs/vue/Shapes.html @@ -0,0 +1,479 @@ + + + + + + Drawing canvas shapes with Vue | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Drawing canvas shapes with Vue

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

All vue-konva components correspond to Konva components of the same name with the prefix ‘v-‘. All the parameters available for Konva objects can add as config in the prop for corresponding vue-konva components.

+

Core shapes are: v-rect, v-circle, v-ellipse, v-line, v-image, v-text, v-text-path, v-star, v-label, v-path, v-regular-polygon. Also you can create custom shape.

+

To get more info about Konva you can read Konva Overview.

+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/vue/Simple_Animations.html b/docs/vue/Simple_Animations.html new file mode 100644 index 000000000..e04255f79 --- /dev/null +++ b/docs/vue/Simple_Animations.html @@ -0,0 +1,479 @@ + + + + + + How to apply canvas animations with vue and konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to apply canvas animations with vue and konva?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Konva itself has two methods for animations Tween and Animation. You can apply both of them to nodes manually.

+

For simple use cases we recommend to use node.to() method.

+

Instructions: Try to move a rectangle.

+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/vue/Transformer.html b/docs/vue/Transformer.html new file mode 100644 index 000000000..42b69e82b --- /dev/null +++ b/docs/vue/Transformer.html @@ -0,0 +1,479 @@ + + + + + + How to resize and rotate canvas shapes with vue and konva? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to resize and rotate canvas shapes with vue and konva?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

Currently there is no good pure declarative “vue-way” to use Transformer tool.
But you still can use it with some small manual requests to the Konva nodes.
And it will work just fine.

+

Idea: you need to create Konva.Transformer node, and attach it into required node manually.

+

Instructions: click on shape to select it.

+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/vue/index.html b/docs/vue/index.html new file mode 100644 index 000000000..bcf302f80 --- /dev/null +++ b/docs/vue/index.html @@ -0,0 +1,501 @@ + + + + + + Getting started with vue and canvas via Konva | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Getting started with vue and canvas via Konva

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to use canvas with Vue?

VueKonva Logo

+

Vue Konva is a JavaScript library for drawing complex canvas graphics using Vue.

+

It provides declarative and reactive bindings to the Konva Framework.

+

All vue-konva components correspond to Konva components of the same name with the prefix ‘v-‘. All the parameters available for Konva objects can add as config in the prop for corresponding vue-konva components.

+

Core shapes are: v-rect, v-circle, v-ellipse, v-line, v-image, v-text, v-text-path, v-star, v-label, v-path, v-regular-polygon.
Also you can create custom shape.

+

To get more info about Konva you can read Konva Overview.

+

Quick Start

Vue.js version 2.4+ is required.

+

1 Install via npm

vue@3:

+
npm install vue-konva konva --save
+ +

vue@2:

+
npm install vue-konva@2 konva --save
+ +

2 Import and use VueKonva

vue@3:

+
import { createApp } from 'vue';
import App from './App.vue';
import VueKonva from 'vue-konva';

const app = createApp(App);
app.use(VueKonva);
app.mount('#app');
+ +

vue@2:

+
import Vue from 'vue';
import VueKonva from 'vue-konva';

Vue.use(VueKonva);
+ +

3 Reference in your component templates

<template>
<v-stage :config="configKonva">
<v-layer>
<v-circle :config="configCircle"></v-circle>
</v-layer>
</v-stage>
</template>
+ +
<script>
export default {
data() {
return {
configKonva: {
width: 200,
height: 200
},
configCircle: {
x: 100,
y: 100,
radius: 70,
fill: "red",
stroke: "black",
strokeWidth: 4
}
};
}
};

</script>
+ + + +

Or use a CDN

<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta http-equiv="x-ua-compatible" content="ie=edge" />
</head>
<body>
<div id="app">
<v-stage ref="stage" :config="configKonva">
<v-layer ref="layer">
<v-circle :config="configCircle"></v-circle>
</v-layer>
</v-stage>
</div>
<!--1. Link Vue Javascript & Konva-->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/konva@9/konva.min.js"></script>
<!--2. Link VueKonva Javascript (Plugin automatically installed)-->
<script src="./lib/vue-konva.min.js"></script>
<script>
// 3. Create the Vue instance
new Vue({
el: '#app',
data: {
configKonva: {
width: 200,
height: 200,
},
configCircle: {
x: 100,
y: 100,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
},
},
});
</script>
</body>
</html>
+ +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/vue/zIndex.html b/docs/vue/zIndex.html new file mode 100644 index 000000000..89324568c --- /dev/null +++ b/docs/vue/zIndex.html @@ -0,0 +1,481 @@ + + + + + + How to change the zIndex of nodes with Vue? | Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

How to change the zIndex of nodes with Vue?

+ +
+ + + + + + + + +
+
+ +
+
+ +
+ + + + +
+

How to change the zIndex and reorder components in vue-konva?

When you are working with Konva directly you have many methods to change the order of nodes like node.zIndex(5), node.moveToTop(), etc. Tutorial.

+

But it is not recommended to use these methods when you are working with the vue framework.

+

vue-konva is trying to follow the order of the nodes exactly as you described them in your <template>. So instead of changing the zIndex manually, you just need to update the data of the app correctly, so the components inside your <template> maintain the correct order.

+

Don’t use the zIndex for your canvas components.

+

Instructions: Try to drag a circle. See how it goes to the top. We are doing this by manipulating the data of the app so that the circles inside the <template> maintain the correct order.

+ + +
+ +
+ Enjoying Konva? Please consider to + support the project. +
+ +
+
+ +
+
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/downloads/code/animations/Moving.html b/downloads/code/animations/Moving.html new file mode 100644 index 000000000..38fde8135 --- /dev/null +++ b/downloads/code/animations/Moving.html @@ -0,0 +1,57 @@ + + + + + + Konva Animate Position Demo + + + +
+ + + diff --git a/downloads/code/animations/Rotation.html b/downloads/code/animations/Rotation.html new file mode 100644 index 000000000..e4b4a72a0 --- /dev/null +++ b/downloads/code/animations/Rotation.html @@ -0,0 +1,100 @@ + + + + + + Konva Rotation Animation Demo + + + +
+ + + diff --git a/downloads/code/animations/Scaling.html b/downloads/code/animations/Scaling.html new file mode 100644 index 000000000..e6e3f90e0 --- /dev/null +++ b/downloads/code/animations/Scaling.html @@ -0,0 +1,96 @@ + + + + + + Konva Scale Animation Demo + + + +
+ + + diff --git a/downloads/code/animations/Stop_Animation.html b/downloads/code/animations/Stop_Animation.html new file mode 100644 index 000000000..6da27da24 --- /dev/null +++ b/downloads/code/animations/Stop_Animation.html @@ -0,0 +1,84 @@ + + + + + + Konva Stop Animation Demo + + + +
+
+ + +
+ + + diff --git a/downloads/code/clipping/Clipping_Function.html b/downloads/code/clipping/Clipping_Function.html new file mode 100644 index 000000000..0a384a6fc --- /dev/null +++ b/downloads/code/clipping/Clipping_Function.html @@ -0,0 +1,67 @@ + + + + + + Konva Clipping Function Demo + + + +
+ + + diff --git a/downloads/code/clipping/Clipping_Regions.html b/downloads/code/clipping/Clipping_Regions.html new file mode 100644 index 000000000..5d7692bcc --- /dev/null +++ b/downloads/code/clipping/Clipping_Regions.html @@ -0,0 +1,69 @@ + + + + + + Konva Simple Clipping Demo + + + +
+ + + diff --git a/downloads/code/data_and_serialization/Best_Practices.html b/downloads/code/data_and_serialization/Best_Practices.html new file mode 100644 index 000000000..226554236 --- /dev/null +++ b/downloads/code/data_and_serialization/Best_Practices.html @@ -0,0 +1,203 @@ + + + + + + Konva Load Complex Stage Demo + + + + + + + +
+ + + diff --git a/downloads/code/data_and_serialization/Complex_Load.html b/downloads/code/data_and_serialization/Complex_Load.html new file mode 100644 index 000000000..110623427 --- /dev/null +++ b/downloads/code/data_and_serialization/Complex_Load.html @@ -0,0 +1,41 @@ + + + + + + Konva Load Complex Stage Demo + + + +
+ + + diff --git a/downloads/code/data_and_serialization/High-Quality-Export.html b/downloads/code/data_and_serialization/High-Quality-Export.html new file mode 100644 index 000000000..bc4686b40 --- /dev/null +++ b/downloads/code/data_and_serialization/High-Quality-Export.html @@ -0,0 +1,89 @@ + + + + + + Konva High Quality Export Demo + + + + +
+
+ + + diff --git a/downloads/code/data_and_serialization/Serialize_a_Stage.html b/downloads/code/data_and_serialization/Serialize_a_Stage.html new file mode 100644 index 000000000..f0e0e7c04 --- /dev/null +++ b/downloads/code/data_and_serialization/Serialize_a_Stage.html @@ -0,0 +1,52 @@ + + + + + + Konva Save Stage Demo + + + +
+ + + diff --git a/downloads/code/data_and_serialization/Simple_Load.html b/downloads/code/data_and_serialization/Simple_Load.html new file mode 100644 index 000000000..a9b4d0e7f --- /dev/null +++ b/downloads/code/data_and_serialization/Simple_Load.html @@ -0,0 +1,26 @@ + + + + + + Konva Simple Load Demo + + + +
+ + + diff --git a/downloads/code/data_and_serialization/Stage_Data_URL.html b/downloads/code/data_and_serialization/Stage_Data_URL.html new file mode 100644 index 000000000..0e6c5a29d --- /dev/null +++ b/downloads/code/data_and_serialization/Stage_Data_URL.html @@ -0,0 +1,92 @@ + + + + + + Konva Stage Data URL Demo + + + + +
+
+ +
+ + + diff --git a/downloads/code/drag_and_drop/Complex_Drag_and_Drop.html b/downloads/code/drag_and_drop/Complex_Drag_and_Drop.html new file mode 100644 index 000000000..1b5e8c466 --- /dev/null +++ b/downloads/code/drag_and_drop/Complex_Drag_and_Drop.html @@ -0,0 +1,104 @@ + + + + + + Konva Complex Drag and Drop Bounds Demo + + + +
+ + + diff --git a/downloads/code/drag_and_drop/Drag_Events.html b/downloads/code/drag_and_drop/Drag_Events.html new file mode 100644 index 000000000..09fbe73be --- /dev/null +++ b/downloads/code/drag_and_drop/Drag_Events.html @@ -0,0 +1,69 @@ + + + + + + Konva Drag Events Demo + + + +
+ + + diff --git a/downloads/code/drag_and_drop/Drag_a_Group.html b/downloads/code/drag_and_drop/Drag_a_Group.html new file mode 100644 index 000000000..09c724bf6 --- /dev/null +++ b/downloads/code/drag_and_drop/Drag_a_Group.html @@ -0,0 +1,59 @@ + + + + + + Konva Drag and Drop a Group Demo + + + +
+ + + diff --git a/downloads/code/drag_and_drop/Drag_a_Line.html b/downloads/code/drag_and_drop/Drag_a_Line.html new file mode 100644 index 000000000..ca69b4eac --- /dev/null +++ b/downloads/code/drag_and_drop/Drag_a_Line.html @@ -0,0 +1,51 @@ + + + + + + Konva Drag and Drop a Line Demo + + + +
+ + + diff --git a/downloads/code/drag_and_drop/Drag_a_Stage.html b/downloads/code/drag_and_drop/Drag_a_Stage.html new file mode 100644 index 000000000..0abf9bfa7 --- /dev/null +++ b/downloads/code/drag_and_drop/Drag_a_Stage.html @@ -0,0 +1,47 @@ + + + + + + Konva Drag and Drop the Stage Demo + + + +
+ + + diff --git a/downloads/code/drag_and_drop/Drag_an_Image.html b/downloads/code/drag_and_drop/Drag_an_Image.html new file mode 100644 index 000000000..6ff253ea9 --- /dev/null +++ b/downloads/code/drag_and_drop/Drag_an_Image.html @@ -0,0 +1,58 @@ + + + + + + Konva Drag and Drop an Image Demo + + + +
+ + + diff --git a/downloads/code/drag_and_drop/Drag_and_Drop.html b/downloads/code/drag_and_drop/Drag_and_Drop.html new file mode 100644 index 000000000..ef5cd5a22 --- /dev/null +++ b/downloads/code/drag_and_drop/Drag_and_Drop.html @@ -0,0 +1,55 @@ + + + + + + Konva Drag and Drop Demo + + + +
+ + + diff --git a/downloads/code/drag_and_drop/Drop_Events.html b/downloads/code/drag_and_drop/Drop_Events.html new file mode 100644 index 000000000..369383a7d --- /dev/null +++ b/downloads/code/drag_and_drop/Drop_Events.html @@ -0,0 +1,152 @@ + + + + + + Konva Drop Events Demo + + + +
+ + + diff --git a/downloads/code/drag_and_drop/Simple_Drag_Bounds.html b/downloads/code/drag_and_drop/Simple_Drag_Bounds.html new file mode 100644 index 000000000..7f6bb8e4a --- /dev/null +++ b/downloads/code/drag_and_drop/Simple_Drag_Bounds.html @@ -0,0 +1,78 @@ + + + + + + Konva Simple Drag Bounds Demo + + + +
+ + + diff --git a/downloads/code/events/Binding_Events.html b/downloads/code/events/Binding_Events.html new file mode 100644 index 000000000..2c964d37a --- /dev/null +++ b/downloads/code/events/Binding_Events.html @@ -0,0 +1,90 @@ + + + + + + Konva Shape Events Demo + + + + +
+ + + diff --git a/downloads/code/events/Cancel_Propagation.html b/downloads/code/events/Cancel_Propagation.html new file mode 100644 index 000000000..543713d53 --- /dev/null +++ b/downloads/code/events/Cancel_Propagation.html @@ -0,0 +1,59 @@ + + + + + + Konva Cancel Event Bubble Propagation Demo + + + + +
+ + + diff --git a/downloads/code/events/Custom_Hit_Region.html b/downloads/code/events/Custom_Hit_Region.html new file mode 100644 index 000000000..79b55f966 --- /dev/null +++ b/downloads/code/events/Custom_Hit_Region.html @@ -0,0 +1,108 @@ + + + + + + Konva Custom Hit Function Demo + + + + + +
+ + + diff --git a/downloads/code/events/Desktop_and_Mobile.html b/downloads/code/events/Desktop_and_Mobile.html new file mode 100644 index 000000000..64927703b --- /dev/null +++ b/downloads/code/events/Desktop_and_Mobile.html @@ -0,0 +1,74 @@ + + + + + + Konva Desktop and Mobile Events Support Demo + + + + +
+ + + diff --git a/downloads/code/events/Event_Delegation.html b/downloads/code/events/Event_Delegation.html new file mode 100644 index 000000000..8db10bf36 --- /dev/null +++ b/downloads/code/events/Event_Delegation.html @@ -0,0 +1,54 @@ + + + + + + Konva Event Delegation Demo + + + + +
+ + + diff --git a/downloads/code/events/Fire_Events.html b/downloads/code/events/Fire_Events.html new file mode 100644 index 000000000..9220e501a --- /dev/null +++ b/downloads/code/events/Fire_Events.html @@ -0,0 +1,57 @@ + + + + + + Konva Fire Event Demo + + + + +
+ + + diff --git a/downloads/code/events/Image_Events.html b/downloads/code/events/Image_Events.html new file mode 100644 index 000000000..9b17501a3 --- /dev/null +++ b/downloads/code/events/Image_Events.html @@ -0,0 +1,101 @@ + + + + + + Konva Image Events Demo + + + +
+ + + diff --git a/downloads/code/events/Keyboard_Events.html b/downloads/code/events/Keyboard_Events.html new file mode 100644 index 000000000..ac391cf46 --- /dev/null +++ b/downloads/code/events/Keyboard_Events.html @@ -0,0 +1,67 @@ + + + + + + Canvas Keyboard events Demo + + + + +
+ + + diff --git a/downloads/code/events/Listen_for_Events.html b/downloads/code/events/Listen_for_Events.html new file mode 100644 index 000000000..ffafd068d --- /dev/null +++ b/downloads/code/events/Listen_for_Events.html @@ -0,0 +1,93 @@ + + + + + + Konva Listen or Don’t Listen to Events Demo + + + + +
+
+ + +
+ + + diff --git a/downloads/code/events/Mobile_Events.html b/downloads/code/events/Mobile_Events.html new file mode 100644 index 000000000..8dd4f823f --- /dev/null +++ b/downloads/code/events/Mobile_Events.html @@ -0,0 +1,82 @@ + + + + + + Konva Mobile Touch Events Demo + + + + +
+ + + diff --git a/downloads/code/events/Mobile_Scrolling.html b/downloads/code/events/Mobile_Scrolling.html new file mode 100644 index 000000000..17d0941fe --- /dev/null +++ b/downloads/code/events/Mobile_Scrolling.html @@ -0,0 +1,52 @@ + + + + + + Konva Mobile Scrolling and Native Events Demo + + + +
+ + + diff --git a/downloads/code/events/Multi_Event.html b/downloads/code/events/Multi_Event.html new file mode 100644 index 000000000..9897d69bb --- /dev/null +++ b/downloads/code/events/Multi_Event.html @@ -0,0 +1,66 @@ + + + + + + Konva Multi-Event Binding Demo + + + + +
+ + + diff --git a/downloads/code/events/Pointer_Events.html b/downloads/code/events/Pointer_Events.html new file mode 100644 index 000000000..f1d56aad1 --- /dev/null +++ b/downloads/code/events/Pointer_Events.html @@ -0,0 +1,86 @@ + + + + + + Konva Pointer Events Demo + + + + +
+ + + diff --git a/downloads/code/events/Remove_Event.html b/downloads/code/events/Remove_Event.html new file mode 100644 index 000000000..e5be67ed6 --- /dev/null +++ b/downloads/code/events/Remove_Event.html @@ -0,0 +1,67 @@ + + + + + + Konva Remove Event Listener Demo + + + + +
+
+ +
+ + + diff --git a/downloads/code/events/Remove_by_Name.html b/downloads/code/events/Remove_by_Name.html new file mode 100644 index 000000000..fd480571d --- /dev/null +++ b/downloads/code/events/Remove_by_Name.html @@ -0,0 +1,90 @@ + + + + + + Konva Remove Event Listener by Name Demo + + + + +
+
+ + + +
+ + + diff --git a/downloads/code/events/Stage_Events.html b/downloads/code/events/Stage_Events.html new file mode 100644 index 000000000..c32f96f2a --- /dev/null +++ b/downloads/code/events/Stage_Events.html @@ -0,0 +1,49 @@ + + + + + + Konva Stage Events Demo + + + + +
+ + + diff --git a/downloads/code/filters/Blur.html b/downloads/code/filters/Blur.html new file mode 100644 index 000000000..7ae0c1e49 --- /dev/null +++ b/downloads/code/filters/Blur.html @@ -0,0 +1,78 @@ + + + + + + Konva Blur Image Demo + + + + +
+ + + + diff --git a/downloads/code/filters/Brighten.html b/downloads/code/filters/Brighten.html new file mode 100644 index 000000000..daf198ff9 --- /dev/null +++ b/downloads/code/filters/Brighten.html @@ -0,0 +1,77 @@ + + + + + + Konva Brighten Image Demo + + + + +
+ + + + diff --git a/downloads/code/filters/Contrast.html b/downloads/code/filters/Contrast.html new file mode 100644 index 000000000..191373a53 --- /dev/null +++ b/downloads/code/filters/Contrast.html @@ -0,0 +1,67 @@ + + + + + + Konva Contrast Image Demo + + + + +
+
+ contrast: + +
+ + + diff --git a/downloads/code/filters/Custom_Filter.html b/downloads/code/filters/Custom_Filter.html new file mode 100644 index 000000000..709bf0278 --- /dev/null +++ b/downloads/code/filters/Custom_Filter.html @@ -0,0 +1,52 @@ + + + + + + Konva Custom Filter Demo + + + + +
+ + + diff --git a/downloads/code/filters/Emboss.html b/downloads/code/filters/Emboss.html new file mode 100644 index 000000000..3ac966cb6 --- /dev/null +++ b/downloads/code/filters/Emboss.html @@ -0,0 +1,97 @@ + + + + + + Konva Emboss Image Demo + + + + +
+
+ Strength: + + WhiteLevel: + + Direction: + + Blend: + +
+ + + diff --git a/downloads/code/filters/Enhance.html b/downloads/code/filters/Enhance.html new file mode 100644 index 000000000..7877d0628 --- /dev/null +++ b/downloads/code/filters/Enhance.html @@ -0,0 +1,54 @@ + + + + + + Konva Enhance Image Demo + + + + +
+ + + + diff --git a/downloads/code/filters/Grayscale.html b/downloads/code/filters/Grayscale.html new file mode 100644 index 000000000..04167f064 --- /dev/null +++ b/downloads/code/filters/Grayscale.html @@ -0,0 +1,66 @@ + + + + + + Konva Grayscale Image Demo + + + + +
+ + + diff --git a/downloads/code/filters/HSL.html b/downloads/code/filters/HSL.html new file mode 100644 index 000000000..5f05edc8a --- /dev/null +++ b/downloads/code/filters/HSL.html @@ -0,0 +1,78 @@ + + + + + + Konva HSL Image Demo + + + + +
+
+ hue: + + saturation: + + luminance: + +
+ + + diff --git a/downloads/code/filters/HSV.html b/downloads/code/filters/HSV.html new file mode 100644 index 000000000..cc50f7b84 --- /dev/null +++ b/downloads/code/filters/HSV.html @@ -0,0 +1,71 @@ + + + + + + Konva HSV Image Demo + + + + +
+
+ hue: + + saturation: + + value: + +
+ + + diff --git a/downloads/code/filters/Invert.html b/downloads/code/filters/Invert.html new file mode 100644 index 000000000..acedce425 --- /dev/null +++ b/downloads/code/filters/Invert.html @@ -0,0 +1,66 @@ + + + + + + Konva Invert Image Demo + + + + +
+ + + diff --git a/downloads/code/filters/Kaleidoscope.html b/downloads/code/filters/Kaleidoscope.html new file mode 100644 index 000000000..4a574c682 --- /dev/null +++ b/downloads/code/filters/Kaleidoscope.html @@ -0,0 +1,78 @@ + + + + + + Konva Kaleidoscope Image Demo + + + + +
+ + + + diff --git a/downloads/code/filters/Mask.html b/downloads/code/filters/Mask.html new file mode 100644 index 000000000..62c0b97ec --- /dev/null +++ b/downloads/code/filters/Mask.html @@ -0,0 +1,78 @@ + + + + + + Konva Mask Image Demo + + + + +
+ + + + diff --git a/downloads/code/filters/Multiple_Filters.html b/downloads/code/filters/Multiple_Filters.html new file mode 100644 index 000000000..8b19e08ff --- /dev/null +++ b/downloads/code/filters/Multiple_Filters.html @@ -0,0 +1,78 @@ + + + + + + Konva Multiple Filters Demo + + + + +
+ + + + diff --git a/downloads/code/filters/Noise.html b/downloads/code/filters/Noise.html new file mode 100644 index 000000000..f317570d8 --- /dev/null +++ b/downloads/code/filters/Noise.html @@ -0,0 +1,60 @@ + + + + + + Konva Noise Image Demo + + + + +
+
+ noise: + +
+ + + diff --git a/downloads/code/filters/Pixelate.html b/downloads/code/filters/Pixelate.html new file mode 100644 index 000000000..e9983886d --- /dev/null +++ b/downloads/code/filters/Pixelate.html @@ -0,0 +1,60 @@ + + + + + + Konva Pixelate Image Demo + + + + +
+
+ pixelSize: + +
+ + + diff --git a/downloads/code/filters/RGB.html b/downloads/code/filters/RGB.html new file mode 100644 index 000000000..38fdef2bf --- /dev/null +++ b/downloads/code/filters/RGB.html @@ -0,0 +1,64 @@ + + + + + + Konva RGB Image Demo + + + + +
+
+ Red: + + Green: + + Blue: + +
+ + + diff --git a/downloads/code/filters/RGBA.html b/downloads/code/filters/RGBA.html new file mode 100644 index 000000000..9fd7f6b64 --- /dev/null +++ b/downloads/code/filters/RGBA.html @@ -0,0 +1,66 @@ + + + + + + Konva RGBA Image Demo + + + + +
+
+ Red: + + Green: + + Blue: + + Alpha: + +
+ + + diff --git a/downloads/code/groups_and_layers/Change_Containers.html b/downloads/code/groups_and_layers/Change_Containers.html new file mode 100644 index 000000000..1c9fc7c4d --- /dev/null +++ b/downloads/code/groups_and_layers/Change_Containers.html @@ -0,0 +1,104 @@ + + + + + + Konva Move Shape to Another Container Demo + + + +
+
+ + +
+ + + diff --git a/downloads/code/groups_and_layers/Groups.html b/downloads/code/groups_and_layers/Groups.html new file mode 100644 index 000000000..7ab238ecf --- /dev/null +++ b/downloads/code/groups_and_layers/Groups.html @@ -0,0 +1,63 @@ + + + + + + Konva Groups Demo + + + +
+ + + diff --git a/downloads/code/groups_and_layers/Layering.html b/downloads/code/groups_and_layers/Layering.html new file mode 100644 index 000000000..d607a38e6 --- /dev/null +++ b/downloads/code/groups_and_layers/Layering.html @@ -0,0 +1,123 @@ + + + + + + Konva Shape Layering Demo + + + +
+
+ + + + + +
+ + + diff --git a/downloads/code/groups_and_layers/zIndex.html b/downloads/code/groups_and_layers/zIndex.html new file mode 100644 index 000000000..5d0463cf0 --- /dev/null +++ b/downloads/code/groups_and_layers/zIndex.html @@ -0,0 +1,76 @@ + + + + + + Konva Shape Layering Demo + + + +
+ + + diff --git a/downloads/code/main-demo.html b/downloads/code/main-demo.html new file mode 100644 index 000000000..baf81f93e --- /dev/null +++ b/downloads/code/main-demo.html @@ -0,0 +1,151 @@ + + + + + + Konva Main demo + + + +
+
Try to drag a star
+ + + diff --git a/downloads/code/performance/BatchDraw.html b/downloads/code/performance/BatchDraw.html new file mode 100644 index 000000000..f8e768a57 --- /dev/null +++ b/downloads/code/performance/BatchDraw.html @@ -0,0 +1,58 @@ + + + + + + Konva Batch Draw Demo + + + + +
+ + + diff --git a/downloads/code/performance/Disable_Perfect_Draw.html b/downloads/code/performance/Disable_Perfect_Draw.html new file mode 100644 index 000000000..9c9587593 --- /dev/null +++ b/downloads/code/performance/Disable_Perfect_Draw.html @@ -0,0 +1,73 @@ + + + + + + Konva Disable Perfect Drawing Demo + + + +
+ + + diff --git a/downloads/code/performance/Layer_Management.html b/downloads/code/performance/Layer_Management.html new file mode 100644 index 000000000..8d57e6e1f --- /dev/null +++ b/downloads/code/performance/Layer_Management.html @@ -0,0 +1,106 @@ + + + + + + Konva Layer Management Demo + + + +
+ + + + diff --git a/downloads/code/performance/Listening_False.html b/downloads/code/performance/Listening_False.html new file mode 100644 index 000000000..3c8b7f8db --- /dev/null +++ b/downloads/code/performance/Listening_False.html @@ -0,0 +1,58 @@ + + + + + + Konva Listening False Demo + + + +
+ + + diff --git a/downloads/code/performance/Optimize_Animation.html b/downloads/code/performance/Optimize_Animation.html new file mode 100644 index 000000000..edd88b51f --- /dev/null +++ b/downloads/code/performance/Optimize_Animation.html @@ -0,0 +1,66 @@ + + + + + + Konva Optimize Animation Demo + + + +
+ + + diff --git a/downloads/code/performance/Optimize_Strokes.html b/downloads/code/performance/Optimize_Strokes.html new file mode 100644 index 000000000..7192480be --- /dev/null +++ b/downloads/code/performance/Optimize_Strokes.html @@ -0,0 +1,89 @@ + + + + + + Konva Optimizing Strokes Demo + + + + +
+ + + + diff --git a/downloads/code/performance/Shape_Caching.html b/downloads/code/performance/Shape_Caching.html new file mode 100644 index 000000000..effce4238 --- /dev/null +++ b/downloads/code/performance/Shape_Caching.html @@ -0,0 +1,62 @@ + + + + + + Konva Shape Caching Demo + + + +
+ + + diff --git a/downloads/code/performance/Shape_Redraw.html b/downloads/code/performance/Shape_Redraw.html new file mode 100644 index 000000000..02d723ac2 --- /dev/null +++ b/downloads/code/performance/Shape_Redraw.html @@ -0,0 +1,68 @@ + + + + + + Konva Shape Redraw Demo + + + +
+ + + diff --git a/downloads/code/posts/Position_vs_Offset_Basic_x_y.html b/downloads/code/posts/Position_vs_Offset_Basic_x_y.html new file mode 100644 index 000000000..d0e82574a --- /dev/null +++ b/downloads/code/posts/Position_vs_Offset_Basic_x_y.html @@ -0,0 +1,73 @@ + + + + + + Konva Basic position demo + + + + + Try to drag a shape. See how coordinates are changing. +
+ + + diff --git a/downloads/code/sandbox/10000_Shapes_With_Tooltip.html b/downloads/code/sandbox/10000_Shapes_With_Tooltip.html new file mode 100644 index 000000000..16c17f994 --- /dev/null +++ b/downloads/code/sandbox/10000_Shapes_With_Tooltip.html @@ -0,0 +1,92 @@ + + + + + + Konva 10,000 Shapes with Tooltips Stress Test Demo + + + +
+ + + diff --git a/downloads/code/sandbox/20000_Nodes.html b/downloads/code/sandbox/20000_Nodes.html new file mode 100644 index 000000000..0c5db9621 --- /dev/null +++ b/downloads/code/sandbox/20000_Nodes.html @@ -0,0 +1,146 @@ + + + + + + Konva Interactive Scatter Plot with 20,000 Nodes Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Animals_on_the_Beach_Game.html b/downloads/code/sandbox/Animals_on_the_Beach_Game.html new file mode 100644 index 000000000..64316d194 --- /dev/null +++ b/downloads/code/sandbox/Animals_on_the_Beach_Game.html @@ -0,0 +1,217 @@ + + + + + + Konva Animals on the Beach Game Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Animation_Stress_Test.html b/downloads/code/sandbox/Animation_Stress_Test.html new file mode 100644 index 000000000..e0b9bef96 --- /dev/null +++ b/downloads/code/sandbox/Animation_Stress_Test.html @@ -0,0 +1,95 @@ + + + + + + Konva Animation Stress Test Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Canvas_Background.html b/downloads/code/sandbox/Canvas_Background.html new file mode 100644 index 000000000..f28921485 --- /dev/null +++ b/downloads/code/sandbox/Canvas_Background.html @@ -0,0 +1,77 @@ + + + + + + Konva Background Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Canvas_Context_Menu.html b/downloads/code/sandbox/Canvas_Context_Menu.html new file mode 100644 index 000000000..34f1a5a1a --- /dev/null +++ b/downloads/code/sandbox/Canvas_Context_Menu.html @@ -0,0 +1,121 @@ + + + + + + Konva Context Menu Demo + + + + +
+ + + + diff --git a/downloads/code/sandbox/Canvas_Scrolling_Drag.html b/downloads/code/sandbox/Canvas_Scrolling_Drag.html new file mode 100644 index 000000000..d891bfd45 --- /dev/null +++ b/downloads/code/sandbox/Canvas_Scrolling_Drag.html @@ -0,0 +1,52 @@ + + + + + + Konva Canvas Scrolling Drag Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Canvas_Scrolling_Large.html b/downloads/code/sandbox/Canvas_Scrolling_Large.html new file mode 100644 index 000000000..c56f555f6 --- /dev/null +++ b/downloads/code/sandbox/Canvas_Scrolling_Large.html @@ -0,0 +1,49 @@ + + + + + + Konva Canvas Scrolling Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Canvas_Scrolling_Manual.html b/downloads/code/sandbox/Canvas_Scrolling_Manual.html new file mode 100644 index 000000000..149fa658c --- /dev/null +++ b/downloads/code/sandbox/Canvas_Scrolling_Manual.html @@ -0,0 +1,145 @@ + + + + + + Konva Canvas Scrolling Drag Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Canvas_Scrolling_Transform.html b/downloads/code/sandbox/Canvas_Scrolling_Transform.html new file mode 100644 index 000000000..3a57067cd --- /dev/null +++ b/downloads/code/sandbox/Canvas_Scrolling_Transform.html @@ -0,0 +1,84 @@ + + + + + + Konva Canvas Scrolling Demo + + + + +
+
+
+
+
+ + + diff --git a/downloads/code/sandbox/Canvas_to_PDF.html b/downloads/code/sandbox/Canvas_to_PDF.html new file mode 100644 index 000000000..3c3bb285a --- /dev/null +++ b/downloads/code/sandbox/Canvas_to_PDF.html @@ -0,0 +1,110 @@ + + + + + + + Konva PDF Demo + + + + +
+ + + + diff --git a/downloads/code/sandbox/Collision_Detection.html b/downloads/code/sandbox/Collision_Detection.html new file mode 100644 index 000000000..67158632a --- /dev/null +++ b/downloads/code/sandbox/Collision_Detection.html @@ -0,0 +1,90 @@ + + + + + + Konva Drag and Drop Collision Detection Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Complex_Editable_Text.html b/downloads/code/sandbox/Complex_Editable_Text.html new file mode 100644 index 000000000..008f11dcc --- /dev/null +++ b/downloads/code/sandbox/Complex_Editable_Text.html @@ -0,0 +1,196 @@ + + + + + + Konva Editable Text on html5 canvas Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Connected_Objects.html b/downloads/code/sandbox/Connected_Objects.html new file mode 100644 index 000000000..3c1e15627 --- /dev/null +++ b/downloads/code/sandbox/Connected_Objects.html @@ -0,0 +1,137 @@ + + + + + + Konva Connect Objects demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Custom_Font.html b/downloads/code/sandbox/Custom_Font.html new file mode 100644 index 000000000..6a6ad6991 --- /dev/null +++ b/downloads/code/sandbox/Custom_Font.html @@ -0,0 +1,95 @@ + + + + + + Konva Custom font loading Demo + + + + + + + +
+ + + diff --git a/downloads/code/sandbox/Drag_And_Drop_Multiple_Shapes.html b/downloads/code/sandbox/Drag_And_Drop_Multiple_Shapes.html new file mode 100644 index 000000000..e90de0eb0 --- /dev/null +++ b/downloads/code/sandbox/Drag_And_Drop_Multiple_Shapes.html @@ -0,0 +1,73 @@ + + + + + + Konva Drag and Drop Multiple Shapes Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Drag_And_Drop_Stress_Test.html b/downloads/code/sandbox/Drag_And_Drop_Stress_Test.html new file mode 100644 index 000000000..0a767305c --- /dev/null +++ b/downloads/code/sandbox/Drag_And_Drop_Stress_Test.html @@ -0,0 +1,89 @@ + + + + + + Konva Drag and Drop Stress Test with 10,000 Shapes Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Drop_DOM_Element.html b/downloads/code/sandbox/Drop_DOM_Element.html new file mode 100644 index 000000000..e74ce7ed9 --- /dev/null +++ b/downloads/code/sandbox/Drop_DOM_Element.html @@ -0,0 +1,78 @@ + + + + + + Konva Drop DOM element Demo + + + + +

Drag&drop yoda into the grey area.

+
+ + +
+
+ + + diff --git a/downloads/code/sandbox/Editable_Text.html b/downloads/code/sandbox/Editable_Text.html new file mode 100644 index 000000000..da469b52f --- /dev/null +++ b/downloads/code/sandbox/Editable_Text.html @@ -0,0 +1,81 @@ + + + + + + Konva Editable Text on html5 canvas Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Elastic_Stars.html b/downloads/code/sandbox/Elastic_Stars.html new file mode 100644 index 000000000..81931264e --- /dev/null +++ b/downloads/code/sandbox/Elastic_Stars.html @@ -0,0 +1,116 @@ + + + + + + Konva Elastic Stars Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Expand_Image_On_Hover.html b/downloads/code/sandbox/Expand_Image_On_Hover.html new file mode 100644 index 000000000..b1e4e0ee6 --- /dev/null +++ b/downloads/code/sandbox/Expand_Image_On_Hover.html @@ -0,0 +1,87 @@ + + + + + + Konva Expand Image on Hover Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Free_Drawing_Manual.html b/downloads/code/sandbox/Free_Drawing_Manual.html new file mode 100644 index 000000000..4e1902915 --- /dev/null +++ b/downloads/code/sandbox/Free_Drawing_Manual.html @@ -0,0 +1,114 @@ + + + + + + Konva Free Drawing Demo + + + + + Tool: + +
+ + + diff --git a/downloads/code/sandbox/Free_Drawing_Vector.html b/downloads/code/sandbox/Free_Drawing_Vector.html new file mode 100644 index 000000000..9cbf5a1e9 --- /dev/null +++ b/downloads/code/sandbox/Free_Drawing_Vector.html @@ -0,0 +1,83 @@ + + + + + + Konva Free Drawing Demo + + + + + Tool: + +
+ + + diff --git a/downloads/code/sandbox/GIF_On_Canvas.html b/downloads/code/sandbox/GIF_On_Canvas.html new file mode 100644 index 000000000..d607e063e --- /dev/null +++ b/downloads/code/sandbox/GIF_On_Canvas.html @@ -0,0 +1,54 @@ + + + + + + + Konva GIF Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Gestures.html b/downloads/code/sandbox/Gestures.html new file mode 100644 index 000000000..99e880232 --- /dev/null +++ b/downloads/code/sandbox/Gestures.html @@ -0,0 +1,143 @@ + + + + + + + + + + + Konva Touch Gestures Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Image_Border.html b/downloads/code/sandbox/Image_Border.html new file mode 100644 index 000000000..db34f674f --- /dev/null +++ b/downloads/code/sandbox/Image_Border.html @@ -0,0 +1,207 @@ + + + + + + Konva Border Image Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Image_Border_Highlighting.html b/downloads/code/sandbox/Image_Border_Highlighting.html new file mode 100644 index 000000000..2b5401bdc --- /dev/null +++ b/downloads/code/sandbox/Image_Border_Highlighting.html @@ -0,0 +1,81 @@ + + + + + + Konva Image Border Highlighting Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Image_Resize.html b/downloads/code/sandbox/Image_Resize.html new file mode 100644 index 000000000..66f0b9faf --- /dev/null +++ b/downloads/code/sandbox/Image_Resize.html @@ -0,0 +1,162 @@ + + + + + + Konva Image Resize Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Interactive_Building_Map.html b/downloads/code/sandbox/Interactive_Building_Map.html new file mode 100644 index 000000000..d23cf2c07 --- /dev/null +++ b/downloads/code/sandbox/Interactive_Building_Map.html @@ -0,0 +1,143 @@ + + + + + + Konva Interactive Building Map Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Jumping_Bunnies.html b/downloads/code/sandbox/Jumping_Bunnies.html new file mode 100644 index 000000000..d4c6bb11d --- /dev/null +++ b/downloads/code/sandbox/Jumping_Bunnies.html @@ -0,0 +1,168 @@ + + + + + + Konva Jumping Bunnies Demo + + + + +
+
+ + + + diff --git a/downloads/code/sandbox/Limited_Drag_And_Resize.html b/downloads/code/sandbox/Limited_Drag_And_Resize.html new file mode 100644 index 000000000..70e561f3c --- /dev/null +++ b/downloads/code/sandbox/Limited_Drag_And_Resize.html @@ -0,0 +1,150 @@ + + + + + + Konva Drag and Drop Multiple Shapes Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Mirror_Canvas_Shape.html b/downloads/code/sandbox/Mirror_Canvas_Shape.html new file mode 100644 index 000000000..21f62628b --- /dev/null +++ b/downloads/code/sandbox/Mirror_Canvas_Shape.html @@ -0,0 +1,68 @@ + + + + + + Konva Transparency for several Shapes Demo + + + + +
+ + + + diff --git a/downloads/code/sandbox/Modify_Curves_with_Anchor_Points.html b/downloads/code/sandbox/Modify_Curves_with_Anchor_Points.html new file mode 100644 index 000000000..1cbdb25ab --- /dev/null +++ b/downloads/code/sandbox/Modify_Curves_with_Anchor_Points.html @@ -0,0 +1,167 @@ + + + + + + Konva Modify Curves with Anchor Points Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Modify_Shape_Color_on_Click.html b/downloads/code/sandbox/Modify_Shape_Color_on_Click.html new file mode 100644 index 000000000..71c902f76 --- /dev/null +++ b/downloads/code/sandbox/Modify_Shape_Color_on_Click.html @@ -0,0 +1,65 @@ + + + + + + Konva Modify Shape Color on Click Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Multi-touch_Scale_Shape.html b/downloads/code/sandbox/Multi-touch_Scale_Shape.html new file mode 100644 index 000000000..3e605f93e --- /dev/null +++ b/downloads/code/sandbox/Multi-touch_Scale_Shape.html @@ -0,0 +1,151 @@ + + + + + + Konva Multi-touch Scale Shape Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Multi-touch_Scale_Stage.html b/downloads/code/sandbox/Multi-touch_Scale_Stage.html new file mode 100644 index 000000000..3255f4e84 --- /dev/null +++ b/downloads/code/sandbox/Multi-touch_Scale_Stage.html @@ -0,0 +1,147 @@ + + + + + + Konva Multi-touch Scale Stage Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Native_Context_Access.html b/downloads/code/sandbox/Native_Context_Access.html new file mode 100644 index 000000000..2ddbaef30 --- /dev/null +++ b/downloads/code/sandbox/Native_Context_Access.html @@ -0,0 +1,57 @@ + + + + + + Konva Native Context Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Objects_Snapping.html b/downloads/code/sandbox/Objects_Snapping.html new file mode 100644 index 000000000..4c529effa --- /dev/null +++ b/downloads/code/sandbox/Objects_Snapping.html @@ -0,0 +1,247 @@ + + + + + + Konva Snapping of shapes Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Physics_Simulator.html b/downloads/code/sandbox/Physics_Simulator.html new file mode 100644 index 000000000..2370fa357 --- /dev/null +++ b/downloads/code/sandbox/Physics_Simulator.html @@ -0,0 +1,338 @@ + + + + + + Konva Physics Simulator Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Planets_Image_Map.html b/downloads/code/sandbox/Planets_Image_Map.html new file mode 100644 index 000000000..5d0c959f6 --- /dev/null +++ b/downloads/code/sandbox/Planets_Image_Map.html @@ -0,0 +1,140 @@ + + + + + + Konva Planets Image Map Demo + + + +
+
+ + +
+ + + diff --git a/downloads/code/sandbox/Quantum_Squiggle.html b/downloads/code/sandbox/Quantum_Squiggle.html new file mode 100644 index 000000000..ecf78d9f2 --- /dev/null +++ b/downloads/code/sandbox/Quantum_Squiggle.html @@ -0,0 +1,73 @@ + + + + + + Konva Quantum Squiggle Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Relative_Pointer_Position.html b/downloads/code/sandbox/Relative_Pointer_Position.html new file mode 100644 index 000000000..dfa44d54e --- /dev/null +++ b/downloads/code/sandbox/Relative_Pointer_Position.html @@ -0,0 +1,64 @@ + + + + + + Konva Relative Pointer Position Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Relative_zooming.html b/downloads/code/sandbox/Relative_zooming.html new file mode 100644 index 000000000..1c7ddbc0e --- /dev/null +++ b/downloads/code/sandbox/Relative_zooming.html @@ -0,0 +1,74 @@ + + + + + + Konva Zoom Relative to Stage Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Resizing_Stress_Test.html b/downloads/code/sandbox/Resizing_Stress_Test.html new file mode 100644 index 000000000..bb759a261 --- /dev/null +++ b/downloads/code/sandbox/Resizing_Stress_Test.html @@ -0,0 +1,163 @@ + + + + + + Konva Resizing stress test Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Responsive_Canvas.html b/downloads/code/sandbox/Responsive_Canvas.html new file mode 100644 index 000000000..291882bcf --- /dev/null +++ b/downloads/code/sandbox/Responsive_Canvas.html @@ -0,0 +1,80 @@ + + + + + + Konva Responsive Canvas Demo + + + + +
+
+
+ + + diff --git a/downloads/code/sandbox/Rich_Text.html b/downloads/code/sandbox/Rich_Text.html new file mode 100644 index 000000000..b23cfc171 --- /dev/null +++ b/downloads/code/sandbox/Rich_Text.html @@ -0,0 +1,99 @@ + + + + + + + + + + Konva Rich text on Canvas Demo + + + + +
+ That is some styled text on + canvas! +

What do you think about it?

+
+ Rendered stage: +
+ + + diff --git a/downloads/code/sandbox/SVG_On_Canvas.html b/downloads/code/sandbox/SVG_On_Canvas.html new file mode 100644 index 000000000..85aedab35 --- /dev/null +++ b/downloads/code/sandbox/SVG_On_Canvas.html @@ -0,0 +1,58 @@ + + + + + + + Konva SVG Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Scale_Image_To_Fit.html b/downloads/code/sandbox/Scale_Image_To_Fit.html new file mode 100644 index 000000000..3d038f7b8 --- /dev/null +++ b/downloads/code/sandbox/Scale_Image_To_Fit.html @@ -0,0 +1,173 @@ + + + + + + Konva Scale to Fit Demo + + + + +
+ + + + diff --git a/downloads/code/sandbox/Scroll_By_Edge_Drag.html b/downloads/code/sandbox/Scroll_By_Edge_Drag.html new file mode 100644 index 000000000..b9c842a2a --- /dev/null +++ b/downloads/code/sandbox/Scroll_By_Edge_Drag.html @@ -0,0 +1,83 @@ + + + + + + Konva Canvas Scrolling Drag Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Shape_Tango.html b/downloads/code/sandbox/Shape_Tango.html new file mode 100644 index 000000000..bcd96755b --- /dev/null +++ b/downloads/code/sandbox/Shape_Tango.html @@ -0,0 +1,90 @@ + + + + + + Konva Shape Tango Demo + + + +
+ + + + diff --git a/downloads/code/sandbox/Shape_Tooltips.html b/downloads/code/sandbox/Shape_Tooltips.html new file mode 100644 index 000000000..4b282307b --- /dev/null +++ b/downloads/code/sandbox/Shape_Tooltips.html @@ -0,0 +1,103 @@ + + + + + + Konva Shape Tooltips Demo + + + +
+ + + diff --git a/downloads/code/sandbox/Simple_Window.html b/downloads/code/sandbox/Simple_Window.html new file mode 100644 index 000000000..c333f3bca --- /dev/null +++ b/downloads/code/sandbox/Simple_Window.html @@ -0,0 +1,353 @@ + + + + + + Konva Simple Window drawing + + + + +
+ +
+
+ Width: + +
+
+ Height: + +
+
+ + + diff --git a/downloads/code/sandbox/Stage_Preview_Clone.html b/downloads/code/sandbox/Stage_Preview_Clone.html new file mode 100644 index 000000000..96357f6d0 --- /dev/null +++ b/downloads/code/sandbox/Stage_Preview_Clone.html @@ -0,0 +1,101 @@ + + + + + + Konva Canvas Stage Preview Demo + + + + +
+
+ + + diff --git a/downloads/code/sandbox/Stage_Preview_Image.html b/downloads/code/sandbox/Stage_Preview_Image.html new file mode 100644 index 000000000..1d44d215a --- /dev/null +++ b/downloads/code/sandbox/Stage_Preview_Image.html @@ -0,0 +1,84 @@ + + + + + + Konva Canvas Stage Preview Demo + + + + +
+ + + + diff --git a/downloads/code/sandbox/Star_Spinner.html b/downloads/code/sandbox/Star_Spinner.html new file mode 100644 index 000000000..ea1e9f2a0 --- /dev/null +++ b/downloads/code/sandbox/Star_Spinner.html @@ -0,0 +1,119 @@ + + + + + + Konva Star Spinner Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Transparent_Group.html b/downloads/code/sandbox/Transparent_Group.html new file mode 100644 index 000000000..78a062e6c --- /dev/null +++ b/downloads/code/sandbox/Transparent_Group.html @@ -0,0 +1,78 @@ + + + + + + Konva Transparency for several Shapes Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Video_On_Canvas.html b/downloads/code/sandbox/Video_On_Canvas.html new file mode 100644 index 000000000..6b9e48ec3 --- /dev/null +++ b/downloads/code/sandbox/Video_On_Canvas.html @@ -0,0 +1,76 @@ + + + + + + Konva GIF Demo + + + + + +
+ + + diff --git a/downloads/code/sandbox/Web_Worker.html b/downloads/code/sandbox/Web_Worker.html new file mode 100644 index 000000000..aa577a56f --- /dev/null +++ b/downloads/code/sandbox/Web_Worker.html @@ -0,0 +1,69 @@ + + + + + Konva Offscreen Canvas Demo + + + + + + + + diff --git a/downloads/code/sandbox/Web_Worker.js b/downloads/code/sandbox/Web_Worker.js new file mode 100644 index 000000000..2b3fafbfa --- /dev/null +++ b/downloads/code/sandbox/Web_Worker.js @@ -0,0 +1,216 @@ +// load konva framework +importScripts('https://unpkg.com/konva@9/konva.min.js'); + +// monkeypatch Konva for offscreen canvas usage +Konva.Util.createCanvasElement = () => { + const canvas = new OffscreenCanvas(1, 1); + canvas.style = {}; + return canvas; +}; + +// now we can create our canvas content +var stage = new Konva.Stage({ + width: 200, + height: 200, +}); + +var layer = new Konva.Layer(); +stage.add(layer); + +var topGroup = new Konva.Group(); +layer.add(topGroup); + +// counter will show number of bunnies +var counter = new Konva.Text({ + x: 5, + y: 35, +}); +topGroup.add(counter); + +// "add more bunnies" button +var button = new Konva.Label({ + x: 5, + y: 5, + opacity: 0.75, +}); +topGroup.add(button); + +button.add( + new Konva.Tag({ + fill: 'black', + }) +); + +button.add( + new Konva.Text({ + text: 'Push me to add bunnies', + fontFamily: 'Calibri', + fontSize: 18, + padding: 5, + fill: 'white', + }) +); + +// draggable circle to show interactivity +var circle = new Konva.Circle({ + x: stage.width() / 2, + y: stage.height() / 2, + radius: 20, + fill: 'red', + draggable: true, +}); +topGroup.add(circle); + +self.onmessage = function (evt) { + // when canvas is passes we can start our worker + // we can try to use that canvas for the layer with some manual replacement (and probably better performance) + // but for simplicity we will just copy layer content into passed canvas + if (evt.data.canvas) { + var canvas = evt.data.canvas; + // adapt stage size + // we may need to add extra event to resize stage on a fly + stage.setSize({ + width: canvas.width, + height: canvas.height, + }); + + const ctx = canvas.getContext('2d'); + + // Konva.Layer has support for "draw" event + // so every time the layer is re-rendered we need to update the canvas + layer.on('draw', () => { + // clear content + ctx.clearRect(0, 0, canvas.width, canvas.height); + // draw layer content + ctx.drawImage(layer.getCanvas()._canvas, 0, 0); + }); + } + // emulate some drag&drop events + if (evt.data.eventName === 'mouseup') { + Konva.DD._endDragBefore(evt.data.event); + } + if (evt.data.eventName === 'touchend') { + Konva.DD._endDragBefore(evt.data.event); + } + if (evt.data.eventName === 'mousemove') { + Konva.DD._drag(evt.data.event); + } + if (evt.data.eventName === 'touchmove') { + Konva.DD._drag(evt.data.event); + } + if (evt.data.eventName === 'mouseup') { + Konva.DD._endDragAfter(evt.data.event); + } + if (evt.data.eventName === 'touchend') { + Konva.DD._endDragAfter(evt.data.event); + } + + // pass incoming events into the stage + if (evt.data.eventName) { + const event = evt.data.eventName.replace('mouse', 'pointer'); + stage['_' + event](evt.data.event); + } +}; + +function requestAnimationFrame(cb) { + setTimeout(cb, 16); +} + +// that function is large and adapted from bunnies demo +// the only interesting part here is how to load images to use for Konva.Image +async function runBunnies() { + const imgBlob = await fetch('https://konvajs.org/assets/bunny.png').then( + (r) => r.blob() + ); + // use "createImageBitmap" instead of "new window.Image()" + const img = await createImageBitmap(imgBlob); + + var bunnys = []; + var gravity = 0.75; + + var startBunnyCount = 100; + var isAdding = false; + var count = 0; + var amount = 10; + + button.on('mousedown', function () { + isAdding = true; + }); + + button.on('mouseup', function () { + isAdding = false; + }); + + for (var i = 0; i < startBunnyCount; i++) { + var bunny = new Konva.Image({ + image: img, + transformsEnabled: 'position', + x: 10, + y: 10, + listening: false, + }); + + bunny.speedX = Math.random() * 10; + bunny.speedY = Math.random() * 10 - 5; + + bunnys.push(bunny); + counter.text('Bunnies number: ' + bunnys.length); + layer.add(bunny); + } + topGroup.moveToTop(); + + function update() { + var maxX = stage.width() - 10; + var minX = 0; + var maxY = stage.height() - 10; + var minY = 0; + if (isAdding) { + for (var i = 0; i < amount; i++) { + var bunny = new Konva.Image({ + image: img, + transformsEnabled: 'position', + x: 0, + y: 0, + listening: false, + }); + bunny.speedX = Math.random() * 10; + bunny.speedY = Math.random() * 10 - 5; + bunnys.push(bunny); + layer.add(bunny); + counter.text('Bunnies number: ' + bunnys.length); + count++; + } + topGroup.moveToTop(); + } + + for (var i = 0; i < bunnys.length; i++) { + var bunny = bunnys[i]; + bunny.setX(bunny.getX() + bunny.speedX); + bunny.setY(bunny.getY() + bunny.speedY); + bunny.speedY += gravity; + if (bunny.getX() > maxX - img.width) { + bunny.speedX *= -1; + bunny.setX(maxX - img.width); + } else if (bunny.getX() < minX) { + bunny.speedX *= -1; + bunny.setX(minX); + } + + if (bunny.getY() > maxY - img.height) { + bunny.speedY *= -0.85; + bunny.setY(maxY - img.height); + if (Math.random() > 0.5) { + bunny.speedY -= Math.random() * 6; + } + } else if (bunny.getY() < minY) { + bunny.speedY = 0; + bunny.setY(minY); + } + } + layer.drawScene(); + requestAnimationFrame(update); + } + update(); +} + +runBunnies(); diff --git a/downloads/code/sandbox/Wheel_of_Fortune.html b/downloads/code/sandbox/Wheel_of_Fortune.html new file mode 100644 index 000000000..6f1df91d2 --- /dev/null +++ b/downloads/code/sandbox/Wheel_of_Fortune.html @@ -0,0 +1,268 @@ + + + + + + Konva Wheel of Fortune Demo + + + + +
+ + + diff --git a/downloads/code/sandbox/Zoom_Layer_On_Hover.html b/downloads/code/sandbox/Zoom_Layer_On_Hover.html new file mode 100644 index 000000000..eb7acdff3 --- /dev/null +++ b/downloads/code/sandbox/Zoom_Layer_On_Hover.html @@ -0,0 +1,70 @@ + + + + + + Konva Zoom Image on Hover Demo + + + +
+ + + diff --git a/downloads/code/select_and_transform/Basic_demo.html b/downloads/code/select_and_transform/Basic_demo.html new file mode 100644 index 000000000..c5664fb14 --- /dev/null +++ b/downloads/code/select_and_transform/Basic_demo.html @@ -0,0 +1,164 @@ + + + + + + + Konva Select and Transform Demo + + + + +
+ + + diff --git a/downloads/code/select_and_transform/Centered_Scaling.html b/downloads/code/select_and_transform/Centered_Scaling.html new file mode 100644 index 000000000..59a2d7bd3 --- /dev/null +++ b/downloads/code/select_and_transform/Centered_Scaling.html @@ -0,0 +1,64 @@ + + + + + + + Konva Centered Scaling Demo + + + + +
+ + + diff --git a/downloads/code/select_and_transform/Force_Update.html b/downloads/code/select_and_transform/Force_Update.html new file mode 100644 index 000000000..4a994bfc3 --- /dev/null +++ b/downloads/code/select_and_transform/Force_Update.html @@ -0,0 +1,71 @@ + + + + + + + Konva Transform Events Demo + + + + +
+ + + + diff --git a/downloads/code/select_and_transform/Ignore_Stroke_On_Transform.html b/downloads/code/select_and_transform/Ignore_Stroke_On_Transform.html new file mode 100644 index 000000000..2dcff53e0 --- /dev/null +++ b/downloads/code/select_and_transform/Ignore_Stroke_On_Transform.html @@ -0,0 +1,90 @@ + + + + + + + Konva Resize Text Demo + + + + +
+ + + diff --git a/downloads/code/select_and_transform/Keep_Ratio.html b/downloads/code/select_and_transform/Keep_Ratio.html new file mode 100644 index 000000000..2e950e844 --- /dev/null +++ b/downloads/code/select_and_transform/Keep_Ratio.html @@ -0,0 +1,76 @@ + + + + + + + Konva Keep Ratio Demo + + + + +
+ + + diff --git a/downloads/code/select_and_transform/Resize_Limits.html b/downloads/code/select_and_transform/Resize_Limits.html new file mode 100644 index 000000000..191a9eceb --- /dev/null +++ b/downloads/code/select_and_transform/Resize_Limits.html @@ -0,0 +1,66 @@ + + + + + + + Konva Transform Limits Demo + + + + +
+ + + diff --git a/downloads/code/select_and_transform/Resize_Snaps.html b/downloads/code/select_and_transform/Resize_Snaps.html new file mode 100644 index 000000000..71ae29bd1 --- /dev/null +++ b/downloads/code/select_and_transform/Resize_Snaps.html @@ -0,0 +1,126 @@ + + + + + + + Konva Resize Snap Demo + + + + +
+ + + diff --git a/downloads/code/select_and_transform/Resize_Text.html b/downloads/code/select_and_transform/Resize_Text.html new file mode 100644 index 000000000..abe9e2e86 --- /dev/null +++ b/downloads/code/select_and_transform/Resize_Text.html @@ -0,0 +1,70 @@ + + + + + + + Konva Resize Text Demo + + + + +
+ + + diff --git a/downloads/code/select_and_transform/Rotation_Snaps.html b/downloads/code/select_and_transform/Rotation_Snaps.html new file mode 100644 index 000000000..f88b60587 --- /dev/null +++ b/downloads/code/select_and_transform/Rotation_Snaps.html @@ -0,0 +1,51 @@ + + + + + + + Konva Rotation snap Demo + + + + +
+ + + diff --git a/downloads/code/select_and_transform/Stop_Transform.html b/downloads/code/select_and_transform/Stop_Transform.html new file mode 100644 index 000000000..cbbaeae03 --- /dev/null +++ b/downloads/code/select_and_transform/Stop_Transform.html @@ -0,0 +1,61 @@ + + + + + + + Konva Stop Transform Demo + + + + +
+ + + diff --git a/downloads/code/select_and_transform/Transform_Events.html b/downloads/code/select_and_transform/Transform_Events.html new file mode 100644 index 000000000..0f3001c48 --- /dev/null +++ b/downloads/code/select_and_transform/Transform_Events.html @@ -0,0 +1,87 @@ + + + + + + + Konva Transform Events Demo + + + + +
+ + + diff --git a/downloads/code/select_and_transform/Transformer_Complex_Styling.html b/downloads/code/select_and_transform/Transformer_Complex_Styling.html new file mode 100644 index 000000000..c2f8c1a88 --- /dev/null +++ b/downloads/code/select_and_transform/Transformer_Complex_Styling.html @@ -0,0 +1,68 @@ + + + + + + + Konva Select and Transform Complex Styling Demo + + + + +
+ + + diff --git a/downloads/code/select_and_transform/Transformer_Styling.html b/downloads/code/select_and_transform/Transformer_Styling.html new file mode 100644 index 000000000..708c85679 --- /dev/null +++ b/downloads/code/select_and_transform/Transformer_Styling.html @@ -0,0 +1,54 @@ + + + + + + + Konva Select and Transform Styling Demo + + + + +
+ + + diff --git a/downloads/code/selectors/Select_by_Name.html b/downloads/code/selectors/Select_by_Name.html new file mode 100644 index 000000000..1476a2822 --- /dev/null +++ b/downloads/code/selectors/Select_by_Name.html @@ -0,0 +1,121 @@ + + + + + + Konva Select Shape by Name Demo + + + +
+
+ +
+ + + diff --git a/downloads/code/selectors/Select_by_Type.html b/downloads/code/selectors/Select_by_Type.html new file mode 100644 index 000000000..a7b3f7717 --- /dev/null +++ b/downloads/code/selectors/Select_by_Type.html @@ -0,0 +1,119 @@ + + + + + + Konva Select Shape by Type Demo + + + +
+
+ +
+ + + diff --git a/downloads/code/selectors/Select_by_id.html b/downloads/code/selectors/Select_by_id.html new file mode 100644 index 000000000..2990369bf --- /dev/null +++ b/downloads/code/selectors/Select_by_id.html @@ -0,0 +1,100 @@ + + + + + + Konva Select Shape by id Demo + + + + +
+
+ +
+ + + diff --git a/downloads/code/shapes/Arc.html b/downloads/code/shapes/Arc.html new file mode 100644 index 000000000..a26078bba --- /dev/null +++ b/downloads/code/shapes/Arc.html @@ -0,0 +1,48 @@ + + + + + + Konva Arc Demo + + + +
+ + + diff --git a/downloads/code/shapes/Arrow.html b/downloads/code/shapes/Arrow.html new file mode 100644 index 000000000..61368950d --- /dev/null +++ b/downloads/code/shapes/Arrow.html @@ -0,0 +1,48 @@ + + + + + + Konva Arrow Demo + + + +
+ + + diff --git a/downloads/code/shapes/Circle.html b/downloads/code/shapes/Circle.html new file mode 100644 index 000000000..be60bf890 --- /dev/null +++ b/downloads/code/shapes/Circle.html @@ -0,0 +1,46 @@ + + + + + + Konva Circle Demo + + + +
+ + + diff --git a/downloads/code/shapes/Custom.html b/downloads/code/shapes/Custom.html new file mode 100644 index 000000000..f292cdaf8 --- /dev/null +++ b/downloads/code/shapes/Custom.html @@ -0,0 +1,59 @@ + + + + + + Konva Custom Shape Demo + + + + +
+ + + diff --git a/downloads/code/shapes/Ellipse.html b/downloads/code/shapes/Ellipse.html new file mode 100644 index 000000000..842ef797a --- /dev/null +++ b/downloads/code/shapes/Ellipse.html @@ -0,0 +1,47 @@ + + + + + + Konva Ellipse Demo + + + +
+ + + diff --git a/downloads/code/shapes/Image.html b/downloads/code/shapes/Image.html new file mode 100644 index 000000000..258e69f19 --- /dev/null +++ b/downloads/code/shapes/Image.html @@ -0,0 +1,60 @@ + + + + + + Konva Image Demo + + + +
+ + + diff --git a/downloads/code/shapes/Label.html b/downloads/code/shapes/Label.html new file mode 100644 index 000000000..0c716a26d --- /dev/null +++ b/downloads/code/shapes/Label.html @@ -0,0 +1,117 @@ + + + + + + Konva Label Demo + + + + +
+ + + diff --git a/downloads/code/shapes/Line_-_Blob.html b/downloads/code/shapes/Line_-_Blob.html new file mode 100644 index 000000000..597d4a7a0 --- /dev/null +++ b/downloads/code/shapes/Line_-_Blob.html @@ -0,0 +1,46 @@ + + + + + + Konva Line Blob Demo + + + +
+ + + diff --git a/downloads/code/shapes/Line_-_Polygon.html b/downloads/code/shapes/Line_-_Polygon.html new file mode 100644 index 000000000..eee733875 --- /dev/null +++ b/downloads/code/shapes/Line_-_Polygon.html @@ -0,0 +1,45 @@ + + + + + + Konva Line Polygon Demo + + + +
+ + + diff --git a/downloads/code/shapes/Line_-_Simple_line.html b/downloads/code/shapes/Line_-_Simple_line.html new file mode 100644 index 000000000..b2d8c376e --- /dev/null +++ b/downloads/code/shapes/Line_-_Simple_line.html @@ -0,0 +1,92 @@ + + + + + + Konva Simple Line Demo + + + +
+ + + diff --git a/downloads/code/shapes/Line_-_Spline.html b/downloads/code/shapes/Line_-_Spline.html new file mode 100644 index 000000000..2d0617b5e --- /dev/null +++ b/downloads/code/shapes/Line_-_Spline.html @@ -0,0 +1,96 @@ + + + + + + Konva Line Spline Demo + + + +
+ + + diff --git a/downloads/code/shapes/Path.html b/downloads/code/shapes/Path.html new file mode 100644 index 000000000..905ab8743 --- /dev/null +++ b/downloads/code/shapes/Path.html @@ -0,0 +1,44 @@ + + + + + + Konva Path Demo + + + + +
+ + + diff --git a/downloads/code/shapes/RegularPolygon.html b/downloads/code/shapes/RegularPolygon.html new file mode 100644 index 000000000..580fc36a1 --- /dev/null +++ b/downloads/code/shapes/RegularPolygon.html @@ -0,0 +1,44 @@ + + + + + + Konva RegularPolygon Demo + + + + +
+ + + diff --git a/downloads/code/shapes/Ring.html b/downloads/code/shapes/Ring.html new file mode 100644 index 000000000..e7a01be33 --- /dev/null +++ b/downloads/code/shapes/Ring.html @@ -0,0 +1,47 @@ + + + + + + Konva Ring Demo + + + +
+ + + diff --git a/downloads/code/shapes/Sprite.html b/downloads/code/shapes/Sprite.html new file mode 100644 index 000000000..9cf2a55fd --- /dev/null +++ b/downloads/code/shapes/Sprite.html @@ -0,0 +1,87 @@ + + + + + + Konva Sprite Demo + + + +
+ + + + diff --git a/downloads/code/shapes/Star.html b/downloads/code/shapes/Star.html new file mode 100644 index 000000000..4a619168b --- /dev/null +++ b/downloads/code/shapes/Star.html @@ -0,0 +1,46 @@ + + + + + + Konva Star Demo + + + + +
+ + + diff --git a/downloads/code/shapes/Text.html b/downloads/code/shapes/Text.html new file mode 100644 index 000000000..d81e295e1 --- /dev/null +++ b/downloads/code/shapes/Text.html @@ -0,0 +1,79 @@ + + + + + + Konva Text Demo + + + +
+ + + diff --git a/downloads/code/shapes/TextPath.html b/downloads/code/shapes/TextPath.html new file mode 100644 index 000000000..dbd6d9612 --- /dev/null +++ b/downloads/code/shapes/TextPath.html @@ -0,0 +1,46 @@ + + + + + + Konva TextPath Demo + + + +
+ + + diff --git a/downloads/code/shapes/Wedge.html b/downloads/code/shapes/Wedge.html new file mode 100644 index 000000000..93b1e79a4 --- /dev/null +++ b/downloads/code/shapes/Wedge.html @@ -0,0 +1,48 @@ + + + + + + Konva Wedge Demo + + + +
+ + + diff --git a/downloads/code/shapes/rect.html b/downloads/code/shapes/rect.html new file mode 100644 index 000000000..3589800af --- /dev/null +++ b/downloads/code/shapes/rect.html @@ -0,0 +1,67 @@ + + + + + + Konva Rect Demo + + + +
+ + + diff --git a/downloads/code/styling/Blend_Mode.html b/downloads/code/styling/Blend_Mode.html new file mode 100644 index 000000000..f60ddba86 --- /dev/null +++ b/downloads/code/styling/Blend_Mode.html @@ -0,0 +1,61 @@ + + + + + + Konva Blend Mode Demo + + + + +
+ + + diff --git a/downloads/code/styling/Fill.html b/downloads/code/styling/Fill.html new file mode 100644 index 000000000..3143a7aaa --- /dev/null +++ b/downloads/code/styling/Fill.html @@ -0,0 +1,173 @@ + + + + + + Konva Fill Demo + + + +
+ + + diff --git a/downloads/code/styling/Fill_Stroke_Order.html b/downloads/code/styling/Fill_Stroke_Order.html new file mode 100644 index 000000000..72b2e7cd2 --- /dev/null +++ b/downloads/code/styling/Fill_Stroke_Order.html @@ -0,0 +1,56 @@ + + + + + + Konva Fill Stroke Order Demo + + + +
+ + + diff --git a/downloads/code/styling/Hide_and_Show.html b/downloads/code/styling/Hide_and_Show.html new file mode 100644 index 000000000..17b1dc2c7 --- /dev/null +++ b/downloads/code/styling/Hide_and_Show.html @@ -0,0 +1,77 @@ + + + + + + Konva Hide and Show Demo + + + +
+
+ + +
+ + + diff --git a/downloads/code/styling/Line_Join.html b/downloads/code/styling/Line_Join.html new file mode 100644 index 000000000..d6563d9f8 --- /dev/null +++ b/downloads/code/styling/Line_Join.html @@ -0,0 +1,55 @@ + + + + + + Konva Line Join Demo + + + +
+ + + diff --git a/downloads/code/styling/Mouse_Cursor.html b/downloads/code/styling/Mouse_Cursor.html new file mode 100644 index 000000000..ef4b1c0f3 --- /dev/null +++ b/downloads/code/styling/Mouse_Cursor.html @@ -0,0 +1,95 @@ + + + + + + Konva Mouse Cursor Styles Demo + + + + +
+ + + diff --git a/downloads/code/styling/Opacity.html b/downloads/code/styling/Opacity.html new file mode 100644 index 000000000..ea319e040 --- /dev/null +++ b/downloads/code/styling/Opacity.html @@ -0,0 +1,55 @@ + + + + + + Konva Opacity Demo + + + +
+ + + diff --git a/downloads/code/styling/Shadow.html b/downloads/code/styling/Shadow.html new file mode 100644 index 000000000..8f5162295 --- /dev/null +++ b/downloads/code/styling/Shadow.html @@ -0,0 +1,77 @@ + + + + + + Konva Shadow Demo + + + +
+ + + diff --git a/downloads/code/styling/Stroke.html b/downloads/code/styling/Stroke.html new file mode 100644 index 000000000..aaba3fca2 --- /dev/null +++ b/downloads/code/styling/Stroke.html @@ -0,0 +1,55 @@ + + + + + + Konva Stroke Demo + + + +
+ + + diff --git a/downloads/code/tweens/All_Controls.html b/downloads/code/tweens/All_Controls.html new file mode 100644 index 000000000..0ef9ec92f --- /dev/null +++ b/downloads/code/tweens/All_Controls.html @@ -0,0 +1,134 @@ + + + + + + Konva All Controls Demo + + + +
+
+ + + + + + +
+ + + diff --git a/downloads/code/tweens/All_Easings.html b/downloads/code/tweens/All_Easings.html new file mode 100644 index 000000000..9c7d918df --- /dev/null +++ b/downloads/code/tweens/All_Easings.html @@ -0,0 +1,127 @@ + + + + + + Konva All Easings Demo + + + +
+
+ + + +
+ + + diff --git a/downloads/code/tweens/Common_Easing.html b/downloads/code/tweens/Common_Easing.html new file mode 100644 index 000000000..720d467d0 --- /dev/null +++ b/downloads/code/tweens/Common_Easing.html @@ -0,0 +1,112 @@ + + + + + + Konva Common Easing Demo + + + +
+ + + diff --git a/downloads/code/tweens/Complex_Tweening.html b/downloads/code/tweens/Complex_Tweening.html new file mode 100644 index 000000000..829a73de3 --- /dev/null +++ b/downloads/code/tweens/Complex_Tweening.html @@ -0,0 +1,135 @@ + + + + + + + + + + Konva Complex Tweening Demo + + + + +
+ + + diff --git a/downloads/code/tweens/Finish_Event.html b/downloads/code/tweens/Finish_Event.html new file mode 100644 index 000000000..6a9c43a37 --- /dev/null +++ b/downloads/code/tweens/Finish_Event.html @@ -0,0 +1,75 @@ + + + + + + Konva Finish Event Demo + + + +
+ + + diff --git a/downloads/code/tweens/Linear_Easing.html b/downloads/code/tweens/Linear_Easing.html new file mode 100644 index 000000000..4dbb9d942 --- /dev/null +++ b/downloads/code/tweens/Linear_Easing.html @@ -0,0 +1,63 @@ + + + + + + Konva Linear Easing Demo + + + +
+ + + diff --git a/downloads/code/tweens/Tween_Filter.html b/downloads/code/tweens/Tween_Filter.html new file mode 100644 index 000000000..ab7d0c796 --- /dev/null +++ b/downloads/code/tweens/Tween_Filter.html @@ -0,0 +1,64 @@ + + + + + + Konva Tween Filter Demo + + + +
+ + + diff --git a/favicon-16x16.png b/favicon-16x16.png new file mode 100644 index 000000000..6a1e95772 Binary files /dev/null and b/favicon-16x16.png differ diff --git a/favicon-32x32.png b/favicon-32x32.png new file mode 100644 index 000000000..814358baf Binary files /dev/null and b/favicon-32x32.png differ diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 000000000..da3ce89b0 Binary files /dev/null and b/favicon.ico differ diff --git a/icon.png b/icon.png new file mode 100644 index 000000000..6ced0a61a Binary files /dev/null and b/icon.png differ diff --git a/index.html b/index.html new file mode 100644 index 000000000..d8d4a9cdb --- /dev/null +++ b/index.html @@ -0,0 +1,428 @@ + + + + + + Konva - JavaScript 2d canvas + library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Features

Object Oriented API with support of many shapes

Support for desktop and mobile devices

Animations and tweens

Node nesting, grouping and event bubbling

Hight quality exports into data URLs, image data, or image objects

Nice ready-to-use filters

Native integration with web frameworks such as React, Vue and Svelte

Built-in Drag&drop support

Demo

Who is using Konva?

+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/js/hammer-konva.js b/js/hammer-konva.js new file mode 100644 index 000000000..bb7dbf58f --- /dev/null +++ b/js/hammer-konva.js @@ -0,0 +1,2804 @@ +/*! This is slightly modified version of hammer library to make it work with Konva framework + * Modified by Anton Lavrenov. + * Original code: + * Hammer.JS - v2.0.7 - 2016-04-22 + * http://hammerjs.github.io/ + * that version is slightly modified by Anton Lavrenov + * to make it work with Konva framework + * Copyright (c) 2016 Jorik Tangelder; + * Licensed under the MIT license */ +(function(window, document, exportName, undefined) { + 'use strict'; + + var VENDOR_PREFIXES = ['', 'webkit', 'Moz', 'MS', 'ms', 'o']; + var TEST_ELEMENT = document.createElement('div'); + + var TYPE_FUNCTION = 'function'; + + var round = Math.round; + var abs = Math.abs; + var now = Date.now; + + /** + * set a timeout with a given scope + * @param {Function} fn + * @param {Number} timeout + * @param {Object} context + * @returns {number} + */ + function setTimeoutContext(fn, timeout, context) { + return setTimeout(bindFn(fn, context), timeout); + } + + /** + * if the argument is an array, we want to execute the fn on each entry + * if it aint an array we don't want to do a thing. + * this is used by all the methods that accept a single and array argument. + * @param {*|Array} arg + * @param {String} fn + * @param {Object} [context] + * @returns {Boolean} + */ + function invokeArrayArg(arg, fn, context) { + if (Array.isArray(arg)) { + each(arg, context[fn], context); + return true; + } + return false; + } + + /** + * walk objects and arrays + * @param {Object} obj + * @param {Function} iterator + * @param {Object} context + */ + function each(obj, iterator, context) { + var i; + + if (!obj) { + return; + } + + if (obj.forEach) { + obj.forEach(iterator, context); + } else if (obj.length !== undefined) { + i = 0; + while (i < obj.length) { + iterator.call(context, obj[i], i, obj); + i++; + } + } else { + for (i in obj) { + obj.hasOwnProperty(i) && iterator.call(context, obj[i], i, obj); + } + } + } + + /** + * wrap a method with a deprecation warning and stack trace + * @param {Function} method + * @param {String} name + * @param {String} message + * @returns {Function} A new function wrapping the supplied method. + */ + function deprecate(method, name, message) { + var deprecationMessage = + 'DEPRECATED METHOD: ' + name + '\n' + message + ' AT \n'; + return function() { + var e = new Error('get-stack-trace'); + var stack = + e && e.stack + ? e.stack + .replace(/^[^\(]+?[\n$]/gm, '') + .replace(/^\s+at\s+/gm, '') + .replace(/^Object.\s*\(/gm, '{anonymous}()@') + : 'Unknown Stack Trace'; + + var log = window.console && (window.console.warn || window.console.log); + if (log) { + log.call(window.console, deprecationMessage, stack); + } + return method.apply(this, arguments); + }; + } + + /** + * extend object. + * means that properties in dest will be overwritten by the ones in src. + * @param {Object} target + * @param {...Object} objects_to_assign + * @returns {Object} target + */ + var assign; + if (typeof Object.assign !== 'function') { + assign = function assign(target) { + if (target === undefined || target === null) { + throw new TypeError('Cannot convert undefined or null to object'); + } + + var output = Object(target); + for (var index = 1; index < arguments.length; index++) { + var source = arguments[index]; + if (source !== undefined && source !== null) { + for (var nextKey in source) { + if (source.hasOwnProperty(nextKey)) { + output[nextKey] = source[nextKey]; + } + } + } + } + return output; + }; + } else { + assign = Object.assign; + } + + /** + * extend object. + * means that properties in dest will be overwritten by the ones in src. + * @param {Object} dest + * @param {Object} src + * @param {Boolean} [merge=false] + * @returns {Object} dest + */ + var extend = deprecate( + function extend(dest, src, merge) { + var keys = Object.keys(src); + var i = 0; + while (i < keys.length) { + if (!merge || (merge && dest[keys[i]] === undefined)) { + dest[keys[i]] = src[keys[i]]; + } + i++; + } + return dest; + }, + 'extend', + 'Use `assign`.' + ); + + /** + * merge the values from src in the dest. + * means that properties that exist in dest will not be overwritten by src + * @param {Object} dest + * @param {Object} src + * @returns {Object} dest + */ + var merge = deprecate( + function merge(dest, src) { + return extend(dest, src, true); + }, + 'merge', + 'Use `assign`.' + ); + + /** + * simple class inheritance + * @param {Function} child + * @param {Function} base + * @param {Object} [properties] + */ + function inherit(child, base, properties) { + var baseP = base.prototype, + childP; + + childP = child.prototype = Object.create(baseP); + childP.constructor = child; + childP._super = baseP; + + if (properties) { + assign(childP, properties); + } + } + + /** + * simple function bind + * @param {Function} fn + * @param {Object} context + * @returns {Function} + */ + function bindFn(fn, context) { + return function boundFn() { + return fn.apply(context, arguments); + }; + } + + /** + * let a boolean value also be a function that must return a boolean + * this first item in args will be used as the context + * @param {Boolean|Function} val + * @param {Array} [args] + * @returns {Boolean} + */ + function boolOrFn(val, args) { + if (typeof val == TYPE_FUNCTION) { + return val.apply(args ? args[0] || undefined : undefined, args); + } + return val; + } + + /** + * use the val2 when val1 is undefined + * @param {*} val1 + * @param {*} val2 + * @returns {*} + */ + function ifUndefined(val1, val2) { + return val1 === undefined ? val2 : val1; + } + + /** + * addEventListener with multiple events at once + * @param {EventTarget} target + * @param {String} types + * @param {Function} handler + */ + function addEventListeners(target, types, handler) { + each(splitStr(types), function(type) { + target.addEventListener(type, handler, false); + }); + } + + /** + * removeEventListener with multiple events at once + * @param {EventTarget} target + * @param {String} types + * @param {Function} handler + */ + function removeEventListeners(target, types, handler) { + each(splitStr(types), function(type) { + target.removeEventListener(type, handler, false); + }); + } + + /** + * find if a node is in the given parent + * @method hasParent + * @param {HTMLElement} node + * @param {HTMLElement} parent + * @return {Boolean} found + */ + function hasParent(node, parent) { + while (node) { + if (node == parent) { + return true; + } + node = node.parentNode; + } + return false; + } + + /** + * small indexOf wrapper + * @param {String} str + * @param {String} find + * @returns {Boolean} found + */ + function inStr(str, find) { + return str.indexOf(find) > -1; + } + + /** + * split string on whitespace + * @param {String} str + * @returns {Array} words + */ + function splitStr(str) { + return str.trim().split(/\s+/g); + } + + /** + * find if a array contains the object using indexOf or a simple polyFill + * @param {Array} src + * @param {String} find + * @param {String} [findByKey] + * @return {Boolean|Number} false when not found, or the index + */ + function inArray(src, find, findByKey) { + if (src.indexOf && !findByKey) { + return src.indexOf(find); + } else { + var i = 0; + while (i < src.length) { + if ( + (findByKey && src[i][findByKey] == find) || + (!findByKey && src[i] === find) + ) { + return i; + } + i++; + } + return -1; + } + } + + /** + * convert array-like objects to real arrays + * @param {Object} obj + * @returns {Array} + */ + function toArray(obj) { + return Array.prototype.slice.call(obj, 0); + } + + /** + * unique array with objects based on a key (like 'id') or just by the array's value + * @param {Array} src [{id:1},{id:2},{id:1}] + * @param {String} [key] + * @param {Boolean} [sort=False] + * @returns {Array} [{id:1},{id:2}] + */ + function uniqueArray(src, key, sort) { + var results = []; + var values = []; + var i = 0; + + while (i < src.length) { + var val = key ? src[i][key] : src[i]; + if (inArray(values, val) < 0) { + results.push(src[i]); + } + values[i] = val; + i++; + } + + if (sort) { + if (!key) { + results = results.sort(); + } else { + results = results.sort(function sortUniqueArray(a, b) { + return a[key] > b[key]; + }); + } + } + + return results; + } + + /** + * get the prefixed property + * @param {Object} obj + * @param {String} property + * @returns {String|Undefined} prefixed + */ + function prefixed(obj, property) { + var prefix, prop; + var camelProp = property[0].toUpperCase() + property.slice(1); + + var i = 0; + while (i < VENDOR_PREFIXES.length) { + prefix = VENDOR_PREFIXES[i]; + prop = prefix ? prefix + camelProp : property; + + if (prop in obj) { + return prop; + } + i++; + } + return undefined; + } + + /** + * get a unique id + * @returns {number} uniqueId + */ + var _uniqueId = 1; + function uniqueId() { + return _uniqueId++; + } + + /** + * get the window object of an element + * @param {HTMLElement} element + * @returns {DocumentView|Window} + */ + function getWindowForElement(element) { + var doc = element.ownerDocument || element; + return doc.defaultView || doc.parentWindow || window; + } + + var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i; + + var SUPPORT_TOUCH = 'ontouchstart' in window; + + // temporary disable pointer events, because Konva doesn't fully support it yet + // var SUPPORT_POINTER_EVENTS = prefixed(window, 'PointerEvent') !== undefined; + var SUPPORT_POINTER_EVENTS = false; + + // var SUPPORT_ONLY_TOUCH = + // SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent); + var SUPPORT_ONLY_TOUCH = true; + + var INPUT_TYPE_TOUCH = 'touch'; + var INPUT_TYPE_PEN = 'pen'; + var INPUT_TYPE_MOUSE = 'mouse'; + var INPUT_TYPE_KINECT = 'kinect'; + + var COMPUTE_INTERVAL = 25; + + var INPUT_START = 1; + var INPUT_MOVE = 2; + var INPUT_END = 4; + var INPUT_CANCEL = 8; + + var DIRECTION_NONE = 1; + var DIRECTION_LEFT = 2; + var DIRECTION_RIGHT = 4; + var DIRECTION_UP = 8; + var DIRECTION_DOWN = 16; + + var DIRECTION_HORIZONTAL = DIRECTION_LEFT | DIRECTION_RIGHT; + var DIRECTION_VERTICAL = DIRECTION_UP | DIRECTION_DOWN; + var DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL; + + var PROPS_XY = ['x', 'y']; + var PROPS_CLIENT_XY = ['clientX', 'clientY']; + + /** + * create new input type manager + * @param {Manager} manager + * @param {Function} callback + * @returns {Input} + * @constructor + */ + function Input(manager, callback) { + var self = this; + this.manager = manager; + this.callback = callback; + this.element = manager.element; + this.target = manager.options.inputTarget; + + // smaller wrapper around the handler, for the scope and the enabled state of the manager, + // so when disabled the input events are completely bypassed. + this.domHandler = function(ev) { + if (boolOrFn(manager.options.enable, [manager])) { + self.handler(ev); + } + }; + + this.init(); + } + + Input.prototype = { + /** + * should handle the inputEvent data and trigger the callback + * @virtual + */ + handler: function() {}, + + /** + * bind the events + */ + init: function() { + this.evEl && addEventListeners(this.element, this.evEl, this.domHandler); + this.evTarget && + addEventListeners(this.target, this.evTarget, this.domHandler); + this.evWin && + addEventListeners( + getWindowForElement(this.element), + this.evWin, + this.domHandler + ); + }, + + /** + * unbind the events + */ + destroy: function() { + this.evEl && + removeEventListeners(this.element, this.evEl, this.domHandler); + this.evTarget && + removeEventListeners(this.target, this.evTarget, this.domHandler); + this.evWin && + removeEventListeners( + getWindowForElement(this.element), + this.evWin, + this.domHandler + ); + } + }; + + /** + * create new input type manager + * called by the Manager constructor + * @param {Hammer} manager + * @returns {Input} + */ + function createInputInstance(manager) { + var Type; + var inputClass = manager.options.inputClass; + + if (inputClass) { + Type = inputClass; + } else if (SUPPORT_POINTER_EVENTS) { + Type = PointerEventInput; + } else if (SUPPORT_ONLY_TOUCH) { + Type = TouchInput; + } else if (!SUPPORT_TOUCH) { + Type = MouseInput; + } else { + Type = TouchMouseInput; + } + return new Type(manager, inputHandler); + } + + /** + * handle input events + * @param {Manager} manager + * @param {String} eventType + * @param {Object} input + */ + function inputHandler(manager, eventType, input) { + var pointersLen = input.pointers.length; + var changedPointersLen = input.changedPointers.length; + var isFirst = + eventType & INPUT_START && pointersLen - changedPointersLen === 0; + var isFinal = + eventType & (INPUT_END | INPUT_CANCEL) && + pointersLen - changedPointersLen === 0; + + input.isFirst = !!isFirst; + input.isFinal = !!isFinal; + + if (isFirst) { + manager.session = {}; + } + + // source event is the normalized value of the domEvents + // like 'touchstart, mouseup, pointerdown' + input.eventType = eventType; + + // compute scale, rotation etc + computeInputData(manager, input); + + // emit secret event + manager.emit('hammer.input', input); + + manager.recognize(input); + manager.session.prevInput = input; + } + + /** + * extend the data with some usable properties like scale, rotate, velocity etc + * @param {Object} manager + * @param {Object} input + */ + function computeInputData(manager, input) { + var session = manager.session; + var pointers = input.pointers; + var pointersLength = pointers.length; + + // store the first input to calculate the distance and direction + if (!session.firstInput) { + session.firstInput = simpleCloneInputData(input); + } + + // to compute scale and rotation we need to store the multiple touches + if (pointersLength > 1 && !session.firstMultiple) { + session.firstMultiple = simpleCloneInputData(input); + } else if (pointersLength === 1) { + session.firstMultiple = false; + } + + var firstInput = session.firstInput; + var firstMultiple = session.firstMultiple; + var offsetCenter = firstMultiple ? firstMultiple.center : firstInput.center; + + var center = (input.center = getCenter(pointers)); + input.timeStamp = now(); + input.deltaTime = input.timeStamp - firstInput.timeStamp; + + input.angle = getAngle(offsetCenter, center); + input.distance = getDistance(offsetCenter, center); + + computeDeltaXY(session, input); + input.offsetDirection = getDirection(input.deltaX, input.deltaY); + + var overallVelocity = getVelocity( + input.deltaTime, + input.deltaX, + input.deltaY + ); + input.overallVelocityX = overallVelocity.x; + input.overallVelocityY = overallVelocity.y; + input.overallVelocity = + abs(overallVelocity.x) > abs(overallVelocity.y) + ? overallVelocity.x + : overallVelocity.y; + + input.scale = firstMultiple + ? getScale(firstMultiple.pointers, pointers) + : 1; + input.rotation = firstMultiple + ? getRotation(firstMultiple.pointers, pointers) + : 0; + + input.maxPointers = !session.prevInput + ? input.pointers.length + : input.pointers.length > session.prevInput.maxPointers + ? input.pointers.length + : session.prevInput.maxPointers; + + computeIntervalInputData(session, input); + + // find the correct target + var target = manager.element; + if (hasParent(input.srcEvent.target, target)) { + target = input.srcEvent.target; + } + input.target = target; + } + + function computeDeltaXY(session, input) { + var center = input.center; + var offset = session.offsetDelta || {}; + var prevDelta = session.prevDelta || {}; + var prevInput = session.prevInput || {}; + + if (input.eventType === INPUT_START || prevInput.eventType === INPUT_END) { + prevDelta = session.prevDelta = { + x: prevInput.deltaX || 0, + y: prevInput.deltaY || 0 + }; + + offset = session.offsetDelta = { + x: center.x, + y: center.y + }; + } + + input.deltaX = prevDelta.x + (center.x - offset.x); + input.deltaY = prevDelta.y + (center.y - offset.y); + } + + /** + * velocity is calculated every x ms + * @param {Object} session + * @param {Object} input + */ + function computeIntervalInputData(session, input) { + var last = session.lastInterval || input, + deltaTime = input.timeStamp - last.timeStamp, + velocity, + velocityX, + velocityY, + direction; + + if ( + input.eventType != INPUT_CANCEL && + (deltaTime > COMPUTE_INTERVAL || last.velocity === undefined) + ) { + var deltaX = input.deltaX - last.deltaX; + var deltaY = input.deltaY - last.deltaY; + + var v = getVelocity(deltaTime, deltaX, deltaY); + velocityX = v.x; + velocityY = v.y; + velocity = abs(v.x) > abs(v.y) ? v.x : v.y; + direction = getDirection(deltaX, deltaY); + + session.lastInterval = input; + } else { + // use latest velocity info if it doesn't overtake a minimum period + velocity = last.velocity; + velocityX = last.velocityX; + velocityY = last.velocityY; + direction = last.direction; + } + + input.velocity = velocity; + input.velocityX = velocityX; + input.velocityY = velocityY; + input.direction = direction; + } + + /** + * create a simple clone from the input used for storage of firstInput and firstMultiple + * @param {Object} input + * @returns {Object} clonedInputData + */ + function simpleCloneInputData(input) { + // make a simple copy of the pointers because we will get a reference if we don't + // we only need clientXY for the calculations + var pointers = []; + var i = 0; + while (i < input.pointers.length) { + pointers[i] = { + clientX: round(input.pointers[i].clientX), + clientY: round(input.pointers[i].clientY) + }; + i++; + } + + return { + timeStamp: now(), + pointers: pointers, + center: getCenter(pointers), + deltaX: input.deltaX, + deltaY: input.deltaY + }; + } + + /** + * get the center of all the pointers + * @param {Array} pointers + * @return {Object} center contains `x` and `y` properties + */ + function getCenter(pointers) { + var pointersLength = pointers.length; + + // no need to loop when only one touch + if (pointersLength === 1) { + return { + x: round(pointers[0].clientX), + y: round(pointers[0].clientY) + }; + } + + var x = 0, + y = 0, + i = 0; + while (i < pointersLength) { + x += pointers[i].clientX; + y += pointers[i].clientY; + i++; + } + + return { + x: round(x / pointersLength), + y: round(y / pointersLength) + }; + } + + /** + * calculate the velocity between two points. unit is in px per ms. + * @param {Number} deltaTime + * @param {Number} x + * @param {Number} y + * @return {Object} velocity `x` and `y` + */ + function getVelocity(deltaTime, x, y) { + return { + x: x / deltaTime || 0, + y: y / deltaTime || 0 + }; + } + + /** + * get the direction between two points + * @param {Number} x + * @param {Number} y + * @return {Number} direction + */ + function getDirection(x, y) { + if (x === y) { + return DIRECTION_NONE; + } + + if (abs(x) >= abs(y)) { + return x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT; + } + return y < 0 ? DIRECTION_UP : DIRECTION_DOWN; + } + + /** + * calculate the absolute distance between two points + * @param {Object} p1 {x, y} + * @param {Object} p2 {x, y} + * @param {Array} [props] containing x and y keys + * @return {Number} distance + */ + function getDistance(p1, p2, props) { + if (!props) { + props = PROPS_XY; + } + var x = p2[props[0]] - p1[props[0]], + y = p2[props[1]] - p1[props[1]]; + + return Math.sqrt(x * x + y * y); + } + + /** + * calculate the angle between two coordinates + * @param {Object} p1 + * @param {Object} p2 + * @param {Array} [props] containing x and y keys + * @return {Number} angle + */ + function getAngle(p1, p2, props) { + if (!props) { + props = PROPS_XY; + } + var x = p2[props[0]] - p1[props[0]], + y = p2[props[1]] - p1[props[1]]; + return (Math.atan2(y, x) * 180) / Math.PI; + } + + /** + * calculate the rotation degrees between two pointersets + * @param {Array} start array of pointers + * @param {Array} end array of pointers + * @return {Number} rotation + */ + function getRotation(start, end) { + return ( + getAngle(end[1], end[0], PROPS_CLIENT_XY) + + getAngle(start[1], start[0], PROPS_CLIENT_XY) + ); + } + + /** + * calculate the scale factor between two pointersets + * no scale is 1, and goes down to 0 when pinched together, and bigger when pinched out + * @param {Array} start array of pointers + * @param {Array} end array of pointers + * @return {Number} scale + */ + function getScale(start, end) { + return ( + getDistance(end[0], end[1], PROPS_CLIENT_XY) / + getDistance(start[0], start[1], PROPS_CLIENT_XY) + ); + } + + var MOUSE_INPUT_MAP = { + mousedown: INPUT_START, + mousemove: INPUT_MOVE, + mouseup: INPUT_END + }; + + var MOUSE_ELEMENT_EVENTS = 'mousedown'; + var MOUSE_WINDOW_EVENTS = 'mousemove mouseup'; + + /** + * Mouse events input + * @constructor + * @extends Input + */ + function MouseInput() { + this.evEl = MOUSE_ELEMENT_EVENTS; + this.evWin = MOUSE_WINDOW_EVENTS; + + this.pressed = false; // mousedown state + + Input.apply(this, arguments); + } + + inherit(MouseInput, Input, { + /** + * handle mouse events + * @param {Object} ev + */ + handler: function MEhandler(ev) { + var eventType = MOUSE_INPUT_MAP[ev.type]; + + // on start we want to have the left mouse button down + if (eventType & INPUT_START && ev.button === 0) { + this.pressed = true; + } + + if (eventType & INPUT_MOVE && ev.which !== 1) { + eventType = INPUT_END; + } + + // mouse must be down + if (!this.pressed) { + return; + } + + if (eventType & INPUT_END) { + this.pressed = false; + } + + this.callback(this.manager, eventType, { + pointers: [ev], + changedPointers: [ev], + pointerType: INPUT_TYPE_MOUSE, + srcEvent: ev + }); + } + }); + + var POINTER_INPUT_MAP = { + pointerdown: INPUT_START, + pointermove: INPUT_MOVE, + pointerup: INPUT_END, + pointercancel: INPUT_CANCEL, + pointerout: INPUT_CANCEL + }; + + // in IE10 the pointer types is defined as an enum + var IE10_POINTER_TYPE_ENUM = { + 2: INPUT_TYPE_TOUCH, + 3: INPUT_TYPE_PEN, + 4: INPUT_TYPE_MOUSE, + 5: INPUT_TYPE_KINECT // see https://twitter.com/jacobrossi/status/480596438489890816 + }; + + var POINTER_ELEMENT_EVENTS = 'pointerdown'; + var POINTER_WINDOW_EVENTS = 'pointermove pointerup pointercancel'; + + // IE10 has prefixed support, and case-sensitive + if (window.MSPointerEvent && !window.PointerEvent) { + POINTER_ELEMENT_EVENTS = 'MSPointerDown'; + POINTER_WINDOW_EVENTS = 'MSPointerMove MSPointerUp MSPointerCancel'; + } + + /** + * Pointer events input + * @constructor + * @extends Input + */ + function PointerEventInput() { + this.evEl = POINTER_ELEMENT_EVENTS; + this.evWin = POINTER_WINDOW_EVENTS; + + Input.apply(this, arguments); + + this.store = this.manager.session.pointerEvents = []; + } + + inherit(PointerEventInput, Input, { + /** + * handle mouse events + * @param {Object} ev + */ + handler: function PEhandler(ev) { + var store = this.store; + var removePointer = false; + + var eventTypeNormalized = ev.type.toLowerCase().replace('ms', ''); + var eventType = POINTER_INPUT_MAP[eventTypeNormalized]; + var pointerType = + IE10_POINTER_TYPE_ENUM[ev.pointerType] || ev.pointerType; + + var isTouch = pointerType == INPUT_TYPE_TOUCH; + + // get index of the event in the store + var storeIndex = inArray(store, ev.pointerId, 'pointerId'); + + // start and mouse must be down + if (eventType & INPUT_START && (ev.button === 0 || isTouch)) { + if (storeIndex < 0) { + store.push(ev); + storeIndex = store.length - 1; + } + } else if (eventType & (INPUT_END | INPUT_CANCEL)) { + removePointer = true; + } + + // it not found, so the pointer hasn't been down (so it's probably a hover) + if (storeIndex < 0) { + return; + } + + // update the event in the store + store[storeIndex] = ev; + + this.callback(this.manager, eventType, { + pointers: store, + changedPointers: [ev], + pointerType: pointerType, + srcEvent: ev + }); + + if (removePointer) { + // remove from the store + store.splice(storeIndex, 1); + } + } + }); + + var SINGLE_TOUCH_INPUT_MAP = { + touchstart: INPUT_START, + touchmove: INPUT_MOVE, + touchend: INPUT_END, + touchcancel: INPUT_CANCEL + }; + + var SINGLE_TOUCH_TARGET_EVENTS = 'touchstart'; + var SINGLE_TOUCH_WINDOW_EVENTS = 'touchstart touchmove touchend touchcancel'; + + /** + * Touch events input + * @constructor + * @extends Input + */ + function SingleTouchInput() { + this.evTarget = SINGLE_TOUCH_TARGET_EVENTS; + this.evWin = SINGLE_TOUCH_WINDOW_EVENTS; + this.started = false; + + Input.apply(this, arguments); + } + + inherit(SingleTouchInput, Input, { + handler: function TEhandler(ev) { + var type = SINGLE_TOUCH_INPUT_MAP[ev.type]; + + // should we handle the touch events? + if (type === INPUT_START) { + this.started = true; + } + + if (!this.started) { + return; + } + + var touches = normalizeSingleTouches.call(this, ev, type); + + // when done, reset the started state + if ( + type & (INPUT_END | INPUT_CANCEL) && + touches[0].length - touches[1].length === 0 + ) { + this.started = false; + } + + this.callback(this.manager, type, { + pointers: touches[0], + changedPointers: touches[1], + pointerType: INPUT_TYPE_TOUCH, + srcEvent: ev + }); + } + }); + + /** + * @this {TouchInput} + * @param {Object} ev + * @param {Number} type flag + * @returns {undefined|Array} [all, changed] + */ + function normalizeSingleTouches(ev, type) { + var all = toArray(ev.touches); + var changed = toArray(ev.changedTouches); + + if (type & (INPUT_END | INPUT_CANCEL)) { + all = uniqueArray(all.concat(changed), 'identifier', true); + } + + return [all, changed]; + } + + var TOUCH_INPUT_MAP = { + touchstart: INPUT_START, + touchmove: INPUT_MOVE, + touchend: INPUT_END, + touchcancel: INPUT_CANCEL + }; + + var TOUCH_TARGET_EVENTS = 'touchstart touchmove touchend touchcancel'; + + /** + * Multi-user touch events input + * @constructor + * @extends Input + */ + function TouchInput() { + this.evTarget = TOUCH_TARGET_EVENTS; + this.targetIds = {}; + + Input.apply(this, arguments); + } + + inherit(TouchInput, Input, { + handler: function MTEhandler(ev) { + var type = TOUCH_INPUT_MAP[ev.type]; + var touches = getTouches.call(this, ev, type); + if (!touches) { + return; + } + + this.callback(this.manager, type, { + pointers: touches[0], + changedPointers: touches[1], + pointerType: INPUT_TYPE_TOUCH, + srcEvent: ev + }); + } + }); + + /** + * @this {TouchInput} + * @param {Object} ev + * @param {Number} type flag + * @returns {undefined|Array} [all, changed] + */ + function getTouches(ev, type) { + var allTouches = toArray(ev.touches); + var targetIds = this.targetIds; + + // when there is only one touch, the process can be simplified + if (type & (INPUT_START | INPUT_MOVE) && allTouches.length === 1) { + targetIds[allTouches[0].identifier] = true; + return [allTouches, allTouches]; + } + + var i, + targetTouches, + changedTouches = toArray(ev.changedTouches), + changedTargetTouches = [], + target = this.target; + + // get target touches from touches + targetTouches = allTouches.filter(function(touch) { + return true; + }); + + // collect touches + if (type === INPUT_START) { + i = 0; + while (i < targetTouches.length) { + targetIds[targetTouches[i].identifier] = true; + i++; + } + } + + // filter changed touches to only contain touches that exist in the collected target ids + i = 0; + while (i < changedTouches.length) { + if (targetIds[changedTouches[i].identifier]) { + changedTargetTouches.push(changedTouches[i]); + } + + // cleanup removed touches + if (type & (INPUT_END | INPUT_CANCEL)) { + delete targetIds[changedTouches[i].identifier]; + } + i++; + } + + if (!changedTargetTouches.length) { + return; + } + + return [ + // merge targetTouches with changedTargetTouches so it contains ALL touches, including 'end' and 'cancel' + uniqueArray( + targetTouches.concat(changedTargetTouches), + 'identifier', + true + ), + changedTargetTouches + ]; + } + + /** + * Combined touch and mouse input + * + * Touch has a higher priority then mouse, and while touching no mouse events are allowed. + * This because touch devices also emit mouse events while doing a touch. + * + * @constructor + * @extends Input + */ + + var DEDUP_TIMEOUT = 2500; + var DED_DISTANCE = 25; + + function TouchMouseInput() { + Input.apply(this, arguments); + + var handler = bindFn(this.handler, this); + this.touch = new TouchInput(this.manager, handler); + this.mouse = new MouseInput(this.manager, handler); + + this.primaryTouch = null; + this.lastTouches = []; + } + + inherit(TouchMouseInput, Input, { + /** + * handle mouse and touch events + * @param {Hammer} manager + * @param {String} inputEvent + * @param {Object} inputData + */ + handler: function TMEhandler(manager, inputEvent, inputData) { + var isTouch = inputData.pointerType == INPUT_TYPE_TOUCH, + isMouse = inputData.pointerType == INPUT_TYPE_MOUSE; + + if ( + isMouse && + inputData.sourceCapabilities && + inputData.sourceCapabilities.firesTouchEvents + ) { + return; + } + + // when we're in a touch event, record touches to de-dupe synthetic mouse event + if (isTouch) { + recordTouches.call(this, inputEvent, inputData); + } else if (isMouse && isSyntheticEvent.call(this, inputData)) { + return; + } + + this.callback(manager, inputEvent, inputData); + }, + + /** + * remove the event listeners + */ + destroy: function destroy() { + this.touch.destroy(); + this.mouse.destroy(); + } + }); + + function recordTouches(eventType, eventData) { + if (eventType & INPUT_START) { + this.primaryTouch = eventData.changedPointers[0].identifier; + setLastTouch.call(this, eventData); + } else if (eventType & (INPUT_END | INPUT_CANCEL)) { + setLastTouch.call(this, eventData); + } + } + + function setLastTouch(eventData) { + var touch = eventData.changedPointers[0]; + + if (touch.identifier === this.primaryTouch) { + var lastTouch = { x: touch.clientX, y: touch.clientY }; + this.lastTouches.push(lastTouch); + var lts = this.lastTouches; + var removeLastTouch = function() { + var i = lts.indexOf(lastTouch); + if (i > -1) { + lts.splice(i, 1); + } + }; + setTimeout(removeLastTouch, DEDUP_TIMEOUT); + } + } + + function isSyntheticEvent(eventData) { + var x = eventData.srcEvent.clientX, + y = eventData.srcEvent.clientY; + for (var i = 0; i < this.lastTouches.length; i++) { + var t = this.lastTouches[i]; + var dx = Math.abs(x - t.x), + dy = Math.abs(y - t.y); + if (dx <= DEDUP_DISTANCE && dy <= DEDUP_DISTANCE) { + return true; + } + } + return false; + } + + var PREFIXED_TOUCH_ACTION = prefixed(TEST_ELEMENT.style, 'touchAction'); + var NATIVE_TOUCH_ACTION = PREFIXED_TOUCH_ACTION !== undefined; + + // magical touchAction value + var TOUCH_ACTION_COMPUTE = 'compute'; + var TOUCH_ACTION_AUTO = 'auto'; + var TOUCH_ACTION_MANIPULATION = 'manipulation'; // not implemented + var TOUCH_ACTION_NONE = 'none'; + var TOUCH_ACTION_PAN_X = 'pan-x'; + var TOUCH_ACTION_PAN_Y = 'pan-y'; + var TOUCH_ACTION_MAP = getTouchActionProps(); + + /** + * Touch Action + * sets the touchAction property or uses the js alternative + * @param {Manager} manager + * @param {String} value + * @constructor + */ + function TouchAction(manager, value) { + this.manager = manager; + this.set(value); + } + + TouchAction.prototype = { + /** + * set the touchAction value on the element or enable the polyfill + * @param {String} value + */ + set: function(value) { + // find out the touch-action by the event handlers + if (value == TOUCH_ACTION_COMPUTE) { + value = this.compute(); + } + + if ( + NATIVE_TOUCH_ACTION && + this.manager.element.style && + TOUCH_ACTION_MAP[value] + ) { + this.manager.element.style[PREFIXED_TOUCH_ACTION] = value; + } + this.actions = value.toLowerCase().trim(); + }, + + /** + * just re-set the touchAction value + */ + update: function() { + this.set(this.manager.options.touchAction); + }, + + /** + * compute the value for the touchAction property based on the recognizer's settings + * @returns {String} value + */ + compute: function() { + var actions = []; + each(this.manager.recognizers, function(recognizer) { + if (boolOrFn(recognizer.options.enable, [recognizer])) { + actions = actions.concat(recognizer.getTouchAction()); + } + }); + return cleanTouchActions(actions.join(' ')); + }, + + /** + * this method is called on each input cycle and provides the preventing of the browser behavior + * @param {Object} input + */ + preventDefaults: function(input) { + var srcEvent = input.srcEvent; + var direction = input.offsetDirection; + + // if the touch action did prevented once this session + if (this.manager.session.prevented) { + srcEvent.preventDefault(); + return; + } + + var actions = this.actions; + var hasNone = + inStr(actions, TOUCH_ACTION_NONE) && + !TOUCH_ACTION_MAP[TOUCH_ACTION_NONE]; + var hasPanY = + inStr(actions, TOUCH_ACTION_PAN_Y) && + !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_Y]; + var hasPanX = + inStr(actions, TOUCH_ACTION_PAN_X) && + !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_X]; + + if (hasNone) { + //do not prevent defaults if this is a tap gesture + + var isTapPointer = input.pointers.length === 1; + var isTapMovement = input.distance < 2; + var isTapTouchTime = input.deltaTime < 250; + + if (isTapPointer && isTapMovement && isTapTouchTime) { + return; + } + } + + if (hasPanX && hasPanY) { + // `pan-x pan-y` means browser handles all scrolling/panning, do not prevent + return; + } + + if ( + hasNone || + (hasPanY && direction & DIRECTION_HORIZONTAL) || + (hasPanX && direction & DIRECTION_VERTICAL) + ) { + return this.preventSrc(srcEvent); + } + }, + + /** + * call preventDefault to prevent the browser's default behavior (scrolling in most cases) + * @param {Object} srcEvent + */ + preventSrc: function(srcEvent) { + this.manager.session.prevented = true; + srcEvent.preventDefault(); + } + }; + + /** + * when the touchActions are collected they are not a valid value, so we need to clean things up. * + * @param {String} actions + * @returns {*} + */ + function cleanTouchActions(actions) { + // none + if (inStr(actions, TOUCH_ACTION_NONE)) { + return TOUCH_ACTION_NONE; + } + + var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X); + var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y); + + // if both pan-x and pan-y are set (different recognizers + // for different directions, e.g. horizontal pan but vertical swipe?) + // we need none (as otherwise with pan-x pan-y combined none of these + // recognizers will work, since the browser would handle all panning + if (hasPanX && hasPanY) { + return TOUCH_ACTION_NONE; + } + + // pan-x OR pan-y + if (hasPanX || hasPanY) { + return hasPanX ? TOUCH_ACTION_PAN_X : TOUCH_ACTION_PAN_Y; + } + + // manipulation + if (inStr(actions, TOUCH_ACTION_MANIPULATION)) { + return TOUCH_ACTION_MANIPULATION; + } + + return TOUCH_ACTION_AUTO; + } + + function getTouchActionProps() { + if (!NATIVE_TOUCH_ACTION) { + return false; + } + var touchMap = {}; + var cssSupports = window.CSS && window.CSS.supports; + ['auto', 'manipulation', 'pan-y', 'pan-x', 'pan-x pan-y', 'none'].forEach( + function(val) { + // If css.supports is not supported but there is native touch-action assume it supports + // all values. This is the case for IE 10 and 11. + touchMap[val] = cssSupports + ? window.CSS.supports('touch-action', val) + : true; + } + ); + return touchMap; + } + + /** + * Recognizer flow explained; * + * All recognizers have the initial state of POSSIBLE when a input session starts. + * The definition of a input session is from the first input until the last input, with all it's movement in it. * + * Example session for mouse-input: mousedown -> mousemove -> mouseup + * + * On each recognizing cycle (see Manager.recognize) the .recognize() method is executed + * which determines with state it should be. + * + * If the recognizer has the state FAILED, CANCELLED or RECOGNIZED (equals ENDED), it is reset to + * POSSIBLE to give it another change on the next cycle. + * + * Possible + * | + * +-----+---------------+ + * | | + * +-----+-----+ | + * | | | + * Failed Cancelled | + * +-------+------+ + * | | + * Recognized Began + * | + * Changed + * | + * Ended/Recognized + */ + var STATE_POSSIBLE = 1; + var STATE_BEGAN = 2; + var STATE_CHANGED = 4; + var STATE_ENDED = 8; + var STATE_RECOGNIZED = STATE_ENDED; + var STATE_CANCELLED = 16; + var STATE_FAILED = 32; + + /** + * Recognizer + * Every recognizer needs to extend from this class. + * @constructor + * @param {Object} options + */ + function Recognizer(options) { + this.options = assign({}, this.defaults, options || {}); + + this.id = uniqueId(); + + this.manager = null; + + // default is enable true + this.options.enable = ifUndefined(this.options.enable, true); + + this.state = STATE_POSSIBLE; + + this.simultaneous = {}; + this.requireFail = []; + } + + Recognizer.prototype = { + /** + * @virtual + * @type {Object} + */ + defaults: {}, + + /** + * set options + * @param {Object} options + * @return {Recognizer} + */ + set: function(options) { + assign(this.options, options); + + // also update the touchAction, in case something changed about the directions/enabled state + this.manager && this.manager.touchAction.update(); + return this; + }, + + /** + * recognize simultaneous with an other recognizer. + * @param {Recognizer} otherRecognizer + * @returns {Recognizer} this + */ + recognizeWith: function(otherRecognizer) { + if (invokeArrayArg(otherRecognizer, 'recognizeWith', this)) { + return this; + } + + var simultaneous = this.simultaneous; + otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this); + if (!simultaneous[otherRecognizer.id]) { + simultaneous[otherRecognizer.id] = otherRecognizer; + otherRecognizer.recognizeWith(this); + } + return this; + }, + + /** + * drop the simultaneous link. it doesnt remove the link on the other recognizer. + * @param {Recognizer} otherRecognizer + * @returns {Recognizer} this + */ + dropRecognizeWith: function(otherRecognizer) { + if (invokeArrayArg(otherRecognizer, 'dropRecognizeWith', this)) { + return this; + } + + otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this); + delete this.simultaneous[otherRecognizer.id]; + return this; + }, + + /** + * recognizer can only run when an other is failing + * @param {Recognizer} otherRecognizer + * @returns {Recognizer} this + */ + requireFailure: function(otherRecognizer) { + if (invokeArrayArg(otherRecognizer, 'requireFailure', this)) { + return this; + } + + var requireFail = this.requireFail; + otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this); + if (inArray(requireFail, otherRecognizer) === -1) { + requireFail.push(otherRecognizer); + otherRecognizer.requireFailure(this); + } + return this; + }, + + /** + * drop the requireFailure link. it does not remove the link on the other recognizer. + * @param {Recognizer} otherRecognizer + * @returns {Recognizer} this + */ + dropRequireFailure: function(otherRecognizer) { + if (invokeArrayArg(otherRecognizer, 'dropRequireFailure', this)) { + return this; + } + + otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this); + var index = inArray(this.requireFail, otherRecognizer); + if (index > -1) { + this.requireFail.splice(index, 1); + } + return this; + }, + + /** + * has require failures boolean + * @returns {boolean} + */ + hasRequireFailures: function() { + return this.requireFail.length > 0; + }, + + /** + * if the recognizer can recognize simultaneous with an other recognizer + * @param {Recognizer} otherRecognizer + * @returns {Boolean} + */ + canRecognizeWith: function(otherRecognizer) { + return !!this.simultaneous[otherRecognizer.id]; + }, + + /** + * You should use `tryEmit` instead of `emit` directly to check + * that all the needed recognizers has failed before emitting. + * @param {Object} input + */ + emit: function(input) { + var self = this; + var state = this.state; + + function emit(event) { + self.manager.emit(event, input); + } + + // 'panstart' and 'panmove' + if (state < STATE_ENDED) { + emit(self.options.event + stateStr(state)); + } + + emit(self.options.event); // simple 'eventName' events + + if (input.additionalEvent) { + // additional event(panleft, panright, pinchin, pinchout...) + emit(input.additionalEvent); + } + + // panend and pancancel + if (state >= STATE_ENDED) { + emit(self.options.event + stateStr(state)); + } + }, + + /** + * Check that all the require failure recognizers has failed, + * if true, it emits a gesture event, + * otherwise, setup the state to FAILED. + * @param {Object} input + */ + tryEmit: function(input) { + if (this.canEmit()) { + return this.emit(input); + } + // it's failing anyway + this.state = STATE_FAILED; + }, + + /** + * can we emit? + * @returns {boolean} + */ + canEmit: function() { + var i = 0; + while (i < this.requireFail.length) { + if (!(this.requireFail[i].state & (STATE_FAILED | STATE_POSSIBLE))) { + return false; + } + i++; + } + return true; + }, + + /** + * update the recognizer + * @param {Object} inputData + */ + recognize: function(inputData) { + // make a new copy of the inputData + // so we can change the inputData without messing up the other recognizers + var inputDataClone = assign({}, inputData); + + // is is enabled and allow recognizing? + if (!boolOrFn(this.options.enable, [this, inputDataClone])) { + this.reset(); + this.state = STATE_FAILED; + return; + } + + // reset when we've reached the end + if (this.state & (STATE_RECOGNIZED | STATE_CANCELLED | STATE_FAILED)) { + this.state = STATE_POSSIBLE; + } + + this.state = this.process(inputDataClone); + + // the recognizer has recognized a gesture + // so trigger an event + if ( + this.state & + (STATE_BEGAN | STATE_CHANGED | STATE_ENDED | STATE_CANCELLED) + ) { + this.tryEmit(inputDataClone); + } + }, + + /** + * return the state of the recognizer + * the actual recognizing happens in this method + * @virtual + * @param {Object} inputData + * @returns {Const} STATE + */ + process: function(inputData) {}, // jshint ignore:line + + /** + * return the preferred touch-action + * @virtual + * @returns {Array} + */ + getTouchAction: function() {}, + + /** + * called when the gesture isn't allowed to recognize + * like when another is being recognized or it is disabled + * @virtual + */ + reset: function() {} + }; + + /** + * get a usable string, used as event postfix + * @param {Const} state + * @returns {String} state + */ + function stateStr(state) { + if (state & STATE_CANCELLED) { + return 'cancel'; + } else if (state & STATE_ENDED) { + return 'end'; + } else if (state & STATE_CHANGED) { + return 'move'; + } else if (state & STATE_BEGAN) { + return 'start'; + } + return ''; + } + + /** + * direction cons to string + * @param {Const} direction + * @returns {String} + */ + function directionStr(direction) { + if (direction == DIRECTION_DOWN) { + return 'down'; + } else if (direction == DIRECTION_UP) { + return 'up'; + } else if (direction == DIRECTION_LEFT) { + return 'left'; + } else if (direction == DIRECTION_RIGHT) { + return 'right'; + } + return ''; + } + + /** + * get a recognizer by name if it is bound to a manager + * @param {Recognizer|String} otherRecognizer + * @param {Recognizer} recognizer + * @returns {Recognizer} + */ + function getRecognizerByNameIfManager(otherRecognizer, recognizer) { + var manager = recognizer.manager; + if (manager) { + return manager.get(otherRecognizer); + } + return otherRecognizer; + } + + /** + * This recognizer is just used as a base for the simple attribute recognizers. + * @constructor + * @extends Recognizer + */ + function AttrRecognizer() { + Recognizer.apply(this, arguments); + } + + inherit(AttrRecognizer, Recognizer, { + /** + * @namespace + * @memberof AttrRecognizer + */ + defaults: { + /** + * @type {Number} + * @default 1 + */ + pointers: 1 + }, + + /** + * Used to check if it the recognizer receives valid input, like input.distance > 10. + * @memberof AttrRecognizer + * @param {Object} input + * @returns {Boolean} recognized + */ + attrTest: function(input) { + var optionPointers = this.options.pointers; + return optionPointers === 0 || input.pointers.length === optionPointers; + }, + + /** + * Process the input and return the state for the recognizer + * @memberof AttrRecognizer + * @param {Object} input + * @returns {*} State + */ + process: function(input) { + var state = this.state; + var eventType = input.eventType; + + var isRecognized = state & (STATE_BEGAN | STATE_CHANGED); + var isValid = this.attrTest(input); + + // on cancel input and we've recognized before, return STATE_CANCELLED + if (isRecognized && (eventType & INPUT_CANCEL || !isValid)) { + return state | STATE_CANCELLED; + } else if (isRecognized || isValid) { + if (eventType & INPUT_END) { + return state | STATE_ENDED; + } else if (!(state & STATE_BEGAN)) { + return STATE_BEGAN; + } + return state | STATE_CHANGED; + } + return STATE_FAILED; + } + }); + + /** + * Pan + * Recognized when the pointer is down and moved in the allowed direction. + * @constructor + * @extends AttrRecognizer + */ + function PanRecognizer() { + AttrRecognizer.apply(this, arguments); + + this.pX = null; + this.pY = null; + } + + inherit(PanRecognizer, AttrRecognizer, { + /** + * @namespace + * @memberof PanRecognizer + */ + defaults: { + event: 'pan', + threshold: 10, + pointers: 1, + direction: DIRECTION_ALL + }, + + getTouchAction: function() { + var direction = this.options.direction; + var actions = []; + if (direction & DIRECTION_HORIZONTAL) { + actions.push(TOUCH_ACTION_PAN_Y); + } + if (direction & DIRECTION_VERTICAL) { + actions.push(TOUCH_ACTION_PAN_X); + } + return actions; + }, + + directionTest: function(input) { + var options = this.options; + var hasMoved = true; + var distance = input.distance; + var direction = input.direction; + var x = input.deltaX; + var y = input.deltaY; + + // lock to axis? + if (!(direction & options.direction)) { + if (options.direction & DIRECTION_HORIZONTAL) { + direction = + x === 0 ? DIRECTION_NONE : x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT; + hasMoved = x != this.pX; + distance = Math.abs(input.deltaX); + } else { + direction = + y === 0 ? DIRECTION_NONE : y < 0 ? DIRECTION_UP : DIRECTION_DOWN; + hasMoved = y != this.pY; + distance = Math.abs(input.deltaY); + } + } + input.direction = direction; + return ( + hasMoved && + distance > options.threshold && + direction & options.direction + ); + }, + + attrTest: function(input) { + return ( + AttrRecognizer.prototype.attrTest.call(this, input) && + (this.state & STATE_BEGAN || + (!(this.state & STATE_BEGAN) && this.directionTest(input))) + ); + }, + + emit: function(input) { + this.pX = input.deltaX; + this.pY = input.deltaY; + + var direction = directionStr(input.direction); + + if (direction) { + input.additionalEvent = this.options.event + direction; + } + this._super.emit.call(this, input); + } + }); + + /** + * Pinch + * Recognized when two or more pointers are moving toward (zoom-in) or away from each other (zoom-out). + * @constructor + * @extends AttrRecognizer + */ + function PinchRecognizer() { + AttrRecognizer.apply(this, arguments); + } + + inherit(PinchRecognizer, AttrRecognizer, { + /** + * @namespace + * @memberof PinchRecognizer + */ + defaults: { + event: 'pinch', + threshold: 0, + pointers: 2 + }, + + getTouchAction: function() { + return [TOUCH_ACTION_NONE]; + }, + + attrTest: function(input) { + return ( + this._super.attrTest.call(this, input) && + (Math.abs(input.scale - 1) > this.options.threshold || + this.state & STATE_BEGAN) + ); + }, + + emit: function(input) { + if (input.scale !== 1) { + var inOut = input.scale < 1 ? 'in' : 'out'; + input.additionalEvent = this.options.event + inOut; + } + this._super.emit.call(this, input); + } + }); + + /** + * Press + * Recognized when the pointer is down for x ms without any movement. + * @constructor + * @extends Recognizer + */ + function PressRecognizer() { + Recognizer.apply(this, arguments); + + this._timer = null; + this._input = null; + } + + inherit(PressRecognizer, Recognizer, { + /** + * @namespace + * @memberof PressRecognizer + */ + defaults: { + event: 'press', + pointers: 1, + time: 251, // minimal time of the pointer to be pressed + threshold: 9 // a minimal movement is ok, but keep it low + }, + + getTouchAction: function() { + return [TOUCH_ACTION_AUTO]; + }, + + process: function(input) { + var options = this.options; + var validPointers = input.pointers.length === options.pointers; + var validMovement = input.distance < options.threshold; + var validTime = input.deltaTime > options.time; + + this._input = input; + + // we only allow little movement + // and we've reached an end event, so a tap is possible + if ( + !validMovement || + !validPointers || + (input.eventType & (INPUT_END | INPUT_CANCEL) && !validTime) + ) { + this.reset(); + } else if (input.eventType & INPUT_START) { + this.reset(); + this._timer = setTimeoutContext( + function() { + this.state = STATE_RECOGNIZED; + this.tryEmit(); + }, + options.time, + this + ); + } else if (input.eventType & INPUT_END) { + return STATE_RECOGNIZED; + } + return STATE_FAILED; + }, + + reset: function() { + clearTimeout(this._timer); + }, + + emit: function(input) { + if (this.state !== STATE_RECOGNIZED) { + return; + } + + if (input && input.eventType & INPUT_END) { + this.manager.emit(this.options.event + 'up', input); + } else { + this._input.timeStamp = now(); + this.manager.emit(this.options.event, this._input); + } + } + }); + + /** + * Rotate + * Recognized when two or more pointer are moving in a circular motion. + * @constructor + * @extends AttrRecognizer + */ + function RotateRecognizer() { + AttrRecognizer.apply(this, arguments); + } + + inherit(RotateRecognizer, AttrRecognizer, { + /** + * @namespace + * @memberof RotateRecognizer + */ + defaults: { + event: 'rotate', + threshold: 0, + pointers: 2 + }, + + getTouchAction: function() { + return [TOUCH_ACTION_NONE]; + }, + + attrTest: function(input) { + return ( + this._super.attrTest.call(this, input) && + (Math.abs(input.rotation) > this.options.threshold || + this.state & STATE_BEGAN) + ); + } + }); + + /** + * Swipe + * Recognized when the pointer is moving fast (velocity), with enough distance in the allowed direction. + * @constructor + * @extends AttrRecognizer + */ + function SwipeRecognizer() { + AttrRecognizer.apply(this, arguments); + } + + inherit(SwipeRecognizer, AttrRecognizer, { + /** + * @namespace + * @memberof SwipeRecognizer + */ + defaults: { + event: 'swipe', + threshold: 10, + velocity: 0.3, + direction: DIRECTION_HORIZONTAL | DIRECTION_VERTICAL, + pointers: 1 + }, + + getTouchAction: function() { + return PanRecognizer.prototype.getTouchAction.call(this); + }, + + attrTest: function(input) { + var direction = this.options.direction; + var velocity; + + if (direction & (DIRECTION_HORIZONTAL | DIRECTION_VERTICAL)) { + velocity = input.overallVelocity; + } else if (direction & DIRECTION_HORIZONTAL) { + velocity = input.overallVelocityX; + } else if (direction & DIRECTION_VERTICAL) { + velocity = input.overallVelocityY; + } + + return ( + this._super.attrTest.call(this, input) && + direction & input.offsetDirection && + input.distance > this.options.threshold && + input.maxPointers == this.options.pointers && + abs(velocity) > this.options.velocity && + input.eventType & INPUT_END + ); + }, + + emit: function(input) { + var direction = directionStr(input.offsetDirection); + if (direction) { + this.manager.emit(this.options.event + direction, input); + } + + this.manager.emit(this.options.event, input); + } + }); + + /** + * A tap is ecognized when the pointer is doing a small tap/click. Multiple taps are recognized if they occur + * between the given interval and position. The delay option can be used to recognize multi-taps without firing + * a single tap. + * + * The eventData from the emitted event contains the property `tapCount`, which contains the amount of + * multi-taps being recognized. + * @constructor + * @extends Recognizer + */ + function TapRecognizer() { + Recognizer.apply(this, arguments); + + // previous time and center, + // used for tap counting + this.pTime = false; + this.pCenter = false; + + this._timer = null; + this._input = null; + this.count = 0; + } + + inherit(TapRecognizer, Recognizer, { + /** + * @namespace + * @memberof PinchRecognizer + */ + defaults: { + event: 'tap', + pointers: 1, + taps: 1, + interval: 300, // max time between the multi-tap taps + time: 250, // max time of the pointer to be down (like finger on the screen) + threshold: 9, // a minimal movement is ok, but keep it low + posThreshold: 10 // a multi-tap can be a bit off the initial position + }, + + getTouchAction: function() { + return [TOUCH_ACTION_MANIPULATION]; + }, + + process: function(input) { + var options = this.options; + + var validPointers = input.pointers.length === options.pointers; + var validMovement = input.distance < options.threshold; + var validTouchTime = input.deltaTime < options.time; + + this.reset(); + + if (input.eventType & INPUT_START && this.count === 0) { + return this.failTimeout(); + } + + // we only allow little movement + // and we've reached an end event, so a tap is possible + if (validMovement && validTouchTime && validPointers) { + if (input.eventType != INPUT_END) { + return this.failTimeout(); + } + + var validInterval = this.pTime + ? input.timeStamp - this.pTime < options.interval + : true; + var validMultiTap = + !this.pCenter || + getDistance(this.pCenter, input.center) < options.posThreshold; + + this.pTime = input.timeStamp; + this.pCenter = input.center; + + if (!validMultiTap || !validInterval) { + this.count = 1; + } else { + this.count += 1; + } + + this._input = input; + + // if tap count matches we have recognized it, + // else it has began recognizing... + var tapCount = this.count % options.taps; + if (tapCount === 0) { + // no failing requirements, immediately trigger the tap event + // or wait as long as the multitap interval to trigger + if (!this.hasRequireFailures()) { + return STATE_RECOGNIZED; + } else { + this._timer = setTimeoutContext( + function() { + this.state = STATE_RECOGNIZED; + this.tryEmit(); + }, + options.interval, + this + ); + return STATE_BEGAN; + } + } + } + return STATE_FAILED; + }, + + failTimeout: function() { + this._timer = setTimeoutContext( + function() { + this.state = STATE_FAILED; + }, + this.options.interval, + this + ); + return STATE_FAILED; + }, + + reset: function() { + clearTimeout(this._timer); + }, + + emit: function() { + if (this.state == STATE_RECOGNIZED) { + this._input.tapCount = this.count; + this.manager.emit(this.options.event, this._input); + } + } + }); + + /** + * Simple way to create a manager with a default set of recognizers. + * @param {HTMLElement} element + * @param {Object} [options] + * @constructor + */ + function Hammer(element, options) { + options = options || {}; + options.recognizers = ifUndefined( + options.recognizers, + Hammer.defaults.preset + ); + return new Manager(element, options); + } + + /** + * @const {string} + */ + Hammer.VERSION = '2.0.7'; + + /** + * default settings + * @namespace + */ + Hammer.defaults = { + /** + * set if DOM events are being triggered. + * But this is slower and unused by simple implementations, so disabled by default. + * @type {Boolean} + * @default false + */ + domEvents: false, + + /** + * The value for the touchAction property/fallback. + * When set to `compute` it will magically set the correct value based on the added recognizers. + * @type {String} + * @default compute + */ + touchAction: TOUCH_ACTION_COMPUTE, + + /** + * @type {Boolean} + * @default true + */ + enable: true, + + /** + * EXPERIMENTAL FEATURE -- can be removed/changed + * Change the parent input target element. + * If Null, then it is being set the to main element. + * @type {Null|EventTarget} + * @default null + */ + inputTarget: null, + + /** + * force an input class + * @type {Null|Function} + * @default null + */ + inputClass: null, + + /** + * Default recognizer setup when calling `Hammer()` + * When creating a new Manager these will be skipped. + * @type {Array} + */ + preset: [ + // RecognizerClass, options, [recognizeWith, ...], [requireFailure, ...] + [RotateRecognizer, { enable: false }], + [PinchRecognizer, { enable: false }, ['rotate']], + [SwipeRecognizer, { direction: DIRECTION_HORIZONTAL }], + [PanRecognizer, { direction: DIRECTION_HORIZONTAL }, ['swipe']], + [TapRecognizer], + [TapRecognizer, { event: 'doubletap', taps: 2 }, ['tap']], + [PressRecognizer] + ], + + /** + * Some CSS properties can be used to improve the working of Hammer. + * Add them to this method and they will be set when creating a new Manager. + * @namespace + */ + cssProps: { + /** + * Disables text selection to improve the dragging gesture. Mainly for desktop browsers. + * @type {String} + * @default 'none' + */ + userSelect: 'none', + + /** + * Disable the Windows Phone grippers when pressing an element. + * @type {String} + * @default 'none' + */ + touchSelect: 'none', + + /** + * Disables the default callout shown when you touch and hold a touch target. + * On iOS, when you touch and hold a touch target such as a link, Safari displays + * a callout containing information about the link. This property allows you to disable that callout. + * @type {String} + * @default 'none' + */ + touchCallout: 'none', + + /** + * Specifies whether zooming is enabled. Used by IE10> + * @type {String} + * @default 'none' + */ + contentZooming: 'none', + + /** + * Specifies that an entire element should be draggable instead of its contents. Mainly for desktop browsers. + * @type {String} + * @default 'none' + */ + userDrag: 'none', + + /** + * Overrides the highlight color shown when the user taps a link or a JavaScript + * clickable element in iOS. This property obeys the alpha value, if specified. + * @type {String} + * @default 'rgba(0,0,0,0)' + */ + tapHighlightColor: 'rgba(0,0,0,0)' + } + }; + + var STOP = 1; + var FORCED_STOP = 2; + + /** + * Manager + * @param {HTMLElement} element + * @param {Object} [options] + * @constructor + */ + function Manager(element, options) { + this.options = assign({}, Hammer.defaults, options || {}); + + this.options.inputTarget = this.options.inputTarget || element; + + this.handlers = {}; + this.session = {}; + this.recognizers = []; + this.oldCssProps = {}; + + this.element = element; + this.input = createInputInstance(this); + this.touchAction = new TouchAction(this, this.options.touchAction); + + toggleCssProps(this, true); + + each( + this.options.recognizers, + function(item) { + var recognizer = this.add(new item[0](item[1])); + item[2] && recognizer.recognizeWith(item[2]); + item[3] && recognizer.requireFailure(item[3]); + }, + this + ); + } + + Manager.prototype = { + /** + * set options + * @param {Object} options + * @returns {Manager} + */ + set: function(options) { + assign(this.options, options); + + // Options that need a little more setup + if (options.touchAction) { + this.touchAction.update(); + } + if (options.inputTarget) { + // Clean up existing event listeners and reinitialize + this.input.destroy(); + this.input.target = options.inputTarget; + this.input.init(); + } + return this; + }, + + /** + * stop recognizing for this session. + * This session will be discarded, when a new [input]start event is fired. + * When forced, the recognizer cycle is stopped immediately. + * @param {Boolean} [force] + */ + stop: function(force) { + this.session.stopped = force ? FORCED_STOP : STOP; + }, + + /** + * run the recognizers! + * called by the inputHandler function on every movement of the pointers (touches) + * it walks through all the recognizers and tries to detect the gesture that is being made + * @param {Object} inputData + */ + recognize: function(inputData) { + var session = this.session; + if (session.stopped) { + return; + } + + // run the touch-action polyfill + this.touchAction.preventDefaults(inputData); + + var recognizer; + var recognizers = this.recognizers; + + // this holds the recognizer that is being recognized. + // so the recognizer's state needs to be BEGAN, CHANGED, ENDED or RECOGNIZED + // if no recognizer is detecting a thing, it is set to `null` + var curRecognizer = session.curRecognizer; + + // reset when the last recognizer is recognized + // or when we're in a new session + if ( + !curRecognizer || + (curRecognizer && curRecognizer.state & STATE_RECOGNIZED) + ) { + curRecognizer = session.curRecognizer = null; + } + + var i = 0; + while (i < recognizers.length) { + recognizer = recognizers[i]; + + // find out if we are allowed try to recognize the input for this one. + // 1. allow if the session is NOT forced stopped (see the .stop() method) + // 2. allow if we still haven't recognized a gesture in this session, or the this recognizer is the one + // that is being recognized. + // 3. allow if the recognizer is allowed to run simultaneous with the current recognized recognizer. + // this can be setup with the `recognizeWith()` method on the recognizer. + if ( + session.stopped !== FORCED_STOP && // 1 + (!curRecognizer || + recognizer == curRecognizer || // 2 + recognizer.canRecognizeWith(curRecognizer)) + ) { + // 3 + recognizer.recognize(inputData); + } else { + recognizer.reset(); + } + + // if the recognizer has been recognizing the input as a valid gesture, we want to store this one as the + // current active recognizer. but only if we don't already have an active recognizer + if ( + !curRecognizer && + recognizer.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED) + ) { + curRecognizer = session.curRecognizer = recognizer; + } + i++; + } + }, + + /** + * get a recognizer by its event name. + * @param {Recognizer|String} recognizer + * @returns {Recognizer|Null} + */ + get: function(recognizer) { + if (recognizer instanceof Recognizer) { + return recognizer; + } + + var recognizers = this.recognizers; + for (var i = 0; i < recognizers.length; i++) { + if (recognizers[i].options.event == recognizer) { + return recognizers[i]; + } + } + return null; + }, + + /** + * add a recognizer to the manager + * existing recognizers with the same event name will be removed + * @param {Recognizer} recognizer + * @returns {Recognizer|Manager} + */ + add: function(recognizer) { + if (invokeArrayArg(recognizer, 'add', this)) { + return this; + } + + // remove existing + var existing = this.get(recognizer.options.event); + if (existing) { + this.remove(existing); + } + + this.recognizers.push(recognizer); + recognizer.manager = this; + + this.touchAction.update(); + return recognizer; + }, + + /** + * remove a recognizer by name or instance + * @param {Recognizer|String} recognizer + * @returns {Manager} + */ + remove: function(recognizer) { + if (invokeArrayArg(recognizer, 'remove', this)) { + return this; + } + + recognizer = this.get(recognizer); + + // let's make sure this recognizer exists + if (recognizer) { + var recognizers = this.recognizers; + var index = inArray(recognizers, recognizer); + + if (index !== -1) { + recognizers.splice(index, 1); + this.touchAction.update(); + } + } + + return this; + }, + + /** + * bind event + * @param {String} events + * @param {Function} handler + * @returns {EventEmitter} this + */ + on: function(events, handler) { + if (events === undefined) { + return; + } + if (handler === undefined) { + return; + } + + var handlers = this.handlers; + each(splitStr(events), function(event) { + handlers[event] = handlers[event] || []; + handlers[event].push(handler); + }); + return this; + }, + + /** + * unbind event, leave emit blank to remove all handlers + * @param {String} events + * @param {Function} [handler] + * @returns {EventEmitter} this + */ + off: function(events, handler) { + if (events === undefined) { + return; + } + + var handlers = this.handlers; + each(splitStr(events), function(event) { + if (!handler) { + delete handlers[event]; + } else { + handlers[event] && + handlers[event].splice(inArray(handlers[event], handler), 1); + } + }); + return this; + }, + + /** + * emit event to the listeners + * @param {String} event + * @param {Object} data + */ + emit: function(event, data) { + // we also want to trigger dom events + if (this.options.domEvents) { + triggerDomEvent(event, data); + } + + // no handlers, so skip it all + var handlers = this.handlers[event] && this.handlers[event].slice(); + if (!handlers || !handlers.length) { + return; + } + + data.type = event; + data.preventDefault = function() { + data.srcEvent.preventDefault(); + }; + + var i = 0; + while (i < handlers.length) { + handlers[i](data); + i++; + } + }, + + /** + * destroy the manager and unbinds all events + * it doesn't unbind dom events, that is the user own responsibility + */ + destroy: function() { + this.element && toggleCssProps(this, false); + + this.handlers = {}; + this.session = {}; + this.input.destroy(); + this.element = null; + } + }; + + /** + * add/remove the css properties as defined in manager.options.cssProps + * @param {Manager} manager + * @param {Boolean} add + */ + function toggleCssProps(manager, add) { + var element = manager.element; + if (!element.style) { + return; + } + var prop; + each(manager.options.cssProps, function(value, name) { + prop = prefixed(element.style, name); + if (add) { + manager.oldCssProps[prop] = element.style[prop]; + element.style[prop] = value; + } else { + element.style[prop] = manager.oldCssProps[prop] || ''; + } + }); + if (!add) { + manager.oldCssProps = {}; + } + } + + /** + * trigger dom event + * @param {String} event + * @param {Object} data + */ + function triggerDomEvent(event, data) { + var gestureEvent = document.createEvent('Event'); + gestureEvent.initEvent(event, true, true); + gestureEvent.gesture = data; + data.target.dispatchEvent(gestureEvent); + } + + assign(Hammer, { + INPUT_START: INPUT_START, + INPUT_MOVE: INPUT_MOVE, + INPUT_END: INPUT_END, + INPUT_CANCEL: INPUT_CANCEL, + + STATE_POSSIBLE: STATE_POSSIBLE, + STATE_BEGAN: STATE_BEGAN, + STATE_CHANGED: STATE_CHANGED, + STATE_ENDED: STATE_ENDED, + STATE_RECOGNIZED: STATE_RECOGNIZED, + STATE_CANCELLED: STATE_CANCELLED, + STATE_FAILED: STATE_FAILED, + + DIRECTION_NONE: DIRECTION_NONE, + DIRECTION_LEFT: DIRECTION_LEFT, + DIRECTION_RIGHT: DIRECTION_RIGHT, + DIRECTION_UP: DIRECTION_UP, + DIRECTION_DOWN: DIRECTION_DOWN, + DIRECTION_HORIZONTAL: DIRECTION_HORIZONTAL, + DIRECTION_VERTICAL: DIRECTION_VERTICAL, + DIRECTION_ALL: DIRECTION_ALL, + + Manager: Manager, + Input: Input, + TouchAction: TouchAction, + + TouchInput: TouchInput, + MouseInput: MouseInput, + PointerEventInput: PointerEventInput, + TouchMouseInput: TouchMouseInput, + SingleTouchInput: SingleTouchInput, + + Recognizer: Recognizer, + AttrRecognizer: AttrRecognizer, + Tap: TapRecognizer, + Pan: PanRecognizer, + Swipe: SwipeRecognizer, + Pinch: PinchRecognizer, + Rotate: RotateRecognizer, + Press: PressRecognizer, + + on: addEventListeners, + off: removeEventListeners, + each: each, + merge: merge, + extend: extend, + assign: assign, + inherit: inherit, + bindFn: bindFn, + prefixed: prefixed + }); + + // this prevents errors when Hammer is loaded in the presence of an AMD + // style loader but by script tag, not by the loader. + var freeGlobal = + typeof window !== 'undefined' + ? window + : typeof self !== 'undefined' + ? self + : {}; // jshint ignore:line + freeGlobal.Hammer = Hammer; + + if (typeof define === 'function' && define.amd) { + define(function() { + return Hammer; + }); + } else if (typeof module != 'undefined' && module.exports) { + module.exports = Hammer; + } else { + window[exportName] = Hammer; + } +})(window, document, 'Hammer'); diff --git a/js/retina.min.js b/js/retina.min.js new file mode 100644 index 000000000..da0a60d24 --- /dev/null +++ b/js/retina.min.js @@ -0,0 +1,10 @@ +/*! + * Retina.js v1.3.0 + * + * Copyright 2014 Imulus, LLC + * Released under the MIT license + * + * Retina.js is an open source script that makes it easy to serve + * high-resolution images to devices with retina displays. + */ +!function(){function a(){}function b(a){return f.retinaImageSuffix+a}function c(a,c){if(this.path=a||"","undefined"!=typeof c&&null!==c)this.at_2x_path=c,this.perform_check=!1;else{if(void 0!==document.createElement){var d=document.createElement("a");d.href=this.path,d.pathname=d.pathname.replace(g,b),this.at_2x_path=d.href}else{var e=this.path.split("?");e[0]=e[0].replace(g,b),this.at_2x_path=e.join("?")}this.perform_check=!0}}function d(a){this.el=a,this.path=new c(this.el.getAttribute("src"),this.el.getAttribute("data-at2x"));var b=this;this.path.check_2x_variant(function(a){a&&b.swap()})}var e="undefined"==typeof exports?window:exports,f={retinaImageSuffix:"@2x",check_mime_type:!0,force_original_dimensions:!0};e.Retina=a,a.configure=function(a){null===a&&(a={});for(var b in a)a.hasOwnProperty(b)&&(f[b]=a[b])},a.init=function(a){null===a&&(a=e);var b=a.onload||function(){};a.onload=function(){var a,c,e=document.getElementsByTagName("img"),f=[];for(a=0;a1?!0:e.matchMedia&&e.matchMedia(a).matches?!0:!1};var g=/\.\w+$/;e.RetinaImagePath=c,c.confirmed_paths=[],c.prototype.is_external=function(){return!(!this.path.match(/^https?\:/i)||this.path.match("//"+document.domain))},c.prototype.check_2x_variant=function(a){var b,d=this;return this.is_external()?a(!1):this.perform_check||"undefined"==typeof this.at_2x_path||null===this.at_2x_path?this.at_2x_path in c.confirmed_paths?a(!0):(b=new XMLHttpRequest,b.open("HEAD",this.at_2x_path),b.onreadystatechange=function(){if(4!==b.readyState)return a(!1);if(b.status>=200&&b.status<=399){if(f.check_mime_type){var e=b.getResponseHeader("Content-Type");if(null===e||!e.match(/^image/i))return a(!1)}return c.confirmed_paths.push(d.at_2x_path),a(!0)}return a(!1)},b.send(),void 0):a(!0)},e.RetinaImage=d,d.prototype.swap=function(a){function b(){c.el.complete?(f.force_original_dimensions&&(c.el.setAttribute("width",c.el.offsetWidth),c.el.setAttribute("height",c.el.offsetHeight)),c.el.setAttribute("src",a)):setTimeout(b,5)}"undefined"==typeof a&&(a=this.path.at_2x_path);var c=this;b()},a.isRetina()&&a.init(e)}(); \ No newline at end of file diff --git a/js/script.js b/js/script.js new file mode 100644 index 000000000..129681034 --- /dev/null +++ b/js/script.js @@ -0,0 +1,57 @@ +(function($){ + // Create menu for mobile devices + var menuHtml = [], + lastTag = ''; + + menuHtml.push(''); + + $('#mobile-menu-wrap').html(menuHtml.join('')); + + $('#page-mobile-menu').on('change', function(){ + var val = $(this).find(':selected').val(); + + if (val) location.href = val; + }); + + // Select text in getting started input in home page + $('#banner-getting-started-input').on('click', function(){ + $(this).select(); + }); + + // Main navigation menu for mobile devices + $('#main-nav-toggle').on('click', function(){ + $('#main-nav').toggleClass('on'); + }); +/* + $('.api-options input').on('change', function(){ + var value = $(this).val(), + checked = $(this).prop('checked'); + + $('.api-item.' + value).css({ + display: checked ? 'block' : 'none' + }); + });*/ +})(jQuery); \ No newline at end of file diff --git a/mstile-150x150.png b/mstile-150x150.png new file mode 100644 index 000000000..d61d19793 Binary files /dev/null and b/mstile-150x150.png differ diff --git a/mstile-310x150.png b/mstile-310x150.png new file mode 100644 index 000000000..5a2c06a02 Binary files /dev/null and b/mstile-310x150.png differ diff --git a/robots.txt b/robots.txt new file mode 100644 index 000000000..96d2463bf --- /dev/null +++ b/robots.txt @@ -0,0 +1,3 @@ +User-agent: * +Sitemap: /sitemap.xml +Disallow: /docs/plugins/filter-flow.html \ No newline at end of file diff --git a/safari-pinned-tab.svg b/safari-pinned-tab.svg new file mode 100644 index 000000000..9812f4127 --- /dev/null +++ b/safari-pinned-tab.svg @@ -0,0 +1,25 @@ + + + + +Created by potrace 1.14, written by Peter Selinger 2001-2017 + + + + + diff --git a/site.webmanifest b/site.webmanifest new file mode 100644 index 000000000..de65106f4 --- /dev/null +++ b/site.webmanifest @@ -0,0 +1,19 @@ +{ + "name": "", + "short_name": "", + "icons": [ + { + "src": "/android-chrome-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/android-chrome-256x256.png", + "sizes": "256x256", + "type": "image/png" + } + ], + "theme_color": "#ffffff", + "background_color": "#ffffff", + "display": "standalone" +} diff --git a/sitemap.xml b/sitemap.xml new file mode 100644 index 000000000..f99bdff43 --- /dev/null +++ b/sitemap.xml @@ -0,0 +1,2934 @@ + + + + + https://konvajs.org/downloads/code/sandbox/Resizing_Stress_Test.html + + 2024-09-17 + + + + + https://konvajs.org/downloads/code/selectors/Select_by_id.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/selectors/Select_by_Type.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/animations/Stop_Animation.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/selectors/Select_by_Name.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/animations/Moving.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/animations/Rotation.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/animations/Scaling.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/performance/Optimize_Animation.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/performance/Disable_Perfect_Draw.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/performance/Layer_Management.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/performance/Shape_Redraw.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/performance/Listening_False.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/performance/BatchDraw.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/performance/Shape_Caching.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/performance/Optimize_Strokes.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/events/Listen_for_Events.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/events/Multi_Event.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/events/Keyboard_Events.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/events/Remove_by_Name.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/events/Binding_Events.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/events/Event_Delegation.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/events/Image_Events.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/events/Custom_Hit_Region.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/events/Cancel_Propagation.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/events/Mobile_Events.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/events/Remove_Event.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/events/Mobile_Scrolling.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/events/Fire_Events.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/events/Pointer_Events.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/events/Stage_Events.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/events/Desktop_and_Mobile.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/main-demo.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/styling/Line_Join.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/styling/Mouse_Cursor.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/styling/Opacity.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/styling/Fill_Stroke_Order.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/styling/Stroke.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/styling/Blend_Mode.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/styling/Hide_and_Show.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/styling/Shadow.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/styling/Fill.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Free_Drawing_Manual.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Stage_Preview_Clone.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Web_Worker.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Native_Context_Access.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Responsive_Canvas.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Modify_Shape_Color_on_Click.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Image_Resize.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Rich_Text.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/GIF_On_Canvas.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Video_On_Canvas.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Canvas_Scrolling_Drag.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Animals_on_the_Beach_Game.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Drop_DOM_Element.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Shape_Tango.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Complex_Editable_Text.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Drag_And_Drop_Multiple_Shapes.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Star_Spinner.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Canvas_Scrolling_Transform.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Physics_Simulator.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Scroll_By_Edge_Drag.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Multi-touch_Scale_Shape.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Scale_Image_To_Fit.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Canvas_Scrolling_Manual.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Canvas_Context_Menu.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Image_Border_Highlighting.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Custom_Font.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Animation_Stress_Test.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Quantum_Squiggle.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Editable_Text.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Image_Border.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Multi-touch_Scale_Stage.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Expand_Image_On_Hover.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Stage_Preview_Image.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Drag_And_Drop_Stress_Test.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/20000_Nodes.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Limited_Drag_And_Resize.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Interactive_Building_Map.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Canvas_to_PDF.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Transparent_Group.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Canvas_Scrolling_Large.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Collision_Detection.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Planets_Image_Map.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Relative_zooming.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Zoom_Layer_On_Hover.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Simple_Window.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Jumping_Bunnies.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Modify_Curves_with_Anchor_Points.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Canvas_Background.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Free_Drawing_Vector.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Wheel_of_Fortune.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Connected_Objects.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Elastic_Stars.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Relative_Pointer_Position.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/10000_Shapes_With_Tooltip.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Mirror_Canvas_Shape.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/SVG_On_Canvas.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Gestures.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Objects_Snapping.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/sandbox/Shape_Tooltips.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/data_and_serialization/High-Quality-Export.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/data_and_serialization/Serialize_a_Stage.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/data_and_serialization/Stage_Data_URL.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/data_and_serialization/Simple_Load.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/data_and_serialization/Complex_Load.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/data_and_serialization/Best_Practices.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Path.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Line_-_Spline.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Wedge.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/RegularPolygon.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/rect.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Line_-_Simple_line.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Arrow.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Circle.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Arc.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Ellipse.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Line_-_Polygon.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Custom.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Ring.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Sprite.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Star.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Label.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Image.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/TextPath.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Text.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/shapes/Line_-_Blob.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/drag_and_drop/Simple_Drag_Bounds.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/drag_and_drop/Drag_a_Stage.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/drag_and_drop/Drag_a_Group.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/drag_and_drop/Drop_Events.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/drag_and_drop/Drag_a_Line.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/drag_and_drop/Drag_Events.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/drag_and_drop/Drag_and_Drop.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/drag_and_drop/Complex_Drag_and_Drop.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/drag_and_drop/Drag_an_Image.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/tweens/All_Easings.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/tweens/All_Controls.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/tweens/Common_Easing.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/tweens/Finish_Event.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/tweens/Tween_Filter.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/tweens/Linear_Easing.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/tweens/Complex_Tweening.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/clipping/Clipping_Function.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/clipping/Clipping_Regions.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/posts/Position_vs_Offset_Basic_x_y.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/groups_and_layers/Change_Containers.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/groups_and_layers/Layering.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/groups_and_layers/Groups.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/groups_and_layers/zIndex.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/Enhance.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/Invert.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/RGBA.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/Pixelate.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/Multiple_Filters.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/HSL.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/Noise.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/Grayscale.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/Kaleidoscope.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/RGB.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/Brighten.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/Contrast.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/Custom_Filter.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/Mask.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/Emboss.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/Blur.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/filters/HSV.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/select_and_transform/Keep_Ratio.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/select_and_transform/Resize_Limits.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/select_and_transform/Resize_Snaps.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/select_and_transform/Rotation_Snaps.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/select_and_transform/Centered_Scaling.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/select_and_transform/Resize_Text.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/select_and_transform/Basic_demo.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/select_and_transform/Ignore_Stroke_On_Transform.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/select_and_transform/Stop_Transform.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/select_and_transform/Transformer_Styling.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/select_and_transform/Force_Update.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/select_and_transform/Transformer_Complex_Styling.html + + 2024-09-09 + + + + + https://konvajs.org/downloads/code/select_and_transform/Transform_Events.html + + 2024-09-09 + + + + + https://konvajs.org/android-chrome-manifest.json + + 2024-09-09 + + + + + https://konvajs.org/docs/tweens/Common_Easings.html + + 2024-08-28 + + + + + https://konvajs.org/docs/react/DOM_Portal.html + + 2024-07-15 + + + + + https://konvajs.org/docs/performance/Listening_False.html + + 2024-07-15 + + + + + https://konvajs.org/docs/vue/Filters.html + + 2024-01-09 + + + + + https://konvajs.org/docs/vue/index.html + + 2024-01-09 + + + + + https://konvajs.org/docs/vue/Simple_Animations.html + + 2024-01-09 + + + + + https://konvajs.org/docs/vue/Cache.html + + 2024-01-09 + + + + + https://konvajs.org/docs/vue/Drag_And_Drop.html + + 2024-01-09 + + + + + https://konvajs.org/docs/vue/Events.html + + 2024-01-09 + + + + + https://konvajs.org/docs/vue/Images.html + + 2024-01-09 + + + + + https://konvajs.org/docs/vue/Save-Load.html + + 2024-01-09 + + + + + https://konvajs.org/docs/vue/Shapes.html + + 2024-01-09 + + + + + https://konvajs.org/docs/vue/Transformer.html + + 2024-01-09 + + + + + https://konvajs.org/docs/vue/zIndex.html + + 2024-01-09 + + + + + https://konvajs.org/docs/vue/Custom_Shape.html + + 2024-01-09 + + + + + https://konvajs.org/docs/sandbox/Scroll_By_Edge_Drag.html + + 2024-01-02 + + + + + https://konvajs.org/docs/svelte/zIndex.html + + 2023-08-31 + + + + + https://konvajs.org/docs/svelte/SvelteKit.html + + 2023-08-31 + + + + + https://konvajs.org/docs/svelte/Transformer.html + + 2023-08-31 + + + + + https://konvajs.org/docs/svelte/index.html + + 2023-08-31 + + + + + https://konvajs.org/docs/svelte/Labels.html + + 2023-08-31 + + + + + https://konvajs.org/docs/svelte/Save_Load.html + + 2023-08-31 + + + + + https://konvajs.org/docs/svelte/Shapes.html + + 2023-08-31 + + + + + https://konvajs.org/docs/svelte/Simple_Animations.html + + 2023-08-31 + + + + + https://konvajs.org/docs/svelte/Events.html + + 2023-08-31 + + + + + https://konvajs.org/docs/svelte/Filters.html + + 2023-08-31 + + + + + https://konvajs.org/docs/svelte/Images.html + + 2023-08-31 + + + + + https://konvajs.org/docs/svelte/Konva_Node.html + + 2023-08-31 + + + + + https://konvajs.org/docs/svelte/Bindings.html + + 2023-08-31 + + + + + https://konvajs.org/docs/svelte/Cache.html + + 2023-08-31 + + + + + https://konvajs.org/docs/svelte/Custom_Shape.html + + 2023-08-31 + + + + + https://konvajs.org/docs/svelte/Drag_And_Drop.html + + 2023-08-31 + + + + + https://konvajs.org/docs/performance/All_Performance_Tips.html + + 2023-08-31 + + + + + https://konvajs.org/docs/sandbox/20000_Nodes.html + + 2023-08-26 + + + + + https://konvajs.org/docs/select_and_transform/Transformer_Complex_Styling.html + + 2023-08-18 + + + + + https://konvajs.org/docs/select_and_transform/Transformer_Styling.html + + 2023-08-18 + + + + + https://konvajs.org/index.html + + 2023-06-02 + + + + + https://konvajs.org/docs/tools.html + + 2023-05-24 + + + + + https://konvajs.org/docs/performance/Shape_Caching.html + + 2023-05-24 + + + + + https://konvajs.org/docs/index.html + + 2023-04-17 + + + + + https://konvajs.org/docs/react/Undo-Redo.html + + 2022-10-01 + + + + + https://konvajs.org/docs/select_and_transform/Force_Update.html + + 2022-07-18 + + + + + https://konvajs.org/docs/events/Pointer_Events.html + + 2022-05-23 + + + + + https://konvajs.org/docs/react/Canvas_Export.html + + 2022-03-23 + + + + + https://konvajs.org/docs/donate.html + + 2022-03-08 + + + + + https://konvajs.org/docs/events/Desktop_and_Mobile.html + + 2021-12-27 + + + + + https://konvajs.org/docs/events/Binding_Events.html + + 2021-12-27 + + + + + https://konvajs.org/docs/events/Multi_Event.html + + 2021-12-27 + + + + + https://konvajs.org/docs/sandbox/Canvas_Editor.html + + 2021-11-18 + + + + + https://konvajs.org/docs/select_and_transform/Resize_Limits.html + + 2021-11-15 + + + + + https://konvajs.org/docs/select_and_transform/Resize_Snaps.html + + 2021-11-15 + + + + + https://konvajs.org/docs/sandbox/Objects_Snapping.html + + 2021-11-15 + + + + + https://konvajs.org/docs/drag_and_drop/Complex_Drag_and_Drop.html + + 2021-09-01 + + + + + https://konvajs.org/docs/drag_and_drop/Simple_Drag_Bounds.html + + 2021-09-01 + + + + + https://konvajs.org/docs/sandbox/Limited_Drag_And_Resize.html + + 2021-08-31 + + + + + https://konvajs.org/docs/posts/Tainted_Canvas.html + + 2021-07-02 + + + + + https://konvajs.org/docs/performance/Shape_Redraw.html + + 2021-06-15 + + + + + https://konvajs.org/docs/performance/Batch_Draw.html + + 2021-06-15 + + + + + https://konvajs.org/docs/selectors/Select_by_Type.html + + 2021-06-11 + + + + + https://konvajs.org/docs/selectors/Select_by_Name.html + + 2021-06-11 + + + + + https://konvajs.org/docs/sandbox/Web_Worker.html + + 2021-05-22 + + + + + https://konvajs.org/docs/sandbox/SVG_On_Canvas.html + + 2021-05-21 + + + + + https://konvajs.org/docs/overview.html + + 2021-05-21 + + + + + https://konvajs.org/docs/sandbox/Video_On_Canvas.html + + 2021-04-28 + + + + + https://konvajs.org/docs/react/Canvas_Portal.html + + 2021-04-14 + + + + + https://konvajs.org/docs/data_and_serialization/Best_Practices.html + + 2021-03-17 + + + + + https://konvajs.org/docs/select_and_transform/Keep_Ratio.html + + 2021-03-17 + + + + + https://konvajs.org/docs/shapes/Image.html + + 2021-01-15 + + + + + https://konvajs.org/docs/react/Images.html + + 2021-01-13 + + + + + https://konvajs.org/docs/styling/Fill_Stroke_Order.html + + 2020-11-24 + + + + + https://konvajs.org/docs/react/Shapes.html + + 2020-11-23 + + + + + https://konvajs.org/docs/react/zIndex.html + + 2020-11-23 + + + + + https://konvajs.org/docs/react/index.html + + 2020-11-23 + + + + + https://konvajs.org/docs/react/Transformer.html + + 2020-11-23 + + + + + https://konvajs.org/docs/react/Intro.html + + 2020-11-23 + + + + + https://konvajs.org/docs/react/Simple_Animations.html + + 2020-11-23 + + + + + https://konvajs.org/docs/react/Free_Drawing.html + + 2020-11-23 + + + + + https://konvajs.org/docs/react/Drop_Image.html + + 2020-11-23 + + + + + https://konvajs.org/docs/react/Drag_And_Drop.html + + 2020-11-23 + + + + + https://konvajs.org/docs/react/Events.html + + 2020-11-23 + + + + + https://konvajs.org/docs/react/Filters.html + + 2020-11-23 + + + + + https://konvajs.org/docs/react/Custom_Shape.html + + 2020-11-23 + + + + + https://konvajs.org/docs/react/Complex_Animations.html + + 2020-11-23 + + + + + https://konvajs.org/docs/react/Access_Konva_Nodes.html + + 2020-11-23 + + + + + https://konvajs.org/docs/sandbox/Image_Resize.html + + 2020-11-05 + + + + + https://konvajs.org/docs/sandbox/Resizing_Stress_Test.html + + 2020-11-05 + + + + + https://konvajs.org/docs/clipping/Clipping_Function.html + + 2020-09-17 + + + + + https://konvajs.org/docs/animations/Rotation.html + + 2020-09-17 + + + + + https://konvajs.org/docs/animations/Moving.html + + 2020-09-17 + + + + + https://konvajs.org/docs/performance/Optimize_Strokes.html + + 2020-09-15 + + + + + https://konvajs.org/docs/support.html + + 2020-09-10 + + + + + https://konvajs.org/docs/sandbox/Mirror_Canvas_Shape.html + + 2020-09-03 + + + + + https://konvajs.org/docs/sandbox/Transparent_Group.html + + 2020-09-02 + + + + + https://konvajs.org/docs/styling/Opacity.html + + 2020-09-02 + + + + + https://konvajs.org/docs/sandbox/Canvas_Background.html + + 2020-08-31 + + + + + https://konvajs.org/docs/select_and_transform/Ignore_Stroke_On_Transform.html + + 2020-08-28 + + + + + https://konvajs.org/docs/select_and_transform/Resize_Text.html + + 2020-08-28 + + + + + https://konvajs.org/docs/sandbox/Scale_Image_To_Fit.html + + 2020-07-31 + + + + + https://konvajs.org/docs/data_and_serialization/Stage_Data_URL.html + + 2020-07-14 + + + + + https://konvajs.org/docs/sandbox/Multi-touch_Scale_Stage.html + + 2020-07-09 + + + + + https://konvajs.org/docs/events/Mobile_Events.html + + 2020-07-09 + + + + + https://konvajs.org/docs/sandbox/Gestures.html + + 2020-07-09 + + + + + https://konvajs.org/docs/sandbox/Native_Context_Access.html + + 2020-07-09 + + + + + https://konvajs.org/docs/sandbox/Jumping_Bunnies.html + + 2020-06-24 + + + + + https://konvajs.org/docs/performance/Disable_Perfect_Draw.html + + 2020-06-24 + + + + + https://konvajs.org/docs/data_and_serialization/High-Quality-Export.html + + 2020-06-09 + + + + + https://konvajs.org/docs/sandbox/Modify_Curves_with_Anchor_Points.html + + 2020-06-09 + + + + + https://konvajs.org/docs/filters/Blur.html + + 2020-05-15 + + + + + https://konvajs.org/docs/filters/Brighten.html + + 2020-05-15 + + + + + https://konvajs.org/docs/filters/Contrast.html + + 2020-05-15 + + + + + https://konvajs.org/docs/filters/Emboss.html + + 2020-05-15 + + + + + https://konvajs.org/docs/filters/Enhance.html + + 2020-05-15 + + + + + https://konvajs.org/docs/filters/Grayscale.html + + 2020-05-15 + + + + + https://konvajs.org/docs/filters/HSL.html + + 2020-05-15 + + + + + https://konvajs.org/docs/filters/HSV.html + + 2020-05-15 + + + + + https://konvajs.org/docs/filters/Invert.html + + 2020-05-15 + + + + + https://konvajs.org/docs/filters/Kaleidoscope.html + + 2020-05-15 + + + + + https://konvajs.org/docs/filters/Mask.html + + 2020-05-15 + + + + + https://konvajs.org/docs/filters/Noise.html + + 2020-05-15 + + + + + https://konvajs.org/docs/filters/Pixelate.html + + 2020-05-15 + + + + + https://konvajs.org/docs/filters/RGB.html + + 2020-05-15 + + + + + https://konvajs.org/docs/filters/RGBA.html + + 2020-05-15 + + + + + https://konvajs.org/docs/select_and_transform/Basic_demo.html + + 2020-05-08 + + + + + https://konvajs.org/docs/select_and_transform/Stop_Transform.html + + 2020-04-22 + + + + + https://konvajs.org/docs/sandbox/Image_Border.html + + 2020-03-11 + + + + + https://konvajs.org/docs/sandbox/Canvas_to_PDF.html + + 2020-03-11 + + + + + https://konvajs.org/docs/sandbox/index.html + + 2020-03-01 + + + + + https://konvajs.org/docs/filters/Custom_Filter.html + + 2020-02-24 + + + + + https://konvajs.org/docs/sandbox/Collision_Detection.html + + 2020-02-18 + + + + + https://konvajs.org/docs/shapes/Path.html + + 2020-02-05 + + + + + https://konvajs.org/docs/sandbox/Rich_Text.html + + 2020-02-05 + + + + + https://konvajs.org/docs/sandbox/Canvas_Context_Menu.html + + 2019-11-09 + + + + + https://konvajs.org/docs/sandbox/Stage_Preview.html + + 2019-11-06 + + + + + https://konvajs.org/docs/sandbox/Image_Labeling.html + + 2019-11-04 + + + + + https://konvajs.org/docs/sandbox/Window_Frame_Designer.html + + 2019-08-09 + + + + + https://konvajs.org/docs/sandbox/Seats_Reservation.html + + 2019-08-09 + + + + + https://konvajs.org/docs/how_it_works.html + + 2019-08-05 + + + + + https://konvajs.org/docs/animations/Create_an_Animation.html + + 2019-08-05 + + + + + https://konvajs.org/docs/animations/Scaling.html + + 2019-08-05 + + + + + https://konvajs.org/docs/clipping/Clipping_Regions.html + + 2019-08-05 + + + + + https://konvajs.org/docs/animations/Stop_Animation.html + + 2019-08-05 + + + + + https://konvajs.org/docs/data_and_serialization/Complex_Load.html + + 2019-08-05 + + + + + https://konvajs.org/docs/data_and_serialization/Serialize_a_Stage.html + + 2019-08-05 + + + + + https://konvajs.org/docs/data_and_serialization/Simple_Load.html + + 2019-08-05 + + + + + https://konvajs.org/docs/drag_and_drop/Drag_a_Group.html + + 2019-08-05 + + + + + https://konvajs.org/docs/drag_and_drop/Drag_Events.html + + 2019-08-05 + + + + + https://konvajs.org/docs/drag_and_drop/Drag_a_Line.html + + 2019-08-05 + + + + + https://konvajs.org/docs/drag_and_drop/Drag_a_Stage.html + + 2019-08-05 + + + + + https://konvajs.org/docs/drag_and_drop/Drag_an_Image.html + + 2019-08-05 + + + + + https://konvajs.org/docs/drag_and_drop/Drag_and_Drop.html + + 2019-08-05 + + + + + https://konvajs.org/docs/drag_and_drop/Drop_Events.html + + 2019-08-05 + + + + + https://konvajs.org/docs/events/Cancel_Propagation.html + + 2019-08-05 + + + + + https://konvajs.org/docs/events/Custom_Hit_Region.html + + 2019-08-05 + + + + + https://konvajs.org/docs/events/Fire_Events.html + + 2019-08-05 + + + + + https://konvajs.org/docs/events/Event_Delegation.html + + 2019-08-05 + + + + + https://konvajs.org/docs/events/Image_Events.html + + 2019-08-05 + + + + + https://konvajs.org/docs/events/Keyboard_Events.html + + 2019-08-05 + + + + + https://konvajs.org/docs/events/Listen_for_Events.html + + 2019-08-05 + + + + + https://konvajs.org/docs/events/Mobile_Scrolling.html + + 2019-08-05 + + + + + https://konvajs.org/docs/events/Remove_Event.html + + 2019-08-05 + + + + + https://konvajs.org/docs/events/Remove_by_Name.html + + 2019-08-05 + + + + + https://konvajs.org/docs/events/Stage_Events.html + + 2019-08-05 + + + + + https://konvajs.org/docs/filters/Multiple_Filters.html + + 2019-08-05 + + + + + https://konvajs.org/docs/groups_and_layers/Change_Containers.html + + 2019-08-05 + + + + + https://konvajs.org/docs/groups_and_layers/Groups.html + + 2019-08-05 + + + + + https://konvajs.org/docs/groups_and_layers/Layering.html + + 2019-08-05 + + + + + https://konvajs.org/docs/groups_and_layers/zIndex.html + + 2019-08-05 + + + + + https://konvajs.org/docs/performance/Avoid_Memory_Leaks.html + + 2019-08-05 + + + + + https://konvajs.org/docs/performance/Layer_Management.html + + 2019-08-05 + + + + + https://konvajs.org/docs/performance/Optimize_Animation.html + + 2019-08-05 + + + + + https://konvajs.org/docs/posts/Position_vs_Offset.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/10000_Shapes_with_Tooltip.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Animals_on_the_Beach_Game.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Animation_Stress_Test.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Canvas_Scrolling.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Connected_Objects.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Custom_Font.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Drag_and_Drop_Multiple_Shapes.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Drag_and_Drop_Stress_Test.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Drop_DOM_Element.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Editable_Text.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Elastic_Stars.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Expand_Images_on_Hover.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Free_Drawing.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/GIF_On_Canvas.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Image_Border_Highlighting.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Interactive_Building_Map.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Multi-touch_Scale_Shape.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Modify_Shape_Color_on_Click.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Physics_Simulator.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Planets_Image_Map.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Quantum_Squiggle.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Relative_Pointer_Position.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Responsive_Canvas.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Shape_Tango.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Simple_Window_Frame.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Shape_Tooltips.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Star_Spinner.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Wheel_of_Fortune.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Zoom_Layer_On_hover.html + + 2019-08-05 + + + + + https://konvajs.org/docs/sandbox/Zooming_Relative_To_Pointer.html + + 2019-08-05 + + + + + https://konvajs.org/docs/select_and_transform/Centered_Scaling.html + + 2019-08-05 + + + + + https://konvajs.org/docs/select_and_transform/Rotation_Snaps.html + + 2019-08-05 + + + + + https://konvajs.org/docs/select_and_transform/Transform_Events.html + + 2019-08-05 + + + + + https://konvajs.org/docs/selectors/Select_by_id.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/Arc.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/Arrow.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/Circle.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/Custom.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/Ellipse.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/Label.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/Line_-_Blob.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/Line_-_Polygon.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/Line_-_Simple_Line.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/Line_-_Spline.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/Rect.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/RegularPolygon.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/Ring.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/Sprite.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/Text.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/Star.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/TextPath.html + + 2019-08-05 + + + + + https://konvajs.org/docs/shapes/Wedge.html + + 2019-08-05 + + + + + https://konvajs.org/docs/styling/Blend_Mode.html + + 2019-08-05 + + + + + https://konvajs.org/docs/styling/Fill.html + + 2019-08-05 + + + + + https://konvajs.org/docs/styling/Line_Join.html + + 2019-08-05 + + + + + https://konvajs.org/docs/styling/Mouse_Cursor.html + + 2019-08-05 + + + + + https://konvajs.org/docs/styling/Hide_and_Show.html + + 2019-08-05 + + + + + https://konvajs.org/docs/styling/Shadow.html + + 2019-08-05 + + + + + https://konvajs.org/docs/styling/Stroke.html + + 2019-08-05 + + + + + https://konvajs.org/docs/tweens/All_Easings.html + + 2019-08-05 + + + + + https://konvajs.org/docs/tweens/All_Controls.html + + 2019-08-05 + + + + + https://konvajs.org/docs/tweens/Complex_Tweening.html + + 2019-08-05 + + + + + https://konvajs.org/docs/tweens/Finish_Event.html + + 2019-08-05 + + + + + https://konvajs.org/docs/tweens/Linear_Easing.html + + 2019-08-05 + + + + + https://konvajs.org/docs/tweens/Tween_Filter.html + + 2019-08-05 + + + + + + https://konvajs.org/ + 2024-09-17 + daily + 1.0 + + + + + +