From 53c70a093b6a44524cf3fb4151a435521efc3da4 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Fri, 14 Oct 2022 22:19:11 +0200 Subject: [PATCH] fix(edges): edge text not aligning correctly into center --- packages/core/src/components/Edges/EdgeText.vue | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/core/src/components/Edges/EdgeText.vue b/packages/core/src/components/Edges/EdgeText.vue index 989fe9df..642425cf 100644 --- a/packages/core/src/components/Edges/EdgeText.vue +++ b/packages/core/src/components/Edges/EdgeText.vue @@ -13,13 +13,17 @@ const { labelBgBorderRadius = 2, } = defineProps() -const el = ref() - let box = $ref({ x: 0, y: 0, width: 0, height: 0 }) -onMounted(() => { - box = el.value!.getBBox() -}) +const el = (el: any) => { + if (!el) return + + const nextBox = el.getBBox() + + if (nextBox.width !== box.width || nextBox.height !== box.height) { + box = nextBox + } +} const transform = computed(() => `translate(${x - box.width / 2} ${y - box.height / 2})`)