documentationfor yFiles for HTML 2.6

PortDecorator

Helps in decorating the lookup method of IPort instances by providing access to decorators for the most common types.

Inheritance Hierarchy
PortDecorator

Remarks

Predefined LookupDecorator<TDecoratedType,TInterface> are made available through properties like e.g. highlightDecorator. Note that the list of possible decorations that are available using this class is not exhaustive in any way. This is merely a way to provide access to those interfaces that are more commonly being decorated by the developer.

Typically, a configured instance of this class is available through portDecorator on the GraphDecorator which is returned by decorator on an IGraph.

This decorator can be used to conveniently decorate the lookup of IPorts in an IGraph. It serves as a factory for predefined LookupDecorator<TDecoratedType,TInterface> instances that are specifically useful for the IPort type.

Examples

The port can be decorated in various ways. setImplementation decorates the port's lookup to return the same instance for each port.

graph.decorator.portDecorator.handleProviderDecorator.setImplementation(
  new ConstantHandleProvider()
)

setImplementation with a predicate decorates the port's lookup only to return the same instance for each port for which the predicate returns true.

graph.decorator.portDecorator.handleProviderDecorator.setImplementation(
  (port) => port.tag !== null,
  new ConstantHandleProvider()
)

setFactory calls the provided factory method to return a new instance of the queried type created for the given port or for ports for which the predicate returns true, respectively:

graph.decorator.portDecorator.handleProviderDecorator.setFactory(
  (port) => new CustomHandleProvider(port)
)
graph.decorator.portDecorator.handleProviderDecorator.setFactory(
  (port) => port.tag !== null,
  (port) => new CustomHandleProvider(port)
)

setImplementationWrapper calls the provided factory method to return a new instance of the queried type which wraps the default implementation, once for all ports and once only for ports for which the predicate returns true.

graph.decorator.portDecorator.handleProviderDecorator.setImplementationWrapper(
  (port, original) => new HandleProviderWrapper(port, original)
)
graph.decorator.portDecorator.handleProviderDecorator.setImplementationWrapper(
  (port) => port.tag !== null,
  (port, original) => new HandleProviderWrapper(port, original)
)graph.decorator.portDecorator.handleProviderDecorator.setImplementationWrapper(
  (port, original) => new HandleProviderWrapper(port!, original)
)
graph.decorator.portDecorator.handleProviderDecorator.setImplementationWrapper(
  (port) => port.tag !== null,
  (port, original) => new HandleProviderWrapper(port!, original)
)

Finally hideImplementation hides the default implementation by letting the lookup always return null for all ports and for ports for which the predicate returns true, respectively

graph.decorator.portDecorator.handleProviderDecorator.hideImplementation()
graph.decorator.portDecorator.handleProviderDecorator.hideImplementation(
  (port) => port.tag !== null
)

Each of these methods returns a IContextLookupChainLink which can be used to remove the modified behavior again:

/**
 * @param {!IGraph} graph
 */
registerLookup(graph) {
  this.chainLink =
    graph.decorator.portDecorator.handleProviderDecorator.setFactory(
      (port) => new CustomHandleProvider(port)
    )
}

/**
 * @param {!IGraph} graph
 */
deregisterLookup(graph) {
  graph.decorator.portDecorator.remove(this.chainLink)
}registerLookup(graph: IGraph): void {
  this.chainLink =
    graph.decorator.portDecorator.handleProviderDecorator.setFactory(
      (port) => new CustomHandleProvider(port)
    )!
}

deregisterLookup(graph: IGraph): void {
  graph.decorator.portDecorator.remove(this.chainLink)
}

Type Details

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

See Also

Constructors

Properties

Methods