!!!###!!!title=API——VisActor/VGraph tutorial documents!!!###!!!!!!###!!!description=If you want to call node instance methods in **batch**, it is recommended to first set the graph's `autoDraw` to `false`. After the batch operation is complete, manually call `graph.draw()`. Then reset `autoDraw` to `true`. This can improve runtime performance.!!!###!!!

Node Instance Methods

If you want to call node instance methods in batch, it is recommended to first set the graph's autoDraw to false. After the batch operation is complete, manually call graph.draw(). Then reset autoDraw to true. This can improve runtime performance.

State Management

Instance MethodReturn ValueDescription
setState(state: string, onlyState=false)voidSets the node state. This is a convenient method for when the node structure remains unchanged but its appearance changes. By default, states will be stacked. If you want only one state to exist at a time, you can set onlyState = true. For details on usage, see the State Management section.
clearStates()voidClears all node states.
removeState(state: string)voidRemoves a state.
get(key: string)anyGets the original data or properties of the node.
show(showEdgee=true)voidShows the node and its related edges. If false is passed, only the node is shown.
hide()voidHides the node and its related edges.
isVisible()booleanQueries the visibility state of the node.
toFront()booleanMoves the node to the front of all nodes.
toBack()booleanMoves the node to the back of all nodes.

Relationship Query

Instance MethodReturn ValueDescription
get(key: string)anyGets a configuration item on the node.
set(key: string, value: any)voidUpdates a business data item on the node. This is an operation that does not involve graphic changes. If you need the update to be reflected in the graph, please use updateData.
updateData(data: NodeData)voidUpdates the node data. It supports incremental data updates and will merge with the old data. This will cause the connection graphics to be updated.
getEdges()Edge[]Gets all edges related to the node.
getLinkedNodes()Node[]Gets all nodes connected to this node.
getDirectParent()Group | nullGets the direct parent group.
getRootParent()Group |nullGets the root group. In the case of nested groups, this will return a different group from getDirectParent.

Graphics Operations

Instance MethodReturn ValueDescription
getBBox()BBoxGets the node's position box model. If the node has transformations such as scaling, the box model range will be affected.
getKeyShape()ShapeGets the key shape of the node.
getLayer()voidGets the node's drawing container, from which you can further get all internal graphics.
getLabel()Text |undefinedGets the text label graphic.
translate(x: number, y: number)voidTranslates the node.
scale(ratio: number)voidScales the node.
setOpacity()voidSets the opacity of the entire node.

Event Operations

Instance MethodReturn ValueDescription
on(eventType: string, callback(e: GraphEvent) => void)voidAdds a handler for a specific event on the node. For more information about events, see the Event Guide.
once(eventType: string, callback(e: GraphEvent) => void)voidAdds a one-time event handler on the node.
emit(eventType: string, args: any)voidTriggers a specified event on the node.
off(eventType: string, callback(e: GraphEvent) => void)voidRemoves a handler for a specific event on the node.
removeAllListeners()voidRemoves all event handlers on the node.