Skip to main content

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.

import Konva from 'konva';

const stage = new Konva.Stage({
  container: 'container',
  width: window.innerWidth,
  height: window.innerHeight,
});

const layer = new Konva.Layer();
stage.add(layer);

const triangle = new Konva.RegularPolygon({
  x: stage.width() / 2,
  y: stage.height() / 2,
  sides: 3,
  radius: 70,
  fill: '#00D2FF',
  stroke: 'black',
  strokeWidth: 20,
  lineJoin: 'miter'
});

layer.add(triangle);

triangle.on('mouseenter', function() {
  const lineJoins = ['miter', 'bevel', 'round'];
  const index = lineJoins.indexOf(triangle.lineJoin());
  const nextIndex = (index + 1) % lineJoins.length;
  triangle.lineJoin(lineJoins[nextIndex]);
  layer.draw();
});