refactor(edges): Remove scaling from edge text
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { EdgeTextProps } from '../../types/components'
|
import type { EdgeTextProps } from '../../types/components'
|
||||||
import { useVueFlow } from '../../composables'
|
import { Rect } from '../../types'
|
||||||
|
|
||||||
const props = withDefaults(defineProps<EdgeTextProps>(), {
|
const props = withDefaults(defineProps<EdgeTextProps>(), {
|
||||||
labelStyle: () => ({}),
|
labelStyle: () => ({}),
|
||||||
@@ -10,12 +10,14 @@ const props = withDefaults(defineProps<EdgeTextProps>(), {
|
|||||||
labelBgBorderRadius: 2,
|
labelBgBorderRadius: 2,
|
||||||
})
|
})
|
||||||
|
|
||||||
const { transform: paneTransform } = useVueFlow()
|
|
||||||
const edgeRef = templateRef<SVGTextElement>('edge-text', null)
|
const edgeRef = templateRef<SVGTextElement>('edge-text', null)
|
||||||
const { width, height } = useElementBounding(edgeRef)
|
|
||||||
const transform = computed(
|
const edgeRefBbox = ref<Rect>({ x: 0, y: 0, width: 0, height: 0 })
|
||||||
() => `translate(${props.x - width.value / paneTransform.value[2] / 2} ${props.y - height.value / paneTransform.value[2] / 2})`,
|
|
||||||
)
|
onMounted(() => {
|
||||||
|
edgeRefBbox.value = edgeRef.value.getBBox()
|
||||||
|
})
|
||||||
|
const transform = computed(() => `translate(${props.x - edgeRefBbox.value.width / 2} ${props.y - edgeRefBbox.value.height / 2})`)
|
||||||
</script>
|
</script>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export default {
|
export default {
|
||||||
@@ -23,24 +25,24 @@ export default {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<g :transform="transform" class="vue-flow__edge-textwrapper">
|
<g :transform="transform" :class="props.class" class="vue-flow__edge-textwrapper">
|
||||||
<rect
|
<rect
|
||||||
v-if="props.labelShowBg"
|
v-if="props.labelShowBg"
|
||||||
class="vue-flow__edge-textbg"
|
class="vue-flow__edge-textbg"
|
||||||
:width="width / paneTransform[2] + 2 * props.labelBgPadding[0] + 'px'"
|
:width="edgeRefBbox.width + 2 * props.labelBgPadding[0] + 'px'"
|
||||||
:height="height / paneTransform[2] + 2 * props.labelBgPadding[1] + 'px'"
|
:height="edgeRefBbox.height + 2 * props.labelBgPadding[1] + 'px'"
|
||||||
:x="-props.labelBgPadding[0]"
|
:x="-props.labelBgPadding[0]"
|
||||||
:y="-props.labelBgPadding[1]"
|
:y="-props.labelBgPadding[1]"
|
||||||
:style="props.labelBgStyle"
|
:style="props.labelBgStyle"
|
||||||
:rx="props.labelBgBorderRadius"
|
:rx="props.labelBgBorderRadius"
|
||||||
:ry="props.labelBgBorderRadius"
|
:ry="props.labelBgBorderRadius"
|
||||||
/>
|
/>
|
||||||
<text ref="edge-text" class="vue-flow__edge-text" :y="height / paneTransform[2] / 2" dy="0.3em" :style="props.labelStyle">
|
<text ref="edge-text" class="vue-flow__edge-text" :y="edgeRefBbox.height / 2" dy="0.3em" :style="props.labelStyle">
|
||||||
<slot v-bind="props">
|
<slot v-bind="props">
|
||||||
<component
|
<component
|
||||||
:is="props.label?.component"
|
:is="props.label?.component"
|
||||||
v-if="typeof props.label !== 'string' && typeof props.label?.component !== 'undefined'"
|
v-if="typeof props.label !== 'string' && typeof props.label?.component !== 'undefined'"
|
||||||
v-bind="{ ...props, ...props.label?.props, width, height }"
|
v-bind="props.label?.props"
|
||||||
/>
|
/>
|
||||||
<template v-else v-html="props.label">
|
<template v-else v-html="props.label">
|
||||||
{{ props.label }}
|
{{ props.label }}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component, CSSProperties, DefineComponent } from 'vue'
|
import { Component, CSSProperties, DefineComponent, HTMLAttributes } from "vue";
|
||||||
import { BackgroundVariant, Dimensions, XYPosition } from './flow'
|
import { BackgroundVariant, Dimensions, XYPosition } from './flow'
|
||||||
import { GraphNode, Node, NodeProps } from './node'
|
import { GraphNode, Node, NodeProps } from './node'
|
||||||
import { EdgeProps } from './edge'
|
import { EdgeProps } from './edge'
|
||||||
@@ -89,7 +89,7 @@ export interface MiniMapNodeProps {
|
|||||||
strokeWidth?: number
|
strokeWidth?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EdgeTextProps {
|
export interface EdgeTextProps extends HTMLAttributes {
|
||||||
x: number
|
x: number
|
||||||
y: number
|
y: number
|
||||||
label?:
|
label?:
|
||||||
|
|||||||
Reference in New Issue
Block a user