documentationfor yFiles for HTML 2.6

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. 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 nodeDecorator 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. setImplementation decorates the node's lookup to return the same instance for each node.

graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementation(
  new ConstantSizeConstraintProvider()
)

setImplementation 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.nodeDecorator.sizeConstraintProviderDecorator.setImplementation(
  (node) => node.tag !== null,
  new ConstantSizeConstraintProvider()
)

setFactory 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.nodeDecorator.sizeConstraintProviderDecorator.setFactory(
  (node) => new CustomSizeConstraintProvider(node)
)
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setFactory(
  (node) => node.tag !== null,
  (node) => new CustomSizeConstraintProvider(node)
)

setImplementationWrapper 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.nodeDecorator.sizeConstraintProviderDecorator.setImplementationWrapper(
  (node, originalProvider) =>
    new SizeConstraintProviderWrapper(node, originalProvider)
)
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementationWrapper(
  (node) => node.tag !== null,
  (node, originalProvider) =>
    new SizeConstraintProviderWrapper(node, originalProvider)
)

Finally hideImplementation 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.nodeDecorator.sizeConstraintProviderDecorator.hideImplementation()
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.hideImplementation(
  (node) => node.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.nodeDecorator.sizeConstraintProviderDecorator.setFactory(
      (node) => new CustomSizeConstraintProvider(node)
    )
}

/**
 * @param {!IGraph} graph
 */
deregisterLookup(graph) {
  graph.decorator.nodeDecorator.remove(this.chainLink)
}registerLookup(graph: IGraph): void {
  this.chainLink =
    graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setFactory(
      (node) => new CustomSizeConstraintProvider(node)
    )!
}

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

Type Details

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

See Also

Constructors

Properties

Methods