diff --git a/src/components/Edges/BezierEdge.tsx b/src/components/Edges/BezierEdge.tsx
index b0b77502..fb7efc21 100644
--- a/src/components/Edges/BezierEdge.tsx
+++ b/src/components/Edges/BezierEdge.tsx
@@ -71,19 +71,6 @@ export default defineComponent({
});
});
- const text = props.label ? (
-
- ) : null;
-
const markerEnd = reactify((arrowHeadType?: ArrowHeadType, markerEndId?: string) => getMarkerEnd(arrowHeadType, markerEndId));
return () => (
@@ -94,7 +81,18 @@ export default defineComponent({
d={path({ ...props }).value}
marker-end={markerEnd(props.arrowHeadType, props.markerEndId).value}
/>
- {text}
+ {props.label ? (
+
+ ) : null}
>
);
}
diff --git a/src/components/Edges/EdgeText.tsx b/src/components/Edges/EdgeText.tsx
index 8a73447c..987ea993 100644
--- a/src/components/Edges/EdgeText.tsx
+++ b/src/components/Edges/EdgeText.tsx
@@ -1,5 +1,5 @@
import { EdgeTextProps, Rect } from '../../types';
-import { defineComponent, PropType, ref, watch } from 'vue';
+import { defineComponent, PropType, ref, watchEffect } from 'vue';
export default defineComponent({
props: {
@@ -12,7 +12,7 @@ export default defineComponent({
required: true
},
label: {
- type: String as PropType,
+ type: [String, Object] as PropType,
required: true
},
labelStyle: {
@@ -39,25 +39,20 @@ export default defineComponent({
setup(props, { slots }) {
const edgeRef = ref(null);
const edgeTextBox = ref({ x: 0, y: 0, width: 0, height: 0 });
- const label = ref(props.label);
- watch(label, () => {
- if (edgeRef.value) {
- const textBbox = edgeRef.value.getBBox();
+ watchEffect(() => {
+ const textBbox = edgeRef.value?.getBBox();
- edgeRef.value = {
+ if (textBbox) {
+ edgeTextBox.value = {
x: textBbox.x,
y: textBbox.y,
width: textBbox.width,
height: textBbox.height
- } as any;
+ };
}
});
- if (typeof label.value === 'undefined' || !label.value) {
- return null;
- }
-
return () => (
)}
-
- {label}
+
+ {props.label}
{slots.default ? slots.default() : ''}
diff --git a/src/components/Edges/SmoothStepEdge.tsx b/src/components/Edges/SmoothStepEdge.tsx
index 1015d522..6178e9e0 100644
--- a/src/components/Edges/SmoothStepEdge.tsx
+++ b/src/components/Edges/SmoothStepEdge.tsx
@@ -123,19 +123,6 @@ export default defineComponent({
const markerEnd = reactify((arrowHeadType?: ArrowHeadType, markerEndId?: string) => getMarkerEnd(arrowHeadType, markerEndId));
- const text = props.label ? (
-
- ) : null;
-
return () => (
<>
- {text}
+ {props.label ? (
+
+ ) : null}
>
);
}
diff --git a/src/components/Edges/StraightEdge.tsx b/src/components/Edges/StraightEdge.tsx
index 45e0332d..66c173b6 100644
--- a/src/components/Edges/StraightEdge.tsx
+++ b/src/components/Edges/StraightEdge.tsx
@@ -19,19 +19,6 @@ export default defineComponent({
return targetX < sourceX ? targetX + xOffset : targetX - xOffset;
});
- const text = props.label ? (
-
- ) : null;
-
const markerEnd = reactify((arrowHeadType?: ArrowHeadType, markerEndId?: string) => getMarkerEnd(arrowHeadType, markerEndId));
return () => (
@@ -42,7 +29,18 @@ export default defineComponent({
d={`M ${props.sourceX},${props.sourceY}L ${props.targetX},${props.targetY}`}
marker-end={markerEnd(props.arrowHeadType, props.markerEndId).value}
/>
- {text}
+ {props.label ? (
+
+ ) : null}
>
);
}
diff --git a/src/components/Edges/utils.ts b/src/components/Edges/utils.ts
index ad2b9ca8..f143ab7e 100644
--- a/src/components/Edges/utils.ts
+++ b/src/components/Edges/utils.ts
@@ -91,9 +91,9 @@ export const DefaultEdgeProps = {
default: Position.Top
},
label: {
- type: String as PropType,
+ type: [String, Object] as PropType,
required: false,
- default: undefined
+ default: () => {}
},
labelStyle: {
type: Object as PropType,
@@ -106,7 +106,7 @@ export const DefaultEdgeProps = {
default: false
},
labelBgStyle: {
- type: String as PropType,
+ type: [String, Object] as PropType,
required: false,
default: undefined
},
@@ -121,7 +121,7 @@ export const DefaultEdgeProps = {
default: undefined
},
arrowHeadType: {
- type: Object as PropType,
+ type: String as PropType,
required: false,
default: undefined
},