documentationfor yFiles for HTML 2.6

Nodes

A node is a graph item which represents an entity. It is modeled by the interface INode. INode provides a number of properties which define the node’s characteristics. All properties (except tag) are read-only. You can set their values using the corresponding methods on IGraph.

Property Setter Description
INode.layoutIGraph.setNodeLayoutThe node’s layout, i.e. its location and size. See the section about node layout.
INode.styleIGraph.setStyleThe visual appearance of the node. See section Visualization of Graph Elements: Styles.
INode.labelsIGraph.addLabelThe collection of labels which are associated with this node.
INode.portsIGraph.addPortThe collection of ports which are associated with this node.
INode.tagINode.tagAn object of arbitrary type which can be used to bind user data to this node. See Storing Business Data for Graph Elements. Note that this is the only property which provides both getter and setter.
Node properties
Layout
Style
Labels
Ports

A node cannot be simply created with a constructor. Instead, you can create nodes as well as remove them from the graph using IGraph’s methods:

createNode(layout: Rect, style: INodeStyle, tag: Object): INode
createNodeAt(location: Point, style: INodeStyle, tag: Object): INode
createNode(parent: INode, layout: Rect, style: INodeStyle, tag: Object): INode
Creates a node. The various overloads allow setting the new node’s properties at creation time. Values which are not passed as parameters will be set to the default values as defined in the node defaults.
remove(item: IModelItem): void
Removes the given node from the graph. Before the node is removed all dependent items (the node’s labels and ports, also adjacent edges) are removed.

You can only modify or remove nodes which are part of the current graph instance. Trying to modify or remove a node which already has been removed will result in an exception. Also, if your use case involves several IGraph instances (especially if you are using filtering or folding) take care to modify and remove nodes only with the graph the node belongs to.