Star
new Konva.Star(config)
Star constructor
Parameters
Name | Type | Description |
---|---|---|
config | Object | |
numPoints | Integer | |
innerRadius | Number | |
outerRadius | Number | |
fill (optional) | String | fill color |
fillPatternImage (optional) | Image | fill pattern image |
fillPatternX (optional) | Number | |
fillPatternY (optional) | Number | |
fillPatternOffset (optional) | Object | object with x and y component |
fillPatternOffsetX (optional) | Number | |
fillPatternOffsetY (optional) | Number | |
fillPatternScale (optional) | Object | object with x and y component |
fillPatternScaleX (optional) | Number | |
fillPatternScaleY (optional) | Number | |
fillPatternRotation (optional) | Number | |
fillPatternRepeat (optional) | String | can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat" |
fillLinearGradientStartPoint (optional) | Object | object with x and y component |
fillLinearGradientStartPointX (optional) | Number | |
fillLinearGradientStartPointY (optional) | Number | |
fillLinearGradientEndPoint (optional) | Object | object with x and y component |
fillLinearGradientEndPointX (optional) | Number | |
fillLinearGradientEndPointY (optional) | Number | |
fillLinearGradientColorStops (optional) | Array | array of color stops |
fillRadialGradientStartPoint (optional) | Object | object with x and y component |
fillRadialGradientStartPointX (optional) | Number | |
fillRadialGradientStartPointY (optional) | Number | |
fillRadialGradientEndPoint (optional) | Object | object with x and y component |
fillRadialGradientEndPointX (optional) | Number | |
fillRadialGradientEndPointY (optional) | Number | |
fillRadialGradientStartRadius (optional) | Number | |
fillRadialGradientEndRadius (optional) | Number | |
fillRadialGradientColorStops (optional) | Array | array of color stops |
fillEnabled (optional) | Boolean | flag which enables or disables the fill. The default value is true |
fillPriority (optional) | String | 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 (optional) | String | stroke color |
strokeWidth (optional) | Number | stroke width |
fillAfterStrokeEnabled (optional) | Boolean | Should we draw fill AFTER stroke? Default is false. |
hitStrokeWidth (optional) | Number | size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth |
strokeHitEnabled (optional) | Boolean | flag which enables or disables stroke hit region. The default is true |
perfectDrawEnabled (optional) | Boolean | flag which enables or disables using buffer canvas. The default is true |
shadowForStrokeEnabled (optional) | Boolean | flag which enables or disables shadow for stroke. The default is true |
strokeScaleEnabled (optional) | Boolean | flag which enables or disables stroke scale. The default is true |
strokeEnabled (optional) | Boolean | flag which enables or disables the stroke. The default value is true |
lineJoin (optional) | String | can be miter, round, or bevel. The default is miter |
lineCap (optional) | String | can be butt, round, or square. The default is butt |
shadowColor (optional) | String | |
shadowBlur (optional) | Number | |
shadowOffset (optional) | Object | object with x and y component |
shadowOffsetX (optional) | Number | |
shadowOffsetY (optional) | Number | |
shadowOpacity (optional) | Number | shadow opacity. Can be any real number between 0 and 1 |
shadowEnabled (optional) | Boolean | flag which enables or disables the shadow. The default value is true |
dash (optional) | Array | |
dashEnabled (optional) | Boolean | flag which enables or disables the dashArray. The default value is true |
x (optional) | Number | |
y (optional) | Number | |
width (optional) | Number | |
height (optional) | Number | |
visible (optional) | Boolean | |
listening (optional) | Boolean | whether or not the node is listening for events |
id (optional) | String | unique id |
name (optional) | String | non-unique name |
opacity (optional) | Number | determines node opacity. Can be any number between 0 and 1 |
scale (optional) | Object | set scale |
scaleX (optional) | Number | set scale x |
scaleY (optional) | Number | set scale y |
rotation (optional) | Number | rotation in degrees |
offset (optional) | Object | offset from center point and rotation point |
offsetX (optional) | Number | set offset x |
offsetY (optional) | Number | set offset y |
draggable (optional) | Boolean | makes the node draggable. When stages are draggable, you can drag and drop the entire stage by dragging any portion of the stage |
dragDistance (optional) | Number | |
dragBoundFunc (optional) | function |
Inherited from: Konva.Shape
Own Methods
numPoints(numPoints)
get/set number of points
Parameters:
numPoints
(Number)
Returns: Number
Example:
// get inner radius
var numPoints = star.numPoints();
// set inner radius
star.numPoints(20);
innerRadius(innerRadius)
get/set innerRadius
Parameters:
innerRadius
(Number)
Returns: Number
Example:
// get inner radius
var innerRadius = star.innerRadius();
// set inner radius
star.innerRadius(20);
outerRadius(outerRadius)
get/set outerRadius
Parameters:
outerRadius
(Number)
Returns: Number
Example:
// get inner radius
var outerRadius = star.outerRadius();
// set inner radius
star.outerRadius(20);
Inherited Methods
hasShadow()
returns whether or not a shadow will be rendered
Returns: Boolean
Inherited from: Konva.Shape#hasShadow
hasFill()
returns whether or not the shape will be filled
Returns: Boolean
Inherited from: Konva.Shape#hasFill
hasStroke()
returns whether or not the shape will be stroked
Returns: Boolean
Inherited from: Konva.Shape#hasStroke
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:
point
(Object)point.x
(Number)point.y
(Number)
Returns: Boolean
Inherited from: Konva.Shape#intersects
getSelfRect()
return self rectangle (x, y, width, height) of shape. This method are not taken into account transformation and styles.
Returns: Object
rect with
\{x, y, width, height\}
properties
Inherited from: Konva.Shape#getSelfRect
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()}
drawHitFromCache(alphaThreshold)
draw hit graph using the cached scene canvas
Parameters:
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
Returns: Konva.Shape
Inherited from: Konva.Shape#drawHitFromCache
Example:
shape.cache();
shape.drawHitFromCache();
stroke(color)
get/set stroke color
Parameters:
color
(String)
Returns: String
Inherited from: Konva.Shape#stroke
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');
strokeWidth(strokeWidth)
get/set stroke width
Parameters:
strokeWidth
(Number)
Returns: Number
Inherited from: Konva.Shape#strokeWidth
Example:
// get stroke width
var strokeWidth = shape.strokeWidth();
// set stroke width
shape.strokeWidth(10);
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:
fillAfterStrokeEnabled
(Boolean)
Returns: Boolean
Inherited from: Konva.Shape#fillAfterStrokeEnabled
Example:
// get stroke width
var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
// set stroke width
shape.fillAfterStrokeEnabled(true);
hitStrokeWidth(hitStrokeWidth)
get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth
Parameters:
hitStrokeWidth
(Number)
Returns: Number
Inherited from: Konva.Shape#hitStrokeWidth
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');
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:
strokeHitEnabled
(Boolean)
Returns: Boolean
Inherited from: Konva.Shape#strokeHitEnabled
Example:
// get strokeHitEnabled
var strokeHitEnabled = shape.strokeHitEnabled();
// set strokeHitEnabled
shape.strokeHitEnabled();
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:
perfectDrawEnabled
(Boolean)
Returns: Boolean
Inherited from: Konva.Shape#perfectDrawEnabled
Example:
// get perfectDrawEnabled
var perfectDrawEnabled = shape.perfectDrawEnabled();
// set perfectDrawEnabled
shape.perfectDrawEnabled();
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:
shadowForStrokeEnabled
(Boolean)
Returns: Boolean
Inherited from: Konva.Shape#shadowForStrokeEnabled
Example:
// get shadowForStrokeEnabled
var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
// set shadowForStrokeEnabled
shape.shadowForStrokeEnabled();
lineJoin(lineJoin)
get/set line join. Can be miter, round, or bevel. The default is miter
Parameters:
lineJoin
(String)
Returns: String
Inherited from: Konva.Shape#lineJoin
Example:
// get line join
var lineJoin = shape.lineJoin();
// set line join
shape.lineJoin('round');
lineCap(lineCap)
get/set line cap. Can be butt, round, or square
Parameters:
lineCap
(String)
Returns: String
Inherited from: Konva.Shape#lineCap
Example:
// get line cap
var lineCap = shape.lineCap();
// set line cap
shape.lineCap('round');
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:
drawFunc
(function): drawing function
Returns: function
Inherited from: Konva.Shape#sceneFunc
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);
});
hitFunc(drawFunc)
get/set hit draw function. That function is used to draw custom hit area of a shape.
Parameters:
drawFunc
(function): drawing function
Returns: function
Inherited from: Konva.Shape#hitFunc
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);
});
dash(dash)
get/set dash array for stroke.
Parameters:
dash
(Array)
Returns: Array
Inherited from: Konva.Shape#dash
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]);
shadowColor(color)
get/set shadow color
Parameters:
color
(String)
Returns: String
Inherited from: Konva.Shape#shadowColor
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');
shadowBlur(blur)
get/set shadow blur
Parameters:
blur
(Number)
Returns: Number
Inherited from: Konva.Shape#shadowBlur
Example:
// get shadow blur
var shadowBlur = shape.shadowBlur();
// set shadow blur
shape.shadowBlur(10);
shadowOpacity(opacity)
get/set shadow opacity. must be a value between 0 and 1
Parameters:
opacity
(Number)
Returns: Number
Inherited from: Konva.Shape#shadowOpacity
Example:
// get shadow opacity
var shadowOpacity = shape.shadowOpacity();
// set shadow opacity
shape.shadowOpacity(0.5);
shadowOffset(offset)
get/set shadow offset
Parameters:
offset
(Object)offset.x
(Number)offset.y
(Number)
Returns: Object
Inherited from: Konva.Shape#shadowOffset
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:
x
(Number)
Returns: Number
Inherited from: Konva.Shape#shadowOffsetX
Example:
// get shadow offset x
var shadowOffsetX = shape.shadowOffsetX();
// set shadow offset x
shape.shadowOffsetX(5);
shadowOffsetY(y)
get/set shadow offset y
Parameters:
y
(Number)
Returns: Number
Inherited from: Konva.Shape#shadowOffsetY
Example:
// get shadow offset y
var shadowOffsetY = shape.shadowOffsetY();
// set shadow offset y
shape.shadowOffsetY(5);
fillPatternImage(image)
get/set fill pattern image
Parameters:
image
(Image): object
Returns: Image
Inherited from: Konva.Shape#fillPatternImage
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';
fill(color)
get/set fill color
Parameters:
color
(String)
Returns: String
Inherited from: Konva.Shape#fill
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);
fillPatternX(x)
get/set fill pattern x
Parameters:
x
(Number)
Returns: Number
Inherited from: Konva.Shape#fillPatternX
Example:
// get fill pattern x
var fillPatternX = shape.fillPatternX();
// set fill pattern x
shape.fillPatternX(20);
fillPatternY(y)
get/set fill pattern y
Parameters:
y
(Number)
Returns: Number
Inherited from: Konva.Shape#fillPatternY
Example:
// get fill pattern y
var fillPatternY = shape.fillPatternY();
// set fill pattern y
shape.fillPatternY(20);
fillLinearGradientColorStops(colorStops)
get/set fill linear gradient color stops
Parameters:
colorStops
(Array)
Returns: Array
colorStops
Inherited from: Konva.Shape#fillLinearGradientColorStops
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');
strokeLinearGradientColorStops(colorStops)
get/set stroke linear gradient color stops
Parameters:
colorStops
(Array)
Returns: Array
colorStops
Inherited from: Konva.Shape#strokeLinearGradientColorStops
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']);
fillRadialGradientStartRadius(radius)
get/set fill radial gradient start radius
Parameters:
radius
(Number)
Returns: Number
Inherited from: Konva.Shape#fillRadialGradientStartRadius
Example:
// get radial gradient start radius
var startRadius = shape.fillRadialGradientStartRadius();
// set radial gradient start radius
shape.fillRadialGradientStartRadius(0);
fillRadialGradientEndRadius(radius)
get/set fill radial gradient end radius
Parameters:
radius
(Number)
Returns: Number
Inherited from: Konva.Shape#fillRadialGradientEndRadius
Example:
// get radial gradient end radius
var endRadius = shape.fillRadialGradientEndRadius();
// set radial gradient end radius
shape.fillRadialGradientEndRadius(100);
fillRadialGradientColorStops(colorStops)
get/set fill radial gradient color stops
Parameters:
colorStops
(Number)
Returns: Array
Inherited from: Konva.Shape#fillRadialGradientColorStops
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');
fillPatternRepeat(repeat)
get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'
Parameters:
repeat
(String)
Returns: String
Inherited from: Konva.Shape#fillPatternRepeat
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');
fillEnabled(enabled)
get/set fill enabled flag
Parameters:
enabled
(Boolean)
Returns: Boolean
Inherited from: Konva.Shape#fillEnabled
Example:
// get fill enabled flag
var fillEnabled = shape.fillEnabled();
// disable fill
shape.fillEnabled(false);
// enable fill
shape.fillEnabled(true);
strokeEnabled(enabled)
get/set stroke enabled flag
Parameters:
enabled
(Boolean)
Returns: Boolean
Inherited from: Konva.Shape#strokeEnabled
Example:
// get stroke enabled flag
var strokeEnabled = shape.strokeEnabled();
// disable stroke
shape.strokeEnabled(false);
// enable stroke
shape.strokeEnabled(true);
shadowEnabled(enabled)
get/set shadow enabled flag
Parameters:
enabled
(Boolean)
Returns: Boolean
Inherited from: Konva.Shape#shadowEnabled
Example:
// get shadow enabled flag
var shadowEnabled = shape.shadowEnabled();
// disable shadow
shape.shadowEnabled(false);
// enable shadow
shape.shadowEnabled(true);
dashEnabled(enabled)
get/set dash enabled flag
Parameters:
enabled
(Boolean)
Returns: Boolean
Inherited from: Konva.Shape#dashEnabled
Example:
// get dash enabled flag
var dashEnabled = shape.dashEnabled();
// disable dash
shape.dashEnabled(false);
// enable dash
shape.dashEnabled(true);
strokeScaleEnabled(enabled)
get/set strokeScale enabled flag
Parameters:
enabled
(Boolean)
Returns: Boolean
Inherited from: Konva.Shape#strokeScaleEnabled
Example:
// get stroke scale enabled flag
var strokeScaleEnabled = shape.strokeScaleEnabled();
// disable stroke scale
shape.strokeScaleEnabled(false);
// enable stroke scale
shape.strokeScaleEnabled(true);
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:
priority
(String)
Returns: String
Inherited from: Konva.Shape#fillPriority
Example:
// get fill priority
var fillPriority = shape.fillPriority();
// set fill priority
shape.fillPriority('linear-gradient');
fillPatternOffset(offset)
get/set fill pattern offset
Parameters:
offset
(Object)offset.x
(Number)offset.y
(Number)
Returns: Object
Inherited from: Konva.Shape#fillPatternOffset
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:
x
(Number)
Returns: Number
Inherited from: Konva.Shape#fillPatternOffsetX
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:
y
(Number)
Returns: Number
Inherited from: Konva.Shape#fillPatternOffsetY
Example:
// get fill pattern offset y
var patternOffsetY = shape.fillPatternOffsetY();
// set fill pattern offset y
shape.fillPatternOffsetY(10);
fillPatternScale(scale)
get/set fill pattern scale
Parameters:
scale
(Object)scale.x
(Number)scale.y
(Number)
Returns: Object
Inherited from: Konva.Shape#fillPatternScale
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:
x
(Number)
Returns: Number
Inherited from: Konva.Shape#fillPatternScaleX
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:
y
(Number)
Returns: Number
Inherited from: Konva.Shape#fillPatternScaleY
Example:
// get fill pattern scale y
var patternScaleY = shape.fillPatternScaleY();
// set fill pattern scale y
shape.fillPatternScaleY(2);
fillLinearGradientStartPoint(startPoint)
get/set fill linear gradient start point
Parameters:
startPoint
(Object)startPoint.x
(Number)startPoint.y
(Number)
Returns: Object
Inherited from: Konva.Shape#fillLinearGradientStartPoint
Example:
// get fill linear gradient start point
var startPoint = shape.fillLinearGradientStartPoint();
// set fill linear gradient start point
shape.fillLinearGradientStartPoint({
x: 20,
y: 10
});
strokeLinearGradientStartPoint(startPoint)
get/set stroke linear gradient start point
Parameters:
startPoint
(Object)startPoint.x
(Number)startPoint.y
(Number)
Returns: Object
Inherited from: Konva.Shape#strokeLinearGradientStartPoint
Example:
// get stroke linear gradient start point
var startPoint = shape.strokeLinearGradientStartPoint();
// set stroke linear gradient start point
shape.strokeLinearGradientStartPoint({
x: 20,
y: 10
});
fillLinearGradientStartPointX(x)
get/set fill linear gradient start point x
Parameters:
x
(Number)
Returns: Number
Inherited from: Konva.Shape#fillLinearGradientStartPointX
Example:
// get fill linear gradient start point x
var startPointX = shape.fillLinearGradientStartPointX();
// set fill linear gradient start point x
shape.fillLinearGradientStartPointX(20);
linearLinearGradientStartPointX(x)
get/set stroke linear gradient start point x
Parameters:
x
(Number)
Returns: Number
Inherited from: Konva.Shape#linearLinearGradientStartPointX
Example:
// get stroke linear gradient start point x
var startPointX = shape.strokeLinearGradientStartPointX();
// set stroke linear gradient start point x
shape.strokeLinearGradientStartPointX(20);
fillLinearGradientStartPointY(y)
get/set fill linear gradient start point y
Parameters:
y
(Number)
Returns: Number
Inherited from: Konva.Shape#fillLinearGradientStartPointY
Example:
// get fill linear gradient start point y
var startPointY = shape.fillLinearGradientStartPointY();
// set fill linear gradient start point y
shape.fillLinearGradientStartPointY(20);
strokeLinearGradientStartPointY(y)
get/set stroke linear gradient start point y
Parameters:
y
(Number)
Returns: Number
Inherited from: Konva.Shape#strokeLinearGradientStartPointY
Example:
// get stroke linear gradient start point y
var startPointY = shape.strokeLinearGradientStartPointY();
// set stroke linear gradient start point y
shape.strokeLinearGradientStartPointY(20);
fillLinearGradientEndPoint(endPoint)
get/set fill linear gradient end point
Parameters:
endPoint
(Object)endPoint.x
(Number)endPoint.y
(Number)
Returns: Object
Inherited from: Konva.Shape#fillLinearGradientEndPoint
Example:
// get fill linear gradient end point
var endPoint = shape.fillLinearGradientEndPoint();
// set fill linear gradient end point
shape.fillLinearGradientEndPoint({
x: 20,
y: 10
});
strokeLinearGradientEndPoint(endPoint)
get/set stroke linear gradient end point
Parameters:
endPoint
(Object)endPoint.x
(Number)endPoint.y
(Number)
Returns: Object
Inherited from: Konva.Shape#strokeLinearGradientEndPoint
Example:
// get stroke linear gradient end point
var endPoint = shape.strokeLinearGradientEndPoint();
// set stroke linear gradient end point
shape.strokeLinearGradientEndPoint({
x: 20,
y: 10
});
fillLinearGradientEndPointX(x)
get/set fill linear gradient end point x
Parameters:
x
(Number)
Returns: Number
Inherited from: Konva.Shape#fillLinearGradientEndPointX
Example:
// get fill linear gradient end point x
var endPointX = shape.fillLinearGradientEndPointX();
// set fill linear gradient end point x
shape.fillLinearGradientEndPointX(20);
strokeLinearGradientEndPointX(x)
get/set fill linear gradient end point x
Parameters:
x
(Number)
Returns: Number
Inherited from: Konva.Shape#strokeLinearGradientEndPointX
Example:
// get stroke linear gradient end point x
var endPointX = shape.strokeLinearGradientEndPointX();
// set stroke linear gradient end point x
shape.strokeLinearGradientEndPointX(20);
fillLinearGradientEndPointY(y)
get/set fill linear gradient end point y
Parameters:
y
(Number)
Returns: Number
Inherited from: Konva.Shape#fillLinearGradientEndPointY
Example:
// get fill linear gradient end point y
var endPointY = shape.fillLinearGradientEndPointY();
// set fill linear gradient end point y
shape.fillLinearGradientEndPointY(20);
strokeLinearGradientEndPointY(y)
get/set stroke linear gradient end point y
Parameters:
y
(Number)
Returns: Number
Inherited from: Konva.Shape#strokeLinearGradientEndPointY
Example:
// get stroke linear gradient end point y
var endPointY = shape.strokeLinearGradientEndPointY();
// set stroke linear gradient end point y
shape.strokeLinearGradientEndPointY(20);
fillRadialGradientStartPoint(startPoint)
get/set fill radial gradient start point
Parameters:
startPoint
(Object)startPoint.x
(Number)startPoint.y
(Number)
Returns: Object
Inherited from: Konva.Shape#fillRadialGradientStartPoint
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:
x
(Number)
Returns: Number
Inherited from: Konva.Shape#fillRadialGradientStartPointX
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:
y
(Number)
Returns: Number
Inherited from: Konva.Shape#fillRadialGradientStartPointY
Example:
// get fill radial gradient start point y
var startPointY = shape.fillRadialGradientStartPointY();
// set fill radial gradient start point y
shape.fillRadialGradientStartPointY(20);
fillRadialGradientEndPoint(endPoint)
get/set fill radial gradient end point
Parameters:
endPoint
(Object)endPoint.x
(Number)endPoint.y
(Number)
Returns: Object
Inherited from: Konva.Shape#fillRadialGradientEndPoint
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:
x
(Number)
Returns: Number
Inherited from: Konva.Shape#fillRadialGradientEndPointX
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:
y
(Number)
Returns: Number
Inherited from: Konva.Shape#fillRadialGradientEndPointY
Example:
// get fill radial gradient end point y
var endPointY = shape.fillRadialGradientEndPointY();
// set fill radial gradient end point y
shape.fillRadialGradientEndPointY(20);
fillPatternRotation(rotation)
get/set fill pattern rotation in degrees
Parameters:
rotation
(Number)
Returns: Konva.Shape
Inherited from: Konva.Shape#fillPatternRotation
Example:
// get fill pattern rotation
var patternRotation = shape.fillPatternRotation();
// set fill pattern rotation
shape.fillPatternRotation(20);
fillRule(rotation)
get/set fill rule
Parameters:
rotation
(CanvasFillRule)
Returns: Konva.Shape
Inherited from: Konva.Shape#fillRule
Example:
// get fill rule
var fillRule = shape.fillRule();
// set fill rule
shape.fillRule('evenodd');
clearCache()
clear cached canvas
Returns: Konva.Node
Inherited from: Konva.Node#clearCache
Example:
node.clearCache();
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:
config
(Object) (optional)config.x
(Number) (optional)config.y
(Number) (optional)config.width
(Number) (optional)config.height
(Number) (optional)config.offset
(Number) (optional): increase canvas size byoffset
pixel in all directions.config.drawBorder
(Boolean) (optional): when set to true, a red border will be drawn around the cached region for debugging purposesconfig.pixelRatio
(Number) (optional): change quality (or pixel ratio) of cached image. pixelRatio = 2 will produce 2x sized cache.config.imageSmoothingEnabled
(Boolean) (optional): control imageSmoothingEnabled property of created canvas for cacheconfig.hitCanvasPixelRatio
(Number) (optional): change quality (or pixel ratio) of cached hit canvas.
Returns: Konva.Node
Inherited from: Konva.Node#cache
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
});
isCached()
determine if node is currently cached
Returns: Boolean
Inherited from: Konva.Node#isCached
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:
config
(Object)config.skipTransform
(Boolean) (optional): should we apply transform to node for calculating rect?config.skipShadow
(Boolean) (optional): should we apply shadow to the node for calculating bound box?config.skipStroke
(Boolean) (optional): should we apply stroke to the node for calculating bound box?config.relativeTo
(Object) (optional): calculate client rect relative to one of the parents
Returns: Object
rect with
\{x, y, width, height\}
properties
Inherited from: Konva.Node#getClientRect
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}
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:
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 hastarget
as main target of the event,currentTarget
as current node listener andevt
as native browser event.
Returns: Konva.Node
Inherited from: Konva.Node#on
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;
});
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:
evtStr
(String): e.g. 'click', 'mousedown touchstart', '.foobar'
Returns: Konva.Node
Inherited from: Konva.Node#off
Example:
// remove listener
node.off('click');
// remove multiple listeners
node.off('click touchstart');
// remove listener by name
node.off('click.foo');
remove()
remove a node from parent, but don't destroy. You can reuse the node later.
Returns: Konva.Node
Inherited from: Konva.Node#remove
Example:
node.remove();
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: Konva.Node#destroy
Example:
node.destroy();
getAttr(attr)
get attr
Parameters:
attr
(String)
Returns: Integer|String|Object|Array
Inherited from: Konva.Node#getAttr
Example:
var x = node.getAttr('x');
getAncestors()
get ancestors
Returns: Array
Inherited from: Konva.Node#getAncestors
Example:
shape.getAncestors().forEach(function(node) {
console.log(node.getId());
})
getAttrs()
get attrs object literal
Returns: Object
Inherited from: Konva.Node#getAttrs
setAttrs(config)
set multiple attrs at once using an object literal
Parameters:
config
(Object): object containing key value pairs
Returns: Konva.Node
Inherited from: Konva.Node#setAttrs
Example:
node.setAttrs({
x: 5,
fill: 'red'
});
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
Returns: Boolean
Inherited from: Konva.Node#isListening
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
Returns: Boolean
Inherited from: Konva.Node#isVisible
show()
show node. set visible = true
Returns: Konva.Node
Inherited from: Konva.Node#show
hide()
hide node. Hidden nodes are no longer detectable
Returns: Konva.Node
Inherited from: Konva.Node#hide
getAbsoluteZIndex()
get absolute z-index which takes into account sibling and ancestor indices
Returns: Integer
Inherited from: Konva.Node#getAbsoluteZIndex
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
Returns: Integer
Inherited from: Konva.Node#getDepth
getRelativePointerPosition()
get position of first pointer (like mouse or first touch) relative to local coordinates of current node
Returns: Konva.Node
Inherited from: Konva.Node#getRelativePointerPosition
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();
getAbsolutePosition(Ancestor)
get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor
Parameters:
Ancestor
(Object): optional ancestor node
Returns: Konva.Node
Inherited from: Konva.Node#getAbsolutePosition
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)
move(change)
move node by an amount relative to its current position
Parameters:
change
(Object)change.x
(Number)change.y
(Number)
Returns: Konva.Node
Inherited from: Konva.Node#move
Example:
// move node in x direction by 1px and y direction by 2px
node.move({
x: 1,
y: 2
});
rotate(theta)
rotate node by an amount in degrees relative to its current rotation
Parameters:
theta
(Number)
Returns: Konva.Node
Inherited from: Konva.Node#rotate
moveToTop()
move node to the top of its siblings
Returns: Boolean
Inherited from: Konva.Node#moveToTop
moveUp()
move node up
Returns: Boolean
flag is moved or not
Inherited from: Konva.Node#moveUp
moveDown()
move node down
Returns: Boolean
Inherited from: Konva.Node#moveDown
moveToBottom()
move node to the bottom of its siblings
Returns: Boolean
Inherited from: Konva.Node#moveToBottom
getAbsoluteOpacity()
get absolute opacity
Returns: Number
Inherited from: Konva.Node#getAbsoluteOpacity
moveTo(newContainer)
move node to another container
Parameters:
newContainer
(Container)
Returns: Konva.Node
Inherited from: Konva.Node#moveTo
Example:
// move node from current layer into layer2
node.moveTo(layer2);