how to fix width of line drawn on canvas using fabric.js

1.2k views Asked by At

I am using fabric.JS to draw a line. I can draw a line successfully but the problem is, that whenever I scale that line, the length of the line should only increase and not the width. Any one know any property related to that?

line = new fabric.Line([250, 125, 250, 175], {
                left: 170,
                top: 150,
                strokeWidth: 4,
                fill: 'red',
                stroke: 'red',
                flipX: 'false'
            });
1

There are 1 answers

0
SilentTremor On

line.strokeWidth

is defining your line width, you are doing incorrect scaling.

do this:

var beforeWidth = line.strokeWidth;

//scaling process

 line.strokeWidth = beforeWidth;