For every standard event published by the Dijit framework,
the Diagram widget publishes two additional events that occur
in association with the node or link in which the event occurs. For
example, the standard Dijit
onMouseDown(e)
event
is associated with two other Diagram widget
events:onLinkMouseDown(link,e)
onNodeMouseDown(node,e)
These events are triggered when the event occurs within
the bounds of a link or node, and the event handlers receive this
element as the first parameter.
There is an option to connect to every node or link using
the GFX connection API. For example, if you need to
connect
to
the onmousedown
event of all nodes, you
can do a single connect to onNodeMouseDown
on
the Diagram widget.For example, the following code generates an alert when
the pointer enters a node:
dojo.connect(D,"onNodeMouseEnter",function(node,e) { alert("entered!); });
Dijit event | Associated event in a node | Associated event in a link |
---|---|---|
onContextMenu |
onNodeContextMenu |
onLinkContextMenu |
onClick |
onNodeClick |
onLinkClick |
onDblClick |
onNodeDblClick |
onLinkDblClick |
onMouseUp |
onNodeMouseUp |
onLinkMouseUp |
onMouseDown |
onNodeMouseDown |
onLinkMouseDown |
onMouseMove |
onNodeMouseMove |
onLinkMouseMove |
onMouseEnter |
onNodeMouseEnter |
onLinkMouseEnter |
onMouseLeave |
onNodeMouseLeave |
onLinkMouseLeave |
onMouseOver |
onNodeMouseOver |
onLinkMouseOver |
onMouseOut |
onNodeMouseOut |
onLinkMouseOut |
Every time the selection changes, there is a notification
event and the
onSelectionChanged([added],[removed])
method
is called. Through this method, you can call any custom function.
In the following code extract, the Diagram widget
is centered on the selected element:dojo.connect(Diagram.getSelection(),"onSelectionChanged",this,function(added,removed){ if(centerOnNode) { if(added.length==1) { Diagram.centerOnNode(added[0],true); } } });
Additional notification events are available for editing
the diagram:
beforeGraphElementDispose(graphElement)
: this event occurs before a graph element is disposedafterGraphElementDispose(graphElement)
: this event occurs after a graph element is disposed