From 37867cc632f5ba4a10ce28bb0347b2d205b53381 Mon Sep 17 00:00:00 2001 From: drew08t Date: Thu, 2 Nov 2023 21:40:55 -0700 Subject: [PATCH] Fix types in coordinate calc function --- public/app/plugins/panel/canvas/utils.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/public/app/plugins/panel/canvas/utils.ts b/public/app/plugins/panel/canvas/utils.ts index 2011be6f38c..d282a237691 100644 --- a/public/app/plugins/panel/canvas/utils.ts +++ b/public/app/plugins/panel/canvas/utils.ts @@ -200,18 +200,15 @@ export const calculateCoordinates = ( const x1 = sourceHorizontalCenter + (info.source.x * sourceRect.width) / 2 / transformScale; const y1 = sourceVerticalCenter - (info.source.y * sourceRect.height) / 2 / transformScale; - let x2; - let y2; + let x2: number; + let y2: number; + const targetRect = target.div?.getBoundingClientRect(); + if (info.targetName && targetRect) { + const targetHorizontalCenter = targetRect.left - parentRect.left + targetRect.width / 2; + const targetVerticalCenter = targetRect.top - parentRect.top + targetRect.height / 2; - if (info.targetName) { - const targetRect = target.div?.getBoundingClientRect(); - if (targetRect) { - const targetHorizontalCenter = targetRect.left - parentRect.left + targetRect.width / 2; - const targetVerticalCenter = targetRect.top - parentRect.top + targetRect.height / 2; - - x2 = targetHorizontalCenter + (info.target.x * targetRect.width) / 2; - y2 = targetVerticalCenter - (info.target.y * targetRect.height) / 2; - } + x2 = targetHorizontalCenter + (info.target.x * targetRect.width) / 2; + y2 = targetVerticalCenter - (info.target.y * targetRect.height) / 2; } else { const parentHorizontalCenter = parentRect.width / 2; const parentVerticalCenter = parentRect.height / 2;