Merge branch 'seethroughtrees-feature/arrow'

This commit is contained in:
Anton Lavrenov 2018-04-02 10:48:08 +07:00
commit 43e628680c
4 changed files with 64 additions and 3 deletions

View File

@ -2,7 +2,7 @@
* Konva JavaScript Framework v2.0.2 * Konva JavaScript Framework v2.0.2
* http://konvajs.github.io/ * http://konvajs.github.io/
* Licensed under the MIT * Licensed under the MIT
* Date: Thu Mar 29 2018 * Date: Mon Apr 02 2018
* *
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
@ -18529,7 +18529,24 @@
ctx.closePath(); ctx.closePath();
ctx.restore(); ctx.restore();
} }
// here is a tricky part
// we need to disable dash for arrow pointers
var isDashEnabled = this.dashEnabled();
if (isDashEnabled) {
// manually disable dash for head
// it is better not to use setter here,
// because it will trigger attr change event
this.attrs.dashEnabled = false;
ctx.setLineDash([]);
}
ctx.fillStrokeShape(this); ctx.fillStrokeShape(this);
// restore old value
if (isDashEnabled) {
this.attrs.dashEnabled = true;
}
} }
}; };

4
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -66,7 +66,24 @@
ctx.closePath(); ctx.closePath();
ctx.restore(); ctx.restore();
} }
// here is a tricky part
// we need to disable dash for arrow pointers
var isDashEnabled = this.dashEnabled();
if (isDashEnabled) {
// manually disable dash for head
// it is better not to use setter here,
// because it will trigger attr change event
this.attrs.dashEnabled = false;
ctx.setLineDash([]);
}
ctx.fillStrokeShape(this); ctx.fillStrokeShape(this);
// restore old value
if (isDashEnabled) {
this.attrs.dashEnabled = true;
}
} }
}; };

View File

@ -35,4 +35,31 @@ suite('Arrow', function() {
layer.draw(); layer.draw();
showHit(layer); showHit(layer);
}); });
test('do not draw dash for head', function() {
var stage = addStage();
var layer = new Konva.Layer();
var arrow = new Konva.Arrow({
points: [50, 50, 100, 100],
stroke: 'red',
fill: 'blue',
strokeWidth: 5,
pointerWidth: 20,
pointerLength: 20,
dash: [5, 5]
});
layer.add(arrow);
stage.add(layer);
var trace = layer.getContext().getTrace();
// console.log(trace);
assert.equal(
trace,
'clearRect(0,0,578,200);save();transform(1,0,0,1,0,0);beginPath();moveTo(50,50);lineTo(100,100);setLineDash(5,5);lineDashOffset=0;lineWidth=5;strokeStyle=red;stroke();save();beginPath();translate(100,100);rotate(0.785);moveTo(0,0);lineTo(-20,10);lineTo(-20,-10);closePath();restore();setLineDash();fillStyle=blue;fill();lineWidth=5;strokeStyle=red;stroke();restore();'
);
});
}); });