documentationfor yFiles for HTML 2.6

The interface used in an IGraph implementation for IEdges to connect to.

Inheritance Hierarchy
Implemented Interfaces

Remarks

This interface provides read-only access to the properties of a port. In order to modify the state of an instance use the various methods provided by the IGraph this instance belongs to. Ports are owned by IPortOwners, normally an INode, but this can also be an IEdge in special graph implementations. To obtain the IEdge instances that are connected to a certain port instance, applications need to use the edgesAt method provided by IGraph. Zero or more edges may be connected to a port, depending on the implementation of the graph. A port is also an ILabelOwner, hence it may own labels. Like all items in an IGraph, this item supports the lookup method that can be used to query additional aspects of the item.

Examples

Working with a port in the graph
const graph = graphComponent.graph
const node = graph.createNodeAt(new Point(0, 0))

// add a port to the node: at the center with default style (invisible)
const port = graph.addPort(
  node,
  FreeNodePortLocationModel.NODE_CENTER_ANCHORED
)

// the newly created port is part of the graph
console.log(graph.contains(port)) // true
console.log(graph.ports.size) // 1

// the port belongs to its owner
console.log(port.owner === node) // true
console.log(node.ports.size) // 1
console.log(node.ports.get(0) === port) // true

// removing the port removes it from the graph
graph.remove(port)
console.log(graph.contains(port)) // false
console.log(graph.ports.size) // 0
// and from its owner
console.log(port.owner === null) // true
console.log(node.ports.size) // 0
Ports cannot live without an owner in the graph
console.log(graph.contains(port)) // true
graph.remove(port.owner)
console.log(graph.contains(port)) // falseconsole.log(graph.contains(port)) // true
graph.remove(port.owner!)
console.log(graph.contains(port)) // false
Unused ports may be removed automatically
const node1 = graph.createNode()
const node2 = graph.createNode()
const port1_1 = graph.addPort(node1)
const port1_2 = graph.addPort(node1)
const port2 = graph.addPort(node2)
const edge1 = graph.createEdge(port1_1, port2)
const edge2 = graph.createEdge(port1_2, port2)

// enable auto cleanup
graph.nodeDefaults.ports.autoCleanUp = true
graph.remove(edge1)
// port1_1 is removed with the edge
console.log(graph.contains(port1_1)) // false
// port2 is not removed since edge2 still is linked to it
console.log(graph.contains(port2))
// disable auto cleanup
graph.nodeDefaults.ports.autoCleanUp = false
graph.remove(edge2)
// no port is removed with the edge now
console.log(graph.contains(port1_2)) // true
console.log(graph.contains(port2)) // true

Related Reading in the Developer's Guide

The graph model with all relevant types and their relationships is presented in detail in the section The Graph Model.

Using the look-up mechanism is explained in the section Service Locator Pattern: Lookup.

Type Details

yfiles module
view-component
yfiles-umd modules
All view modules
Legacy UMD name
yfiles.graph.IPort

See Also

Properties

Methods