!!!###!!!title=Edge Editor——VisActor/VGraph tutorial documents!!!###!!!!!!###!!!description=EdgeEditor is an edge editing component in vGraph suitable for graph editing scenarios, used for operations such as dragging and adding new edges from anchor points, and modifying edge endpoints. After configuring the [Stack](docs/) and [Router](docs/) components, the EdgeEditor component will complete the relevant logic of the operation stack during the process of dragging edge anchor points to support undo and redo, as well as automatically updating the intelligent routing paths of related edges.The following is an example of how to use the EdgeEditor component. You can also experience it in the demo.```javascriptimport { Graph, EdgeEditor } from "@visactor/vgraph";const edgeEditor = new EdgeEditor(graph, { stack, router, ...})```!!!###!!!

EdgeEditor

EdgeEditor is an edge editing component in vGraph suitable for graph editing scenarios, used for operations such as dragging and adding new edges from anchor points, and modifying edge endpoints. After configuring the Stack and Router components, the EdgeEditor component will complete the relevant logic of the operation stack during the process of dragging edge anchor points to support undo and redo, as well as automatically updating the intelligent routing paths of related edges.

The following is an example of how to use the EdgeEditor component. You can also experience it in the demo.

import { Graph, EdgeEditor } from "@visactor/vgraph";
const edgeEditor = new EdgeEditor(graph, {
	stack,
	router,
	...
})

Configuration Items

EdgeEditorOptions is defined as follows.

FieldTypeDescription
stackStackOperation stack instance. Used by the component to complete the relevant logic of the operation stack during the process of dragging anchor point edges to support undo and redo. If not passed in, data changes caused by node dragging will not enter the operation stack.
routerRouterIntelligent routing component instance. Used by the component to automatically update the intelligent routing path during the process of dragging anchor point edges.
autoTranslatebooleanEnabled by default. When enabled, dragging to the view boundary will automatically pan the canvas to expand the view boundary.
tempEdgeStylesRecord<string, any>The style of the temporary edge during the drag process. The default is a blue dashed line, i.e., { strokeStyle: '#3073F2', lineDash: [4, 4] }.
editTerminalbooleanWhether the endpoints of the edge can be edited. The default is true. When enabled, users can select an edge and drag its two endpoints to edit the edge.
dragEdgeToEditbooleanWhether to allow dragging the edge directly to edit the node. This needs to be used in conjunction with editTerminal.
editAnchorStylesRecord<string, any>The style of the anchor points at both ends of the edge when it is in the edge editing state. You can refer to the Circle style.
magnetbooleanWhether to automatically snap to anchor points.
magnetDistnumberThe effective distance for automatically snapping to anchor points. The default is 28px.
magnetAnchorStylesRecord<string, any>The style of the snapped anchor point. You can refer to the Circle style.
shouldTrigger(e: GraphEvent, shape: Shape, target: Node, edge?: Edge) =>booleanA function to determine whether it can be triggered.
shouldMagnet(source: Node, target: Node, anchor: AnchorConfigs) =>booleanA function to determine whether it can be snapped.
shouldDrop(source: Node, target: Node, sourceAnchor: number, targetAnchor: number, edit: boolean) =>booleanA function to determine whether it can be dropped.
onDragStart(node: Node, e: GraphEvent) =>voidA function triggered when the drag starts.
onDragEnter(node: Node, e: GraphEvent) =>voidA function triggered when passing through a node during the drag process.
onDragLeave(node: Node, e: GraphEvent) =>voidA function triggered when leaving a node during the drag process.
onDrag() =>voidA function triggered when the mouse is moved during the drag process.
onDrop(source: Node, target: Node) =>voidA function triggered after a successful drop.
showAnchors(anchorConfigs: AnchorConfigs, anchorShape?: Layer, node: Node) =>booleanWhich anchor points should be displayed during the drag process (generally means connectable). For example, if the business only allows connecting from the output anchor point of a node to the input anchor point of another node, you can use this method to hide all output anchor points.

Instance Methods

Instance MethodReturn ValueDescription
enable()voidEnable the component.
disable()voidDisable the component.
destroy()voidDestroy the component.