mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
fix arrow.getClientRect() calculations. fix #1851
This commit is contained in:
parent
14118054f6
commit
00ee0846d5
@ -151,9 +151,9 @@ export class Arrow extends Line<ArrowConfig> {
|
|||||||
const lineRect = super.getSelfRect();
|
const lineRect = super.getSelfRect();
|
||||||
const offset = this.pointerWidth() / 2;
|
const offset = this.pointerWidth() / 2;
|
||||||
return {
|
return {
|
||||||
x: lineRect.x - offset,
|
x: lineRect.x,
|
||||||
y: lineRect.y - offset,
|
y: lineRect.y - offset,
|
||||||
width: lineRect.width + offset * 2,
|
width: lineRect.width,
|
||||||
height: lineRect.height + offset * 2,
|
height: lineRect.height + offset * 2,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -229,4 +229,33 @@ describe('Arrow', function () {
|
|||||||
|
|
||||||
cloneAndCompareLayer(layer, 255, 50);
|
cloneAndCompareLayer(layer, 255, 50);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getClientRect', function () {
|
||||||
|
var stage = addStage();
|
||||||
|
var layer = new Konva.Layer();
|
||||||
|
|
||||||
|
var arrow = new Konva.Arrow({
|
||||||
|
points: [50, 50, 150, 50],
|
||||||
|
stroke: 'blue',
|
||||||
|
fill: 'blue',
|
||||||
|
// large stroke width will not work :(
|
||||||
|
strokeWidth: 1,
|
||||||
|
draggable: true,
|
||||||
|
tension: 0,
|
||||||
|
pointerLength: 10,
|
||||||
|
pointerWidth: 20,
|
||||||
|
});
|
||||||
|
layer.add(arrow);
|
||||||
|
|
||||||
|
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
var rect = arrow.getClientRect({ skipStroke: true });
|
||||||
|
layer.add(new Konva.Rect({...rect, stroke: 'red' }));
|
||||||
|
|
||||||
|
assert.equal(rect.x, 50);
|
||||||
|
assert.equal(rect.y, 40);
|
||||||
|
assert.equal(rect.width, 100);
|
||||||
|
assert.equal(rect.height, 20);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -741,7 +741,7 @@ describe('Text', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
it.only('text multi line with justify align and decoration', function () {
|
it('text multi line with justify align and decoration', function () {
|
||||||
var stage = addStage();
|
var stage = addStage();
|
||||||
var layer = new Konva.Layer();
|
var layer = new Konva.Layer();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user