chore(core,edges): simplify edge components

This commit is contained in:
braks
2022-11-13 23:25:04 +01:00
committed by Braks
parent 354c721fd3
commit c93ffafd31
12 changed files with 34 additions and 127 deletions
@@ -104,6 +104,7 @@ export default {
markerStart: `url(#${getMarkerId(connectionLineOptions.markerStart)})`, markerStart: `url(#${getMarkerId(connectionLineOptions.markerStart)})`,
}" }"
/> />
<path <path
v-else v-else
:d="dAttr" :d="dAttr"
@@ -67,6 +67,7 @@ BaseEdge.props = [
'style', 'style',
'interactionWidth', 'interactionWidth',
] ]
BaseEdge.inheritAttrs = false BaseEdge.inheritAttrs = false
export default BaseEdge export default BaseEdge
@@ -6,46 +6,19 @@ import type { EdgeProps } from '~/types'
const BezierEdge: FunctionalComponent<EdgeProps> = function ({ const BezierEdge: FunctionalComponent<EdgeProps> = function ({
sourcePosition = Position.Bottom, sourcePosition = Position.Bottom,
targetPosition = Position.Top, targetPosition = Position.Top,
label, ...props
labelStyle = {},
labelShowBg = true,
labelBgStyle = {},
labelBgPadding,
labelBgBorderRadius,
sourceY,
sourceX,
targetX,
targetY,
curvature,
markerEnd,
markerStart,
style,
interactionWidth,
}) { }) {
const [path, labelX, labelY] = getBezierPath({ const [path, labelX, labelY] = getBezierPath({
sourceX,
sourceY,
targetX,
targetY,
sourcePosition, sourcePosition,
targetPosition, targetPosition,
curvature, ...props,
}) })
return h(BaseEdge, { return h(BaseEdge, {
path, path,
labelX, labelX,
labelY, labelY,
label, ...props,
labelStyle,
labelShowBg,
labelBgStyle,
labelBgPadding,
labelBgBorderRadius,
style,
markerEnd,
markerStart,
interactionWidth,
}) })
} }
@@ -67,7 +40,9 @@ BezierEdge.props = [
'markerStart', 'markerStart',
'style', 'style',
'interactionWidth', 'interactionWidth',
'ref',
] ]
BezierEdge.inheritAttrs = false BezierEdge.inheritAttrs = false
export default BezierEdge export default BezierEdge
@@ -21,21 +21,24 @@ const shiftY = (y: number, shift: number, position: Position): number => {
} }
const EdgeAnchor: FunctionalComponent<Props> = function ({ radius = 10, centerX = 0, centerY = 0, position = Position.Top }) { const EdgeAnchor: FunctionalComponent<Props> = function ({ radius = 10, centerX = 0, centerY = 0, position = Position.Top }) {
const cx = computed(() => { const cx = () => {
const val = shiftX(centerX, radius, position) const val = shiftX(centerX, radius, position)
if (isNaN(val)) return 0 if (isNaN(val)) return 0
else return val else return val
}) }
const cy = computed(() => {
const cy = () => {
const val = shiftY(centerY, radius, position) const val = shiftY(centerY, radius, position)
if (isNaN(val)) return 0 if (isNaN(val)) return 0
else return val else return val
}) }
return h('circle', { return h('circle', {
class: 'vue-flow__edgeupdater', class: 'vue-flow__edgeupdater',
cx: cx.value, cx: cx(),
cy: cy.value, cy: cy(),
r: radius, r: radius,
stroke: 'transparent', stroke: 'transparent',
fill: 'transparent', fill: 'transparent',
@@ -54,6 +54,7 @@ export default {
:rx="labelBgBorderRadius" :rx="labelBgBorderRadius"
:ry="labelBgBorderRadius" :ry="labelBgBorderRadius"
/> />
<text v-bind="$attrs" ref="el" class="vue-flow__edge-text" :y="box.height / 2" dy="0.3em" :style="labelStyle"> <text v-bind="$attrs" ref="el" class="vue-flow__edge-text" :y="box.height / 2" dy="0.3em" :style="labelStyle">
<slot> <slot>
<component :is="label" v-if="!isString(label)" /> <component :is="label" v-if="!isString(label)" />
@@ -13,7 +13,7 @@ interface Props {
targetNode: GraphNode targetNode: GraphNode
} }
const Wrapper = defineComponent({ const EdgeWrapper = defineComponent({
props: ['name', 'type', 'id', 'updatable', 'selectable', 'edge', 'sourceNode', 'targetNode'], props: ['name', 'type', 'id', 'updatable', 'selectable', 'edge', 'sourceNode', 'targetNode'],
setup(props: Props) { setup(props: Props) {
const { addSelectedEdges, connectionMode, edgeUpdaterRadius, emits, nodesSelectionActive, getEdges, getEdgeTypes } = const { addSelectedEdges, connectionMode, edgeUpdaterRadius, emits, nodesSelectionActive, getEdges, getEdgeTypes } =
@@ -239,4 +239,4 @@ const Wrapper = defineComponent({
}, },
}) })
export default Wrapper export default EdgeWrapper
@@ -6,44 +6,19 @@ import type { EdgeProps } from '~/types'
const SimpleBezierEdge: FunctionalComponent<EdgeProps> = function ({ const SimpleBezierEdge: FunctionalComponent<EdgeProps> = function ({
sourcePosition = Position.Bottom, sourcePosition = Position.Bottom,
targetPosition = Position.Top, targetPosition = Position.Top,
label, ...props
labelStyle = {},
labelShowBg = true,
labelBgStyle = {},
labelBgPadding,
labelBgBorderRadius,
sourceY,
sourceX,
targetX,
targetY,
markerEnd,
markerStart,
style,
interactionWidth,
}) { }) {
const [path, labelX, labelY] = getSimpleBezierPath({ const [path, labelX, labelY] = getSimpleBezierPath({
sourceX,
sourceY,
targetX,
targetY,
sourcePosition, sourcePosition,
targetPosition, targetPosition,
...props,
}) })
return h(BaseEdge, { return h(BaseEdge, {
path, path,
labelX, labelX,
labelY, labelY,
label, ...props,
labelStyle,
labelShowBg,
labelBgStyle,
labelBgPadding,
labelBgBorderRadius,
style,
markerEnd,
markerStart,
interactionWidth,
}) })
} }
@@ -65,6 +40,7 @@ SimpleBezierEdge.props = [
'style', 'style',
'interactionWidth', 'interactionWidth',
] ]
SimpleBezierEdge.inheritAttrs = false SimpleBezierEdge.inheritAttrs = false
export default SimpleBezierEdge export default SimpleBezierEdge
@@ -6,48 +6,19 @@ import { Position } from '~/types'
const SmoothStepEdge: FunctionalComponent<SmoothStepEdgeProps> = function ({ const SmoothStepEdge: FunctionalComponent<SmoothStepEdgeProps> = function ({
sourcePosition = Position.Bottom, sourcePosition = Position.Bottom,
targetPosition = Position.Top, targetPosition = Position.Top,
label, ...props
labelStyle = {},
labelShowBg = true,
labelBgStyle = {},
labelBgPadding,
labelBgBorderRadius,
sourceY,
sourceX,
targetX,
targetY,
markerEnd,
markerStart,
borderRadius,
offset,
style,
interactionWidth,
}) { }) {
const [path, labelX, labelY] = getSmoothStepPath({ const [path, labelX, labelY] = getSmoothStepPath({
sourceX,
sourceY,
targetX,
targetY,
sourcePosition, sourcePosition,
targetPosition, targetPosition,
borderRadius, ...props,
offset,
}) })
return h(BaseEdge, { return h(BaseEdge, {
path, path,
labelX, labelX,
labelY, labelY,
label, ...props,
labelStyle,
labelShowBg,
labelBgStyle,
labelBgPadding,
labelBgBorderRadius,
style,
markerEnd,
markerStart,
interactionWidth,
}) })
} }
@@ -71,6 +42,7 @@ SmoothStepEdge.props = [
'style', 'style',
'interactionWidth', 'interactionWidth',
] ]
SmoothStepEdge.inheritAttrs = false SmoothStepEdge.inheritAttrs = false
export default SmoothStepEdge export default SmoothStepEdge
@@ -24,6 +24,7 @@ StepEdge.props = [
'style', 'style',
'interactionWidth', 'interactionWidth',
] ]
StepEdge.inheritAttrs = false StepEdge.inheritAttrs = false
export default StepEdge export default StepEdge
@@ -2,38 +2,14 @@ import type { FunctionalComponent } from 'vue'
import BaseEdge from './BaseEdge' import BaseEdge from './BaseEdge'
import type { EdgeProps } from '~/types' import type { EdgeProps } from '~/types'
const StraightEdge: FunctionalComponent<EdgeProps> = function ({ const StraightEdge: FunctionalComponent<EdgeProps> = function (props) {
label, const [path, labelX, labelY] = getStraightPath(props)
labelStyle = {},
labelShowBg = true,
labelBgStyle = {},
labelBgPadding,
labelBgBorderRadius,
sourceY,
sourceX,
targetX,
targetY,
markerEnd,
markerStart,
style,
interactionWidth,
}) {
const [path, labelX, labelY] = getStraightPath({ sourceX, sourceY, targetX, targetY })
return h(BaseEdge, { return h(BaseEdge, {
path, path,
labelX, labelX,
labelY, labelY,
label, ...props,
labelStyle,
labelShowBg,
labelBgStyle,
labelBgPadding,
labelBgBorderRadius,
style,
markerEnd,
markerStart,
interactionWidth,
}) })
} }
@@ -53,6 +29,7 @@ StraightEdge.props = [
'style', 'style',
'interactionWidth', 'interactionWidth',
] ]
StraightEdge.inheritAttrs = false StraightEdge.inheritAttrs = false
export default StraightEdge export default StraightEdge
+1 -1
View File
@@ -6,5 +6,5 @@ export { default as SmoothStepEdge } from './SmoothStepEdge'
export { default as StraightEdge } from './StraightEdge' export { default as StraightEdge } from './StraightEdge'
export { default as EdgeAnchor } from './EdgeAnchor' export { default as EdgeAnchor } from './EdgeAnchor'
export { default as EdgeText } from './EdgeText.vue' export { default as EdgeText } from './EdgeText.vue'
export { default as EdgeWrapper } from './Wrapper' export { default as EdgeWrapper } from './EdgeWrapper'
export { default as EdgeLabelRenderer } from './EdgeLabelRenderer.vue' export { default as EdgeLabelRenderer } from './EdgeLabelRenderer.vue'
@@ -1,6 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { EffectScope } from 'vue' import type { EffectScope } from 'vue'
import EdgeWrapper from '../../components/Edges/Wrapper' import EdgeWrapper from '../../components/Edges/EdgeWrapper'
import ConnectionLine from '../../components/ConnectionLine/ConnectionLine.vue' import ConnectionLine from '../../components/ConnectionLine/ConnectionLine.vue'
import type { EdgeComponent, EdgeUpdatable, GraphEdge } from '../../types' import type { EdgeComponent, EdgeUpdatable, GraphEdge } from '../../types'
import MarkerDefinitions from './MarkerDefinitions.vue' import MarkerDefinitions from './MarkerDefinitions.vue'