mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 03:13:41 +08:00
refix dash
This commit is contained in:
parent
cfe0f9aa8a
commit
504bab7261
19
konva.js
19
konva.js
@ -2,7 +2,7 @@
|
||||
* Konva JavaScript Framework v2.0.2
|
||||
* http://konvajs.github.io/
|
||||
* Licensed under the MIT
|
||||
* Date: Thu Mar 29 2018
|
||||
* Date: Mon Apr 02 2018
|
||||
*
|
||||
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
||||
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
||||
@ -18529,7 +18529,24 @@
|
||||
ctx.closePath();
|
||||
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);
|
||||
|
||||
// restore old value
|
||||
if (isDashEnabled) {
|
||||
this.attrs.dashEnabled = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
4
konva.min.js
vendored
4
konva.min.js
vendored
File diff suppressed because one or more lines are too long
@ -67,20 +67,23 @@
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
this._fillArrowHead(ctx);
|
||||
},
|
||||
|
||||
// removing dash from arrow-head only, but putting it back to the
|
||||
// intial value after render
|
||||
_fillArrowHead: function(ctx) {
|
||||
// here is a tricky part
|
||||
// we need to disable dash for arrow pointers
|
||||
var isDashEnabled = this.dashEnabled();
|
||||
if (isDashEnabled) {
|
||||
this.dashEnabled(false);
|
||||
// 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);
|
||||
|
||||
this.dashEnabled(isDashEnabled);
|
||||
// restore old value
|
||||
if (isDashEnabled) {
|
||||
this.attrs.dashEnabled = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -35,4 +35,31 @@ suite('Arrow', function() {
|
||||
layer.draw();
|
||||
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();'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user