From 00ee0846d58a97b976f8b6e24315d21506bfea82 Mon Sep 17 00:00:00 2001 From: Anton Lavrevov Date: Sun, 1 Dec 2024 19:18:41 -0600 Subject: [PATCH] fix arrow.getClientRect() calculations. fix #1851 --- src/shapes/Arrow.ts | 4 ++-- test/unit/Arrow-test.ts | 29 +++++++++++++++++++++++++++++ test/unit/Text-test.ts | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/shapes/Arrow.ts b/src/shapes/Arrow.ts index 72c735025..2503743ff 100644 --- a/src/shapes/Arrow.ts +++ b/src/shapes/Arrow.ts @@ -151,9 +151,9 @@ export class Arrow extends Line { 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, }; } diff --git a/test/unit/Arrow-test.ts b/test/unit/Arrow-test.ts index 7bc2c1495..ace482a61 100644 --- a/test/unit/Arrow-test.ts +++ b/test/unit/Arrow-test.ts @@ -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); + }); }); diff --git a/test/unit/Text-test.ts b/test/unit/Text-test.ts index 8d9bb850b..6f5ae0016 100644 --- a/test/unit/Text-test.ts +++ b/test/unit/Text-test.ts @@ -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();