documentationfor yFiles for HTML 3.0.0.3

NodeDecorator

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

Inheritance Hierarchy
NodeDecorator

Remarks

Predefined LookupDecorator<TDecoratedType,TInterface> are made available through properties like e.g. highlightRenderer. 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 nodes on the GraphDecorator which is returned by decorator on an IGraph.

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

Examples

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

graph.decorator.nodes.sizeConstraintProvider.addConstant(
  new ConstantSizeConstraintProvider(),
)

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

graph.decorator.nodes.sizeConstraintProvider.addConstant(
  (node) => node.tag !== null,
  new ConstantSizeConstraintProvider(),
)

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

graph.decorator.nodes.sizeConstraintProvider.addFactory(
  (node) => new CustomSizeConstraintProvider(node),
)
graph.decorator.nodes.sizeConstraintProvider.addFactory(
  (node) => node.tag !== null,
  (node) => new CustomSizeConstraintProvider(node),
)

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

graph.decorator.nodes.sizeConstraintProvider.addWrapperFactory(
  (node, originalProvider) =>
    new SizeConstraintProviderWrapper(node, originalProvider),
)
graph.decorator.nodes.sizeConstraintProvider.addWrapperFactory(
  (node) => node.tag !== null,
  (node, originalProvider) =>
    new SizeConstraintProviderWrapper(node, originalProvider),
)

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

graph.decorator.nodes.sizeConstraintProvider.hide()
graph.decorator.nodes.sizeConstraintProvider.hide(
  (node) => node.tag !== null,
)

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

registerLookup(graph: IGraph): void {
  this.chainLink =
    graph.decorator.nodes.sizeConstraintProvider.addFactory(
      (node) => new CustomSizeConstraintProvider(node),
    )!
}

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

Type Details

yFiles module
view

See Also

Constructors

Properties

Methods