KineticJS icon indicating copy to clipboard operation
KineticJS copied to clipboard

Line (Shape) stroke scaling problem

Open mihailox opened this issue 13 years ago • 6 comments

Hi,

I have just noticed a problem with Line stroke scaling in new version of Chrome. (KineticJs 4.7.4)

main_stage  =   new Kinetic.Stage({
                width: 400,
                height: 400,
                container: 'cont'
            });
            main_layer  =   new Kinetic.Layer();
            bg          =   new Kinetic.Rect({
                x:0,
                y:0,
                width:400,
                height:400,
                fill:'limegreen',
                opacity:0.5
            });
            main_layer.add(bg);
            line        =   new Kinetic.Line({
                x:0,
                y:0,
                points: [{x:0,y:0},{x:100,y:100}],
                stroke:'#000000',
                strokeWidth:1,
                strokeScaleEnabled:false
            });
            main_stage.add(main_layer);
            main_layer.add(line);
            main_layer.setScaleY(4);
            main_layer.draw();

That piece of code worked fine on all browsers until 2 days ago when new chrome version popped up. When strokeScaleEnabled is set to false it basically stops all forms of scaling where previously it only stopped scaling in terms of width (and still does in Forefox, Opera and Safari).

To elaborate a bit further consider this, you want to have a rectangle which is scaled differently on X axis and Y axis (0 on X and 4 on Y for example), in previous versions of Chrome and current ones of other browsers when setting strokeScaleEnabled:false you would get a rectangle which is scaled right and with its stroke width kept intact unaffected by the scaling of the rectangle itself, and setting strokeScaleEnabled:true would affect stroke by thickening the lines normal to Y axis in this example (code sample provided below).

What happens in current Chrome version is that when using strokeScaleEnabled:false rectangle or its stroke to be exact just vanishes (same happens to lines poly's and other elements with stroke)

main_stage  =   new Kinetic.Stage({
                width: 400,
                height: 400,
                container: 'cont2'
            });
            main_layer  =   new Kinetic.Layer();
            bg          =   new Kinetic.Rect({
                x:0,
                y:0,
                width:400,
                height:400,
                fill:'limegreen',
                opacity:0.5
            });
            main_layer.add(bg);
            rect  = new Kinetic.Rect({
                x:50,
                y:50,
                width:50,
                height:50,
                stroke:'#000000',
                strokeWidth:1,
                strokeScaleEnabled:false
            });

            main_stage.add(main_layer);
            main_layer.add(rect);
            main_layer.setScaleY(4);
            main_layer.draw();

Chrome (strokeScaleEnabled:true) chrome_stroke_true Chrome (strokeScaleEnabled:false) chrome_stroke_false

Opera (strokeScaleEnabled:false) (same as Firefox and Safari) opera_stroke_false

mihailox avatar Nov 16 '13 15:11 mihailox

There seems to be a problem with stroke offset when strokeScaleEnabled:false is set and setScale is used. I've just tried drawing a rectangle in the middle of canvas layer and made it drag-able, when i moved it to the top left corner of the canvas, stroke started moving in in another direction like it was mirrored diagonally.

mihailox avatar Nov 16 '13 16:11 mihailox

For tests: http://jsfiddle.net/lavrton/T43NK/6/ As @CyranX said : try to drag red rect to top left corner.

lavrton avatar Nov 16 '13 16:11 lavrton

I haven't dabbled much but problem seems to happen after applying this.setTransform(1, 0, 0, 1, 0, 0); at line 1976. No clue what changed in latest chrome build but seems it affects all versions (stable, beta, dev and canary) from 31.0.1650.57 (14th Nov. edition and up). Weird thing is that works perfect in other browsers

mihailox avatar Nov 16 '13 23:11 mihailox

I ran into this problem as well. My app relies on drawing lines that need to stay the same width while scaling...I just about died when the chrome update happened...ha!

Here's what I've observed. I can verify that the issue appears to be at line 1976 as stated above. An easy way to reproduce the issue: just go to the kineticjs tutorial here and add the strokeScaleEnabled to the rectangle. Toggle it between true and false to see the results.

http://www.html5canvastutorials.com/kineticjs/html5-canvas-kineticjs-rect-tutorial/

In chrome, setting the value to false now causes the stroke to disappear. At first I was convinced that this was purely a chrome bug, however, it looks like FF behaves strangely too. If you do the above in FF, the stroke will stick around, but its width will vary even when scale=1...weird!

Hope this helps. I'm going to try to work around it by dividing my default line widths by the current scale and using that as the current line width.

andynemzek avatar Nov 18 '13 01:11 andynemzek

This chrome bug may be related to this...looks like it was just fixed. https://code.google.com/p/chromium/issues/detail?id=319541#c6

andynemzek avatar Nov 18 '13 20:11 andynemzek

In my machine latest example http://jsfiddle.net/lavrton/T43NK/6/ (Chrome) works as expected. I will close the issue.

lavrton avatar Mar 03 '14 08:03 lavrton