The interface used in an IGraph implementation for IEdges to connect to.
Remarks
IGraph
, this item supports the lookup method that can be used to query additional aspects of the item.Examples
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.CENTER)
// 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(node.ports.size) // 0
console.log(port.owner === null) // throws Error!!
console.log(graph.contains(port)) // true
graph.remove(port.owner)
console.log(graph.contains(port)) // false
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
Properties
Gets a live view of the location of the port in world coordinates.
Remarks
See Also
Gets a collection of labels that are owned by this instance.
Remarks
This gives access to a read-only live view of the labels, i.e. the collection can change over time, as well as the labels contained in it. If a snapshot of the current state is needed, one needs to copy the collection and its contents.
To modify the label collection for instances of the default implementations that were created via the factory methods on IGraph, use addLabel and remove.
Examples
// add label with given text, default style, and default placement
// and determine the preferred size automatically
const label1 = graph.addLabel(node, 'Some Label')
// add label with given text, placement, style, size, and tag (user object)
const label2 = graph.addLabel(
node,
'Some Label',
InteriorNodeLabelModel.CENTER,
new LabelStyle(),
new Size(10, 150),
userObject,
)
// add label with given text and style but default placement
// and determine the preferred size automatically
const label3 = graph.addLabel({
owner: node,
text: 'Some Label',
style: new LabelStyle(),
})
for (const label of node.labels) {
// ...
}
graph.remove(label)
See Also
Defined in
Gets a snapshot of the current location of the port.
Remarks
See Also
Gets the IPortLocationModelParameter that is used to determine the location of this port.
Remarks
The port location can be calculated using the model's getLocation method or the methods location and dynamicLocation.
To change the port location parameter for instances of the default implementation that were created via the factory methods on IGraph, use setPortLocationParameter
Note that parameters may be shared across port instances.
Examples
graph.setPortLocationParameter(port, FreeNodePortLocationModel.CENTER)
const parameter = port.locationParameter
graph.setPortLocation(port, new Point(x, y))
const location = port.location
See Also
Gets the owner of this port.
Remarks
In traditional IGraph implementations, this will be an INode and can safely be cast to one. In order to get to the IEdges that connect to this instance, use IGraph's edgesAt method.
Note that for instances of the default implementation that were created via the factory methods on IGraph, the owner can't be changed after creation and the port has to be deleted and recreated with a new owner.
Throws
- Exception({ name: 'InvalidOperationError' })
- if the port has no owner.
Examples
// add a port to the owner
const port = graph.addPort(owner)
// the port's Owner property is set to the owner
console.log(port.owner === owner) // true
// the port is in its owner's Ports collection
console.log(owner.ports.includes(port)) // true
See Also
Gets the style that is responsible for the visual representation of this port in a CanvasComponent.
Remarks
Note that the style instance associated with a port instance may be shared between multiple port instances and that the modification of this style will result in a change of the appearance of all ports that are associated with the same style instance.
To change the style for instances of the default implementation that were created via the factory methods on IGraph, use setStyle
Examples
graph.setStyle(port, portStyle)
const style = port.style
See Also
Gets or sets the tag object associated with this item instance.
Remarks
Property Value
Examples
owner.tag = newTag
const tag = owner.tag
Implements
Methods
Returns an instance that implements the given type or null
.
Remarks
null
implementations for the types, nor does it have to return the same instance any time. Also, it depends on the type and context whether the instance returned stays up to date or needs to be re-obtained for further use.Type Parameters
- T
Parameters
A map of options to pass to the method.
- type - Constructor<T>
- the type for which an instance shall be returned
Returns
- ↪T?
- an instance that is assignable to the type or
null