Skip to Content
代码示例Edges

浮动边缘

这是浮动边缘的示例实现。边缘的源位置和目标位置正在动态计算。你可以在 utils.js 文件中找到实现细节。

¥This is an example implementation for floating edges. The source and target position of the edges are getting calculated dynamically. You can find the implementation details in the utils.js file.

import React, { useCallback } from 'react'; import { ReactFlow, addEdge, Background, useNodesState, useEdgesState, MarkerType, } from '@xyflow/react'; import '@xyflow/react/dist/style.css'; import FloatingEdge from './FloatingEdge'; import FloatingConnectionLine from './FloatingConnectionLine'; import { initialElements } from './initialElements'; const { nodes: initialNodes, edges: initialEdges } = initialElements(); const edgeTypes = { floating: FloatingEdge, }; const NodeAsHandleFlow = () => { const [nodes, , onNodesChange] = useNodesState(initialNodes); const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges); const onConnect = useCallback( (params) => setEdges((eds) => addEdge( { ...params, type: 'floating', markerEnd: { type: MarkerType.Arrow }, }, eds, ), ), [setEdges], ); return ( <div className="floating-edges"> <ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} onConnect={onConnect} fitView edgeTypes={edgeTypes} connectionLineComponent={FloatingConnectionLine} style={{ backgroundColor: "#F7F9FB" }} > <Background /> </ReactFlow> </div> ); }; export default NodeAsHandleFlow;