Skip to main content

Line

new Konva.Line(config)

Line constructor.  Lines are defined by an array of points and a tension

Parameters

NameTypeDescription
configObject
pointsArrayFlat array of points coordinates. You should define them as [x1, y1, x2, y2, x3, y3].
tension (optional)NumberHigher values will result in a more curvy line. A value of 0 will result in no interpolation. The default is 0
closed (optional)Booleandefines whether or not the line shape is closed, creating a polygon or blob
bezier (optional)Booleanif no tension is provided but bezier=true, we draw the line as a bezier using the passed points
fill (optional)Stringfill color
fillPatternImage (optional)Imagefill pattern image
fillPatternX (optional)Number
fillPatternY (optional)Number
fillPatternOffset (optional)Objectobject with x and y component
fillPatternOffsetX (optional)Number
fillPatternOffsetY (optional)Number
fillPatternScale (optional)Objectobject with x and y component
fillPatternScaleX (optional)Number
fillPatternScaleY (optional)Number
fillPatternRotation (optional)Number
fillPatternRepeat (optional)Stringcan be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"
fillLinearGradientStartPoint (optional)Objectobject with x and y component
fillLinearGradientStartPointX (optional)Number
fillLinearGradientStartPointY (optional)Number
fillLinearGradientEndPoint (optional)Objectobject with x and y component
fillLinearGradientEndPointX (optional)Number
fillLinearGradientEndPointY (optional)Number
fillLinearGradientColorStops (optional)Arrayarray of color stops
fillRadialGradientStartPoint (optional)Objectobject with x and y component
fillRadialGradientStartPointX (optional)Number
fillRadialGradientStartPointY (optional)Number
fillRadialGradientEndPoint (optional)Objectobject with x and y component
fillRadialGradientEndPointX (optional)Number
fillRadialGradientEndPointY (optional)Number
fillRadialGradientStartRadius (optional)Number
fillRadialGradientEndRadius (optional)Number
fillRadialGradientColorStops (optional)Arrayarray of color stops
fillEnabled (optional)Booleanflag which enables or disables the fill. The default value is true
fillPriority (optional)Stringcan 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)Stringstroke color
strokeWidth (optional)Numberstroke width
fillAfterStrokeEnabled (optional)BooleanShould we draw fill AFTER stroke? Default is false.
hitStrokeWidth (optional)Numbersize of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
strokeHitEnabled (optional)Booleanflag which enables or disables stroke hit region. The default is true
perfectDrawEnabled (optional)Booleanflag which enables or disables using buffer canvas. The default is true
shadowForStrokeEnabled (optional)Booleanflag which enables or disables shadow for stroke. The default is true
strokeScaleEnabled (optional)Booleanflag which enables or disables stroke scale. The default is true
strokeEnabled (optional)Booleanflag which enables or disables the stroke. The default value is true
lineJoin (optional)Stringcan be miter, round, or bevel. The default is miter
lineCap (optional)Stringcan be butt, round, or square. The default is butt
shadowColor (optional)String
shadowBlur (optional)Number
shadowOffset (optional)Objectobject with x and y component
shadowOffsetX (optional)Number
shadowOffsetY (optional)Number
shadowOpacity (optional)Numbershadow opacity. Can be any real number between 0 and 1
shadowEnabled (optional)Booleanflag which enables or disables the shadow. The default value is true
dash (optional)Array
dashEnabled (optional)Booleanflag 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)Booleanwhether or not the node is listening for events
id (optional)Stringunique id
name (optional)Stringnon-unique name
opacity (optional)Numberdetermines node opacity. Can be any number between 0 and 1
scale (optional)Objectset scale
scaleX (optional)Numberset scale x
scaleY (optional)Numberset scale y
rotation (optional)Numberrotation in degrees
offset (optional)Objectoffset from center point and rotation point
offsetX (optional)Numberset offset x
offsetY (optional)Numberset offset y
draggable (optional)Booleanmakes 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

_eachTensionSegment()

Report every curve segment of a line with a tension, in draw order. Both the scene function and the bounding rect read the shape through this, so that they can not disagree about which curve the line is. The handlers take plain numbers, because this runs on every frame.

closed(closed)

get/set closed flag. The default is false

Parameters:

  • closed (Boolean)

Returns: Boolean

Example:

// get closed flag
var closed = line.closed();

// close the shape
line.closed(true);

// open the shape
line.closed(false);

bezier(bezier)

get/set bezier flag. The default is false

Parameters:

  • bezier (Boolean)

Returns: Boolean

Example:

// get whether the line is a bezier
var isBezier = line.bezier();

// set whether the line is a bezier
line.bezier(true);

tension(tension)

get/set tension

Parameters:

  • tension (Number): Higher values will result in a more curvy line. A value of 0 will result in no interpolation. The default is 0

Returns: Number

Example:

// get tension
var tension = line.tension();

// set tension
line.tension(3);

points(points)

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

Parameters:

  • points (Array)

Returns: 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]));

Inherited Methods

Konva.Line also has all methods of its parent classes. Each link below opens the full documentation of the method on the class that defines it.

From Konva.Shape

From Konva.Node