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
Members
Properties
Gets the IRenderTreeGroup that holds the rendering of the background elements.
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
Developer's Guide
API
- foregroundGroup, contentGroup
Gets the IRenderTreeGroup that should be used by the application code to put actual content in.
See Also
Developer's Guide
API
- backgroundGroup, foregroundGroup
Gets the IRenderTreeGroup which is used for visual markers of the currentItem.
Gets the IRenderTreeGroup that holds the rendering of the foreground elements.
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
Developer's Guide
API
- backgroundGroup, contentGroup
Gets the IRenderTreeGroup which is used for visual markers to highlight IModelItems.
Gets the IRenderTreeGroup where the IInputModes should add their temporary content to.
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
Developer's Guide
API
- contentGroup, backgroundGroup, foregroundGroup
Gets an comparison instance that compares two IRenderTreeElement with respect to their rendering order.
Throws
- Exception ({ name: 'ArgumentError' })
- If one of the elements is not part of this tree.
Gets the root of the scene graph.
Gets the IRenderTreeGroup that should be used by the application code to put the selection indicators in.
Methods
Adds a Visual to the scene graph as a child of the parent group.
parent group.Parameters
- parent: IRenderTreeGroup
- The parent group to which the visual element is added.
- visual: Visual
- The Visual to add to the render tree.
Return Value
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
Developer's Guide
API
- remove, IObjectRenderer
Adds an IVisualCreator to the scene graph as a child of the parent group.
parent group.Parameters
- parent: IRenderTreeGroup
- The parent group to which the visual creator is added.
- visualCreator: IVisualCreator
- The IVisualCreator to add to the render tree.
Return Value
Examples
const renderTreeElement = graphComponent.renderTree.createElement(
graphComponent.renderTree.backgroundGroup,
new RectangleVisualCreator(rectangle),
)See Also
Developer's Guide
API
- remove, IObjectRenderer
Adds an ILookup implementation to the scene graph that provides the IObjectRenderer<T> interfaces (IVisualCreator, IBoundsProvider, IVisibilityTestable, IHitTestable) in its lookup implementation.
Parameters
- parent: IRenderTreeGroup
- The parent group to which the element is added.
- lookup: ILookup
- The ILookup implementation to add to the render-tree.
Return Value
Examples
// the node provides an IVisualCreator via its lookup
const renderTreeElement = graphComponent.renderTree.createElement(
graphComponent.renderTree.backgroundGroup,
node,
)See Also
Developer's Guide
API
- remove, IObjectRenderer
Adds a child element to the scene graph as a child of the parent group.
parent group.renderTag at rendering time.Parameters
- 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
renderTagto provide the various implementations that are used during rendering.
Return Value
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
Developer's Guide
API
- remove, IObjectRenderer
Adds a new IRenderTreeGroup to this group in the current scene graph.
null tag.Parameters
- parent: IRenderTreeGroup
- The IRenderTreeGroup to add a new IRenderTreeGroup to.
Return Value
See Also
Developer's Guide
API
- remove
Calculates the bounds for a given render tree element.
Parameters
- renderTreeElement: IRenderTreeElement
- The render tree element to query the bounds from
Return Value
- Rect
- The non-
nullbounds
Enumerates over all possible IRenderTreeElement instances in the tree below the given group.
Parameters
- 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 befalsewhich causes enumeration in declaration order.
Return Value
- 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.
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
- renderTreeElement: IRenderTreeElement
- The render tree element.
Return Value
Retrieves the IVisualCreator for a given IRenderTreeElement.
Parameters
- renderTreeElement: IRenderTreeElement
- the render tree element to query the visual creator implementation from
Return Value
- IVisualCreator
- an instance of the visual creator interface
See Also
Returns an IEnumerable<T> of all hit elements in the canvas below the given group.
Parameters
- 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.
Return Value
- IEnumerable<IRenderTreeElement>
- a live enumeration of the elements that are hit
See Also
Developer's Guide
API
- IHitTestable, hitTestRadius, hitTestRadius
Tests if a given render tree element is hit at the given location.
false.Parameters
- renderTreeElement: IRenderTreeElement
- the render tree element to test
- location: Point
- the coordinates of the query in the world coordinate system
Return Value
- 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
- element: IRenderTreeElement
- The element to remove from this render tree.
See Also
Developer's Guide
Changes the parent of the given element to be the newParent.
element to be the newParent.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
- element: IRenderTreeElement
- The element to move to another parent.
- newParent: IRenderTreeGroup
- The new parent group element for
element.
See Also
API
- remove