Manages the tree of IRenderTreeElements and IRenderTreeGroups that render elements inside a CanvasComponent
Remarks
This class keeps all relevant state and provides access to helper methods around the management of the render tree.
You don't create an instance of this type, but get it from the associated CanvasComponent's renderTree property.
It provides references to the predefined groups that are used for rendering various important parts of a CanvasComponent:
- foregroundGroup – Elements that are rendered in the foreground of the visualization and in front of the actual contents.
- inputModeGroup – Elements that are rendered typically in front of everything else and that typically only exist temporarily during user interaction like handles, marquee selection boxes, etc.
- highlightGroup – A layer of elements that add a highlighting effect at the top of the visualization, but behind the interaction decorators.
- focusGroup – A layer for showing the highlight to the user where the keyboard focus is.
- selectionGroup – Layer showing the selection decoration for the contents.
- contentGroup – The actual "contents" being displayed to the user, without any selection or input decoration, and excluding background rendering.
- backgroundGroup – Elements that are rendered in the background of the visualization and behind the actual contents. The user typically does not interact with this group directly.
This class cannot be instantiated
Type Details
- yFiles module
- view
Properties
Gets the IRenderTreeGroup that holds the rendering of the background elements.
Remarks
Examples
The backgroundGroup can be used for displaying visuals in the background of the main content. For example, a background image:
/**
* Creates the image for the background visual.
*/
class ImageVisualCreator
extends BaseClass<IVisualCreator>(IVisualCreator)
implements IVisualCreator
{
createVisual(context: IRenderContext): Visual {
const image = window.document.createElementNS(
'http://www.w3.org/2000/svg',
'image',
)
image.setAttribute('width', '640')
image.setAttribute('height', '480')
image.setAttribute('x', '-150')
image.setAttribute('y', '-160')
image.setAttributeNS(
'http://www.w3.org/1999/xlink',
'href',
'ylogo.svg',
)
return new SvgVisual(image)
}
updateVisual(context: IRenderContext, oldVisual: Visual): Visual {
return oldVisual
}
}
const renderTree = graphComponent.renderTree
renderTree.createElement(
renderTree.backgroundGroup,
new ImageVisualCreator(),
)
This image will scroll and zoom with the content, though. If a static image that doesn't move with the content is needed, add it as CSS background to the element of this component.
See Also
Gets the IRenderTreeGroup that should be used by the application code to put actual content in.
Remarks
See Also
Gets the IRenderTreeGroup which is used for visual markers of the currentItem.
Gets the IRenderTreeGroup that holds the rendering of the foreground elements.
Remarks
Examples
/**
* Creates the image for the foreground visual.
*/
class ImageVisualCreator
extends BaseClass<IVisualCreator>(IVisualCreator)
implements IVisualCreator
{
createVisual(context: IRenderContext): Visual {
const image = window.document.createElementNS(
'http://www.w3.org/2000/svg',
'image',
)
image.setAttribute('width', '640')
image.setAttribute('height', '480')
image.setAttribute('x', '-150')
image.setAttribute('y', '-160')
image.setAttributeNS(
'http://www.w3.org/1999/xlink',
'href',
'ylogo.svg',
)
return new SvgVisual(image)
}
updateVisual(context: IRenderContext, oldVisual: Visual): Visual {
return oldVisual
}
}
const renderTree = graphComponent.renderTree
renderTree.createElement(
renderTree.foregroundGroup,
new ImageVisualCreator(),
)
See Also
Gets the IRenderTreeGroup which is used for visual markers to highlight IModelItems.
Gets the IRenderTreeGroup where the IInputModes should add their temporary content to.
Remarks
Examples
In this example a custom IReshapeHandler installs a ghost visualization in the inputModeGroup.
initializeReshape(context: IInputModeContext) {
this.originalHandler.initializeReshape(context)
// ...
const node = new SimpleNode({
layout: this.originalHandler.bounds,
style: new ShapeNodeStyle({
fill: 'transparent',
stroke: '2px solid gray',
}),
})
const renderTree = context.canvasComponent!.renderTree
this.shadowElement = renderTree
.createElement(
renderTree.inputModeGroup,
node,
GraphModelManager.DEFAULT_NODE_RENDERER,
)
.toFront()
}
cancelReshape(context: IInputModeContext, originalBounds: Rect) {
context.canvasComponent.renderTree.remove(this.shadowElement)
this.originalHandler.cancelReshape(context, originalBounds)
}
The sample shows only the initializeReshape method where the ghost is installed and cancelReshape where the ghost is removed, again.
See Also
Gets an comparison instance that compares two IRenderTreeElement with respect to their rendering order.
Remarks
Signature Details
function(x: IRenderTreeElement, y: IRenderTreeElement) : number
Parameters
- x - IRenderTreeElement
- The first object to compare.
- y - IRenderTreeElement
- The second object to compare.
Returns
- number
- An integer value which is
<0
ifx
is less thany
,0
ifx
is equal toy
, or>0
ifx
is greater thany
Throws
- Exception({ name: 'ArgumentError' })
- If one of the elements is not part of this tree.
Gets the root of the scene graph.
Remarks
Gets the IRenderTreeGroup that should be used by the application code to put the selection indicators in.
Methods
createElement
<TRenderTag>(parent: IRenderTreeGroup, renderTag: TRenderTag, renderer: IObjectRenderer<TRenderTag>) : IRenderTreeElementAdds a child element to the scene graph as a child of the parent
group.
Remarks
renderTag
at rendering time.Type Parameters
- TRenderTag
Parameters
A map of options to pass to the method.
- parent - IRenderTreeGroup
- The parent group to which the child element is added.
- renderTag - TRenderTag
- The render tag to associate with this child element. This object will be passed to the
renderer
's methods. - renderer - IObjectRenderer<TRenderTag>
- An implementation of the IObjectRenderer<T> interface that will be passed the
renderTag
to provide the various implementations that are used during rendering.
Returns
Examples
Providing an IVisualCreator instance as renderTag
const renderTreeElement = graphComponent.renderTree.createElement(
graphComponent.renderTree.backgroundGroup,
new RectangleVisualCreator(rectangle),
)
Using a renderTag
which implements ILookup and returns its own IVisualCreator.
// the node provides an IVisualCreator via its lookup
const renderTreeElement = graphComponent.renderTree.createElement(
graphComponent.renderTree.backgroundGroup,
node,
)
Visuals provided as renderTag
can be used "as is"
const image = window.document.createElementNS(
'http://www.w3.org/2000/svg',
'image',
)
image.setAttributeNS(
'http://www.w3.org/1999/xlink',
'href',
'resources/background.png',
)
image.x.baseVal.value = 1
image.y.baseVal.value = 1
image.width.baseVal.value = 100
image.height.baseVal.value = 100
const visual = new SvgVisual(image)
graphComponent.renderTree.createElement(
graphComponent.renderTree.rootGroup,
visual,
)
See Also
Adds a Visual to the scene graph as a child of the parent
group.
Parameters
A map of options to pass to the method.
- parent - IRenderTreeGroup
- The parent group to which the visual element is added.
- visual - Visual
- The Visual to add to the render tree.
Returns
Examples
const image = window.document.createElementNS(
'http://www.w3.org/2000/svg',
'image',
)
image.setAttributeNS(
'http://www.w3.org/1999/xlink',
'href',
'resources/background.png',
)
image.x.baseVal.value = 1
image.y.baseVal.value = 1
image.width.baseVal.value = 100
image.height.baseVal.value = 100
const visual = new SvgVisual(image)
graphComponent.renderTree.createElement(
graphComponent.renderTree.rootGroup,
visual,
)
See Also
Adds an IVisualCreator to the scene graph as a child of the parent
group.
Parameters
A map of options to pass to the method.
- parent - IRenderTreeGroup
- The parent group to which the visual creator is added.
- visualCreator - IVisualCreator
- The IVisualCreator to add to the render tree.
Returns
Examples
const renderTreeElement = graphComponent.renderTree.createElement(
graphComponent.renderTree.backgroundGroup,
new RectangleVisualCreator(rectangle),
)
See Also
Adds an ILookup implementation to the scene graph that provides the IObjectRenderer<T> interfaces (IVisualCreator, IBoundsProvider, IVisibilityTestable, IHitTestable) in its lookup implementation.
Parameters
A map of options to pass to the method.
- parent - IRenderTreeGroup
- The parent group to which the element is added.
- lookup - ILookup
- The ILookup implementation to add to the render-tree.
Returns
Examples
// the node provides an IVisualCreator via its lookup
const renderTreeElement = graphComponent.renderTree.createElement(
graphComponent.renderTree.backgroundGroup,
node,
)
See Also
Adds a new IRenderTreeGroup to this group in the current scene graph.
Remarks
null
tag.Parameters
A map of options to pass to the method.
- parent - IRenderTreeGroup
- The IRenderTreeGroup to add a new IRenderTreeGroup to.
Returns
See Also
Calculates the bounds for a given render tree element.
Remarks
Parameters
A map of options to pass to the method.
- renderTreeElement - IRenderTreeElement
- The render tree element to query the bounds from
Returns
- ↪Rect
- The non-
null
bounds
Enumerates over all possible IRenderTreeElement instances in the tree below the given group.
Remarks
Parameters
A map of options to pass to the method.
- root - IRenderTreeGroup
- The group at which the enumeration should yield all the children recursively. If omitted/
null
, this will iterate over all elements in the tree. - reverse - boolean
- Whether the elements should be iterated in reverse order. Elements rendered last (on top) will be enumerated first when set to
true
. This is useful for hit testing. When not specified, the default will befalse
which causes enumeration in declaration order.
Returns
- ↪IEnumerable<IRenderTreeElement>
- A live enumerable for all IRenderTreeElements in the tree below the given group.
Gets the Visual that is currently visualizing the given IRenderTreeElement.
Remarks
null
. However, if a visual is currently being displayed for the given render tree element, it will be returned. This method should be used with care. Manipulation of the given instance should normally be done through the corresponding IVisualCreator that created the visual in the first place. This method rather serves as a utility method for UI testing frameworks and similar use cases.Parameters
A map of options to pass to the method.
- renderTreeElement - IRenderTreeElement
- The render tree element.
Returns
Retrieves the IVisualCreator for a given IRenderTreeElement.
Parameters
A map of options to pass to the method.
- renderTreeElement - IRenderTreeElement
- the render tree element to query the visual creator implementation from
Returns
- ↪IVisualCreator
- an instance of the visual creator interface
See Also
hitElementsAt
(location: Point, context?: IInputModeContext, root?: IRenderTreeGroup) : IEnumerable<IRenderTreeElement>Returns an IEnumerable<T> of all hit elements in the canvas below the given group.
Remarks
Parameters
A map of options to pass to the method.
- location - Point
- the coordinates for the hit test.
- context - IInputModeContext
- The context to use for passing to the isHit implementations. If not specified, the CanvasComponent's inputModeContext will be used.
- root - IRenderTreeGroup
- the root of the scene graph or rootGroup if none is specified.
Returns
- ↪IEnumerable<IRenderTreeElement>
- a live enumeration of the elements that are hit
See Also
Tests if a given render tree element is hit at the given location.
Remarks
false
.Parameters
A map of options to pass to the method.
- renderTreeElement - IRenderTreeElement
- the render tree element to test
- location - Point
- the coordinates of the query in the world coordinate system
Returns
- ↪boolean
- whether the render tree element is hit at the given location
Removes an element from this tree along with all its descendants if it's a group.
Parameters
A map of options to pass to the method.
- element - IRenderTreeElement
- The element to remove from this render tree.
Changes the parent of the given element
to be the newParent
.
Remarks
newParent
also needs to be managed by and included in this render tree. element
may not be the new parent or an ancestor of the new parent, either, as this would create a cycle.Parameters
A map of options to pass to the method.
- element - IRenderTreeElement
- The element to move to another parent.
- newParent - IRenderTreeGroup
- The new parent group element for
element
.