Interface used by IGraph to declare and obtain the defaults for ports at nodes and edges.
Inheritance Hierarchy
IPortDefaults
Remarks
Note that changing these defaults does not change properties of already created model items. Rather, only items created after the change are affected.
Examples
// Ports on nodes and edges have different IPortDefault instances.
// These can be retrieved from their owner type's defaults
// the defaults for node ports can be set on the IPortDefaults instance
// found at the Ports property of the node defaults
graph.nodeDefaults.ports.autoCleanUp = false
graph.nodeDefaults.ports.locationParameter =
FreeNodePortLocationModel.CENTER
// the defaults for edge ports can be set on the IPortDefaults instance
// found at the Ports property of the edge defaults
graph.edgeDefaults.ports.autoCleanUp = false
graph.edgeDefaults.ports.locationParameter =
BendAnchoredPortLocationModel.FIRST_BEND
Type Details
- yFiles module
- view
See Also
Properties
Gets or sets whether unused ports should automatically be removed from their owners as soon as no further edge is connected to them.
Examples
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
See Also
Gets or sets the defaults for labels at ports.
Property Value
The label defaults.
Examples
graph.nodeDefaults.ports.labels.layoutParameter =
FreePortLabelModel.CENTER
Gets or sets the location model parameter to use for ports.
Remarks
Depending on the setting of shareLocationParameterInstance, the getLocationParameterInstance method should return a clone of this instance or the very same instance.
Property Value
The parameter to use as a template.
Examples
graph.nodeDefaults.ports.style = new ShapePortStyle({
shape: ShapeNodeShape.ELLIPSE,
})
graph.nodeDefaults.ports.locationParameter =
FreeNodePortLocationModel.CENTER
See Also
Gets or sets the style to use for ports.
Remarks
Depending on the setting of shareStyleInstance, the getStyleInstance method should return a clone of this instance or the very same instance.
Property Value
The style to use as a template.
Examples
graph.nodeDefaults.ports.style = new ShapePortStyle({
shape: ShapeNodeShape.ELLIPSE,
})
graph.nodeDefaults.ports.locationParameter =
FreeNodePortLocationModel.CENTER
See Also
Methods
Factory method that returns a location model parameter instance for use with newly created ports.
Remarks
Most implementations will yield either a clone or the locationParameter property if shareLocationParameterInstance is enabled, but they might use more complicated logic, too.
Parameters
options - Object
A map of options to pass to the method.
A map of options to pass to the method.
- owner - IPortOwner
- The owner of the port that will be created.
Returns
- ↪IPortLocationModelParameter
- The parameter to use, which for most implementations is either a clone or the locationParameter property if shareLocationParameterInstance is enabled.
Factory method that returns a style instance for use with newly created ports.
Remarks
Most implementations will yield either, a clone of or the style property, if shareStyleInstance is enabled, but they might use more complicated logic, too.
Parameters
options - Object
A map of options to pass to the method.
A map of options to pass to the method.
- owner - IPortOwner
- The owner of the port that will be created.
Returns
- ↪IPortStyle
- The style to use, which for most implementations is either a clone of or the style property, if shareStyleInstance is enabled.