Changing the displaying order of a graph's items (z-order)
Questions & AnswersSummary
ICanvasObjects of IModelItems and how to change the order in which they are painted (e.g. forcing one object to be drawn in front of other objects)Description
To gain control over some details of the drawing of items as nodes and edges, like the drawing order,
one can use the various methods of com.yworks.canvas.ICanvasObject:
- mark the item for repainting: set
ICanvasObject.dirty:booleantotrue - show or hide the item: set
ICanvasObject.visible - to control the painting order (z-order) use:
To get the ICanvasObject for an item, use the com.yworks.graph.model.GraphModelManager's
method getCanvasObjects(item:IModelItem):Array,
which returns an Array of the canvas objects which are related to the item. The GraphModelManager can be
obtained from the com.yworks.ui.GraphCanvasComponent's property graphModelManager.
Thus, the complete code to get the item's canvas objects is (where gcc is the GraphCanvasComponent):
var canvasObjects:Array = gcc.graphModelManager.getCanvasObjects( item );
Using canvas object groups
Canvas object groups, described by com.yworks.canvas.ICanvasObjectGroup offer the same functionality as com.yworks.canvas.ICanvasObjects, i.e. you
can, for example, put whole groups into the back by calling toBack() on a ICanvasObjectGroup.
Some important object groups are
- the content group which contains the whole content of the graph and which can be accessed by
GraphCanvasComponent.contentGroup - the selection group, which contains the canvas objects selected by the user and which can be accessed by
GraphCanvasComponent.selectionGroup
com.yworks.graph.model.GraphModelManager:
- The nodes:
gmm.nodeGroup - The edges:
gmm.edgeGroup - The node labels:
gmm.nodeLabelGroup - The edge labels:
gmm.edgeLabelGroup - The ports:
gmm.portGroup
gmm is the instance of the GraphModelManager
Draw edges behind grouped nodes
When using a grouped graph, edges are drawn in front of nodes.Since yFiles FLEX 1.5 theGraphModelManager offers the property drawEdgesBehindGroupedNodes that can be set to true to render the edges behind the nodes.