fix: edges not updating text
This commit is contained in:
@@ -71,19 +71,6 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const text = props.label ? (
|
|
||||||
<EdgeText
|
|
||||||
x={centered({ ...props }).value[0]}
|
|
||||||
y={centered({ ...props }).value[1]}
|
|
||||||
label={props.label}
|
|
||||||
labelStyle={props.labelStyle}
|
|
||||||
labelShowBg={props.labelShowBg}
|
|
||||||
labelBgStyle={props.labelBgStyle}
|
|
||||||
labelBgPadding={props.labelBgPadding}
|
|
||||||
labelBgBorderRadius={props.labelBgBorderRadius}
|
|
||||||
/>
|
|
||||||
) : null;
|
|
||||||
|
|
||||||
const markerEnd = reactify((arrowHeadType?: ArrowHeadType, markerEndId?: string) => getMarkerEnd(arrowHeadType, markerEndId));
|
const markerEnd = reactify((arrowHeadType?: ArrowHeadType, markerEndId?: string) => getMarkerEnd(arrowHeadType, markerEndId));
|
||||||
|
|
||||||
return () => (
|
return () => (
|
||||||
@@ -94,7 +81,18 @@ export default defineComponent({
|
|||||||
d={path({ ...props }).value}
|
d={path({ ...props }).value}
|
||||||
marker-end={markerEnd(props.arrowHeadType, props.markerEndId).value}
|
marker-end={markerEnd(props.arrowHeadType, props.markerEndId).value}
|
||||||
/>
|
/>
|
||||||
{text}
|
{props.label ? (
|
||||||
|
<EdgeText
|
||||||
|
x={centered({ ...props }).value[0]}
|
||||||
|
y={centered({ ...props }).value[1]}
|
||||||
|
label={props.label}
|
||||||
|
labelStyle={props.labelStyle}
|
||||||
|
labelShowBg={props.labelShowBg}
|
||||||
|
labelBgStyle={props.labelBgStyle}
|
||||||
|
labelBgPadding={props.labelBgPadding}
|
||||||
|
labelBgBorderRadius={props.labelBgBorderRadius}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { EdgeTextProps, Rect } from '../../types';
|
import { EdgeTextProps, Rect } from '../../types';
|
||||||
import { defineComponent, PropType, ref, watch } from 'vue';
|
import { defineComponent, PropType, ref, watchEffect } from 'vue';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
@@ -12,7 +12,7 @@ export default defineComponent({
|
|||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
label: {
|
label: {
|
||||||
type: String as PropType<EdgeTextProps['label']>,
|
type: [String, Object] as PropType<EdgeTextProps['label']>,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
labelStyle: {
|
labelStyle: {
|
||||||
@@ -39,25 +39,20 @@ export default defineComponent({
|
|||||||
setup(props, { slots }) {
|
setup(props, { slots }) {
|
||||||
const edgeRef = ref<SVGTextElement | null>(null);
|
const edgeRef = ref<SVGTextElement | null>(null);
|
||||||
const edgeTextBox = ref<Rect>({ x: 0, y: 0, width: 0, height: 0 });
|
const edgeTextBox = ref<Rect>({ x: 0, y: 0, width: 0, height: 0 });
|
||||||
const label = ref(props.label);
|
|
||||||
|
|
||||||
watch(label, () => {
|
watchEffect(() => {
|
||||||
if (edgeRef.value) {
|
const textBbox = edgeRef.value?.getBBox();
|
||||||
const textBbox = edgeRef.value.getBBox();
|
|
||||||
|
|
||||||
edgeRef.value = {
|
if (textBbox) {
|
||||||
|
edgeTextBox.value = {
|
||||||
x: textBbox.x,
|
x: textBbox.x,
|
||||||
y: textBbox.y,
|
y: textBbox.y,
|
||||||
width: textBbox.width,
|
width: textBbox.width,
|
||||||
height: textBbox.height
|
height: textBbox.height
|
||||||
} as any;
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof label.value === 'undefined' || !label.value) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => (
|
return () => (
|
||||||
<g
|
<g
|
||||||
transform={`translate(${props.x - edgeTextBox.value.width / 2} ${props.y - edgeTextBox.value.height / 2})`}
|
transform={`translate(${props.x - edgeTextBox.value.width / 2} ${props.y - edgeTextBox.value.height / 2})`}
|
||||||
@@ -75,8 +70,8 @@ export default defineComponent({
|
|||||||
ry={props.labelBgBorderRadius}
|
ry={props.labelBgBorderRadius}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<text class="revue-flow__edge-text" y={edgeTextBox.value.height / 2} dy="0.3em" ref={edgeRef} style={props.labelStyle}>
|
<text ref={edgeRef} class="revue-flow__edge-text" y={edgeTextBox.value.height / 2} dy="0.3em" style={props.labelStyle}>
|
||||||
{label}
|
{props.label}
|
||||||
</text>
|
</text>
|
||||||
{slots.default ? slots.default() : ''}
|
{slots.default ? slots.default() : ''}
|
||||||
</g>
|
</g>
|
||||||
|
|||||||
@@ -123,19 +123,6 @@ export default defineComponent({
|
|||||||
|
|
||||||
const markerEnd = reactify((arrowHeadType?: ArrowHeadType, markerEndId?: string) => getMarkerEnd(arrowHeadType, markerEndId));
|
const markerEnd = reactify((arrowHeadType?: ArrowHeadType, markerEndId?: string) => getMarkerEnd(arrowHeadType, markerEndId));
|
||||||
|
|
||||||
const text = props.label ? (
|
|
||||||
<EdgeText
|
|
||||||
x={centered.value[0]}
|
|
||||||
y={centered.value[1]}
|
|
||||||
label={props.label}
|
|
||||||
labelStyle={props.labelStyle}
|
|
||||||
labelShowBg={props.labelShowBg}
|
|
||||||
labelBgStyle={props.labelBgStyle}
|
|
||||||
labelBgPadding={props.labelBgPadding}
|
|
||||||
labelBgBorderRadius={props.labelBgBorderRadius}
|
|
||||||
/>
|
|
||||||
) : null;
|
|
||||||
|
|
||||||
return () => (
|
return () => (
|
||||||
<>
|
<>
|
||||||
<path
|
<path
|
||||||
@@ -144,7 +131,18 @@ export default defineComponent({
|
|||||||
d={path.value}
|
d={path.value}
|
||||||
marker-end={markerEnd(props.arrowHeadType, props.markerEndId).value}
|
marker-end={markerEnd(props.arrowHeadType, props.markerEndId).value}
|
||||||
/>
|
/>
|
||||||
{text}
|
{props.label ? (
|
||||||
|
<EdgeText
|
||||||
|
x={centered.value[0]}
|
||||||
|
y={centered.value[1]}
|
||||||
|
label={props.label}
|
||||||
|
labelStyle={props.labelStyle}
|
||||||
|
labelShowBg={props.labelShowBg}
|
||||||
|
labelBgStyle={props.labelBgStyle}
|
||||||
|
labelBgPadding={props.labelBgPadding}
|
||||||
|
labelBgBorderRadius={props.labelBgBorderRadius}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,19 +19,6 @@ export default defineComponent({
|
|||||||
return targetX < sourceX ? targetX + xOffset : targetX - xOffset;
|
return targetX < sourceX ? targetX + xOffset : targetX - xOffset;
|
||||||
});
|
});
|
||||||
|
|
||||||
const text = props.label ? (
|
|
||||||
<EdgeText
|
|
||||||
x={centerX(props.targetX, props.sourceX).value}
|
|
||||||
y={centerY(props.targetY, props.sourceY).value}
|
|
||||||
label={props.label}
|
|
||||||
labelStyle={props.labelStyle}
|
|
||||||
labelShowBg={props.labelShowBg}
|
|
||||||
labelBgStyle={props.labelBgStyle}
|
|
||||||
labelBgPadding={props.labelBgPadding}
|
|
||||||
labelBgBorderRadius={props.labelBgBorderRadius}
|
|
||||||
/>
|
|
||||||
) : null;
|
|
||||||
|
|
||||||
const markerEnd = reactify((arrowHeadType?: ArrowHeadType, markerEndId?: string) => getMarkerEnd(arrowHeadType, markerEndId));
|
const markerEnd = reactify((arrowHeadType?: ArrowHeadType, markerEndId?: string) => getMarkerEnd(arrowHeadType, markerEndId));
|
||||||
|
|
||||||
return () => (
|
return () => (
|
||||||
@@ -42,7 +29,18 @@ export default defineComponent({
|
|||||||
d={`M ${props.sourceX},${props.sourceY}L ${props.targetX},${props.targetY}`}
|
d={`M ${props.sourceX},${props.sourceY}L ${props.targetX},${props.targetY}`}
|
||||||
marker-end={markerEnd(props.arrowHeadType, props.markerEndId).value}
|
marker-end={markerEnd(props.arrowHeadType, props.markerEndId).value}
|
||||||
/>
|
/>
|
||||||
{text}
|
{props.label ? (
|
||||||
|
<EdgeText
|
||||||
|
x={centerX(props.targetX, props.sourceX).value}
|
||||||
|
y={centerY(props.targetY, props.sourceY).value}
|
||||||
|
label={props.label}
|
||||||
|
labelStyle={props.labelStyle}
|
||||||
|
labelShowBg={props.labelShowBg}
|
||||||
|
labelBgStyle={props.labelBgStyle}
|
||||||
|
labelBgPadding={props.labelBgPadding}
|
||||||
|
labelBgBorderRadius={props.labelBgBorderRadius}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,9 +91,9 @@ export const DefaultEdgeProps = {
|
|||||||
default: Position.Top
|
default: Position.Top
|
||||||
},
|
},
|
||||||
label: {
|
label: {
|
||||||
type: String as PropType<EdgeProps['label']>,
|
type: [String, Object] as PropType<EdgeProps['label']>,
|
||||||
required: false,
|
required: false,
|
||||||
default: undefined
|
default: () => {}
|
||||||
},
|
},
|
||||||
labelStyle: {
|
labelStyle: {
|
||||||
type: Object as PropType<EdgeProps['labelStyle']>,
|
type: Object as PropType<EdgeProps['labelStyle']>,
|
||||||
@@ -106,7 +106,7 @@ export const DefaultEdgeProps = {
|
|||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
labelBgStyle: {
|
labelBgStyle: {
|
||||||
type: String as PropType<EdgeProps['labelBgStyle']>,
|
type: [String, Object] as PropType<EdgeProps['labelBgStyle']>,
|
||||||
required: false,
|
required: false,
|
||||||
default: undefined
|
default: undefined
|
||||||
},
|
},
|
||||||
@@ -121,7 +121,7 @@ export const DefaultEdgeProps = {
|
|||||||
default: undefined
|
default: undefined
|
||||||
},
|
},
|
||||||
arrowHeadType: {
|
arrowHeadType: {
|
||||||
type: Object as PropType<EdgeProps['arrowHeadType']>,
|
type: String as PropType<EdgeProps['arrowHeadType']>,
|
||||||
required: false,
|
required: false,
|
||||||
default: undefined
|
default: undefined
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user