PortStyleBase<TVisual extends Visual>
An abstract base class that makes it possible to easily implement a custom IPortStyle.
Remarks
Only createVisual and getBounds need to be implemented by subclasses, however to improve rendering performance it is highly recommended to implement at least updateVisual, too.
This implementation differs from the straightforward IPortStyle implementation in that there is no visible separation between the style and its IPortStyleRenderer. Instead the renderer used by the base class is fixed and delegates all calls back to the style instance.
Note that if your subclass has private fields (defined with JavaScript's # name syntax), the clone method needs to be overridden for the cloning to work properly.
Related Programming Samples
- Custom Styles
- Shows how to create custom styles for nodes, edges, labels, ports, and edge arrows.
- 01 Rendering the Port
- Visualize a port as a basic circle shape
Type Parameters
- TVisual: Visual
- The optional type of the
created and updated by the and methods. This type argument can be omitted, but specifying a more concrete type helps conveniently implementing with TypeScript.
Type Details
- yFiles module
- view
Constructors
Initializes a new instance of the PortStyleBase<TVisual> class.
Properties
Gets the renderer implementation for this instance.
Remarks
Implements
Methods
Creates a new object that is a copy of the current instance.
Remarks
Immutable subclasses should consider returning this for the best performance.
The base class implementation creates a simple shallow clone that copies all own properties to a new instance. This will not work for classes that use private fields or properties (defined with JavaScript's # name syntax) as no constructors will be run and implementations like this cannot be accessed from outside the classes that declare them.
Classes that use private members or require special initialization must override this method and manually create a new instance or call super.clone() and then explicitly copy the private fields and properties explicitly.
Returns
- ↪Object
- A new object that is a copy of this instance using a memberwise clone.
Implements
Creates the visual.
Remarks
Parameters
A map of options to pass to the method.
- context - IRenderContext
- The render context.
- port - IPort
- The port to which this style instance is assigned.
Returns
- ↪TVisual?
- The visual as required by the createVisual interface.
See Also
Returns the bounds of the visual for the port in the given context.
Parameters
A map of options to pass to the method.
- context - ICanvasContext
- The canvas context.
- port - IPort
- The port to which this style instance is assigned.
Returns
- ↪Rect
- The visual bounds of the visual representation.
Determines whether the visual representation of the port has been hit at the given location.
Remarks
This method is called in response to a isHit call to the instance that has been queried from the renderer.
This implementation uses the bounds to determine whether the port has been hit.
Parameters
A map of options to pass to the method.
- context - IInputModeContext
- The input mode context.
- location - Point
- The point to test.
- port - IPort
- The port to which this style instance is assigned.
Returns
- ↪boolean
trueif the specified port representation is hit;falseotherwise.
Determines whether the visualization for the specified port is included in the marquee selection.
Remarks
This method is called in response to a isInBox call to the instance that has been queried from the renderer.
This implementation simply tests whether the bounds intersect the marquee box.
Parameters
A map of options to pass to the method.
- context - IInputModeContext
- The input mode context.
- rectangle - Rect
- The marquee selection box.
- port - IPort
- The port to which this style instance is assigned.
Returns
- ↪boolean
trueif the specified port is visible and selected by the marquee rectangle;falseotherwise.
Determines whether the visualization for the specified port is included in the lasso selection.
Remarks
This method is called in response to a isInPath call to the instance that has been queried from the renderer.
This implementation simply tests whether the bounds intersect the lasso path.
Parameters
A map of options to pass to the method.
- context - IInputModeContext
- The input mode context.
- path - GeneralPath
- The lasso selection path.
- port - IPort
- The port to which this style instance is assigned.
Returns
- ↪boolean
trueif the specified port is visible and selected by the lasso path;falseotherwise.
Determines whether the visualization for the specified port is visible in the context.
Remarks
Parameters
A map of options to pass to the method.
- context - ICanvasContext
- The canvas context.
- rectangle - Rect
- The clipping rectangle.
- port - IPort
- The port to which this style instance is assigned.
Returns
- ↪boolean
trueif the specified port is visible in the clipping rectangle;falseotherwise.
Performs the lookup operation for the getContext that has been queried from the renderer.
Remarks
This implementation yields null for everything but:
For these interfaces an implementation will be returned that delegates to the methods in this instance.
Parameters
A map of options to pass to the method.
- port - IPort
- The port to use for the context lookup.
- type - Constructor
- The type to query.
Returns
- ↪any?
- An implementation of the
typeornull.
Updates the visual previously created by createVisual.
Remarks
Parameters
A map of options to pass to the method.
- context - IRenderContext
- The render context.
- oldVisual - TVisual
- The visual that has been created in the call to createVisual.
- port - IPort
- The port to which this style instance is assigned.
Returns
- ↪TVisual?
- The visual as required by the createVisual interface.