Skip to content

Commit

Permalink
fix arrow.getClientRect() calculations. fix #1851
Browse files Browse the repository at this point in the history
  • Loading branch information
lavrton committed Dec 2, 2024
1 parent 1411805 commit 00ee084
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/shapes/Arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ export class Arrow extends Line<ArrowConfig> {
const lineRect = super.getSelfRect();
const offset = this.pointerWidth() / 2;
return {
x: lineRect.x - offset,
x: lineRect.x,
y: lineRect.y - offset,
width: lineRect.width + offset * 2,
width: lineRect.width,
height: lineRect.height + offset * 2,
};
}
Expand Down
29 changes: 29 additions & 0 deletions test/unit/Arrow-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,33 @@ describe('Arrow', function () {

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);
});
});
2 changes: 1 addition & 1 deletion test/unit/Text-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 layer = new Konva.Layer();

Expand Down

0 comments on commit 00ee084

Please sign in to comment.