Constructs an event handler that connects vertices using the specified factory method to create the new edges.
Holds the change event listener for later removal.
Holds the offset for connect icons during connection preview. Default is mxPoint(0, Constants#TOOLTIP_VERTICAL_OFFSET). Note that placing the icon under the mouse pointer with an offset of (0,0) will affect hit detection.
Image that is used to trigger the creation of a new connection. This is used in createIcons.
Holds the ConstraintHandler used for drawing and highlighting constraints.
Specifies if
Specifies the cursor to be used while the handler is active. Default is null.
Holds the drill event listener for later removal.
Optional
Specifies if events are handled. Default is false.
Holds the current validation error while connections are being created.
Holds the event names and associated listeners in an array. The array contains the event name followed by the respective listener for each registered listener.
Specifies if events can be fired. Default is true.
Optional source for events. Default is null.
Function that is used for creating new edges. The function takes the source and target Cell as the first and second argument and returns a new Cell that represents the edge. This is used in createEdge.
Holds the Point where the mouseDown took place while the handler is active.
Reference to the enclosing Graph.
Specifies if the connection handler should ignore the state of the mouse button when highlighting the source. Default is false, that is, the handler only highlights the source if no button is being pressed.
Specifies if new edges should be inserted before the source vertex in the cell hierarchy. Default is false for backwards compatibility.
Specifies if the actual shape of the edge state should be used for the preview.
Default is false. (Ignored if no edge state is created in
Holds the CellMarker used for finding source and target cells.
Counts the number of mouseDown events since the start. The initial mouse down event counts as 1.
Specifies if icons should be moved to the back of the overlay pane. This can be set to true if the icons of the connection handler conflict with other handles, such as the vertex label move handle. Default is false.
Specifies if icons should be displayed inside the graph container instead of the overlay pane. This is used for HTML labels on vertices which hide the connect icon. This has precedence over moveIconBack when set to true.
Switch to enable moving the preview away from the mousepointer. This is required in browsers where the preview cannot be made transparent to events and if the built-in hit detection on the HTML elements in the page should be used.
Specifies if connections to the outline of a highlighted target should be enabled. This will allow to place the connection point along the outline of the highlighted target.
Specifies if new edges should be selected. Default is true.
Specifies if the connect icon should be centered on the target state while connections are being previewed. Default is false.
Specifies if single clicks should add waypoints on the new edge. Default is false.
Static
pluginBinds the specified function to the given event name. If no event name is given, then the listener is registered for all events.
The parameters of the listener are the sender and an EventObject.
Returns true if the connection for the given constraints is valid. This implementation returns true if the constraints are not pointing to the same fixed connection point.
Converts the given point from screen coordinates to model coordinates.
Creates and returns a new edge using
Hook to return an
Use the following code to create a preview for an existing edge style:
graph.getPlugin('ConnectionHandler').createEdgeState(me)
{
var edge = graph.createEdge(null, null, null, null, null, 'edgeStyle=elbowEdgeStyle');
return new CellState(this.graph.view, edge, this.graph.getCellStyle(edge));
};
Optional
me: InternalMouseEventCreates the array ImageShapes that represent the connect icons for the given CellState.
Creates and returns the CellMarker used in arker.
Dispatches the given event to the listeners which are registered for the event. The sender argument is optional. The current execution scope ("this") is used for the listener invocation (see Utils#bind).
Example:
fireEvent(new mxEventObject("eventName", key1, val1, .., keyN, valN))
EventObject that represents the event.
Optional sender to be passed to the listener. Default value is
the return value of
Hook to return the Image used for the connection icon of the given CellState. This implementation returns connectImage.
Hook to update the icon position(s) based on a mouseOver event. This is an empty implementation.
Point that represents the next point along the previewed edge.
MouseEvent that represents the mouse move.
Returns the perimeter point for the given target state.
MouseEvent that represents the mouse move.
Creates, inserts and returns the new edge for the given parameters. This
implementation does only use
Returns true if the given cell does not allow new connections to be created.
Returns true if the given cell is connectable. This is a hook to disable floating connections. This implementation returns true.
Returns true if a tap on the given source state should immediately start connecting. This implementation returns true if the state is not movable in the graph.
Returns
Mousedown event of the connect gesture.
Returns true if the state has a HTML label in the graph's container, otherwise it returns oveIconFront.
Returns true if the given mouse down event should start this handler. The
This implementation returns true if the event does not force marquee
selection, and the currentConstraint and currentFocus of the
Returns Graph#isValidSource for the given source terminal.
MouseEvent that is associated with this call.
Returns true. The call to Graph#isValidTarget is implicit by calling
Graph#getEdgeValidationError in
Handles the event by initiating a new connection.
Handles the event by updating the preview edge or by highlighting a possible source or target terminal.
Handles the event by inserting the new connection.
Destroys the handler and all its resources and DOM nodes. This should be called on all instances. It is called automatically for the built-in instance created for each Graph.
Redraws the given array of ImageShapes.
Array of ImageShapes to be redrawn.
Called to snap the given point to the current preview. This snaps to the first point of the preview if alt is not pressed.
Updates the current state for a given mouse move event by using the arker.
Updates
Hook to update the icon position(s) based on a mouseOver event. This is an empty implementation.
Array of currently displayed icons.
MouseEvent that contains the mouse event.
Returns the error message or an empty string if the connection for the given source target pair is not valid. Otherwise it returns null. This implementation uses Graph#getEdgeValidationError.
Graph event handler that creates new connections. Uses CellMarker for finding and highlighting the source and target vertices and factoryMethod to create the edge instance.
This handler is enabled using Graph.setConnectable.
Example:
Here is an alternative solution that just sets a specific user object for new edges by overriding insertEdge.
Using images to trigger connections
This handler uses CellMarker to find the source and target cell for the new connection and creates a new edge using connect. The new edge is created using createEdge which in turn uses factoryMethod or creates a new default edge.
The handler uses a "highlight-paradigm" for indicating if a cell is being used as a source or target terminal, as seen in other diagramming products. In order to allow both, moving and connecting cells at the same time, DEFAULT_HOTSPOT is used in the handler to determine the hotspot of a cell, that is, the region of the cell which is used to trigger a new connection. The constant is a value between 0 and 1 that specifies the amount of the width and height around the center to be used for the hotspot of a cell and its default value is 0.5. In addition, MIN_HOTSPOT_SIZE defines the minimum number of pixels for the width and height of the hotspot.
This solution, while standards compliant, may be somewhat confusing because there is no visual indicator for the hotspot and the highlight is seen to switch on and off while the mouse is being moved in and out. Furthermore, this paradigm does not allow to create different connections depending on the highlighted hotspot as there is only one hotspot per cell, and it normally does not allow cells to be moved and connected at the same time as there is no clear indication of the connectable area of the cell.
To come across these issues, the handle has an additional createIcons hook with a default implementation that allows to create one icon to be used to trigger new connections. If this icon is specified, then new connections can only be created if the image is clicked while the cell is being highlighted. The createIcons hook may be overridden to create more than one ImageShape for creating new connections, but the default implementation supports one image and is used as follows:
In order to display the "connect image" whenever the mouse is over the cell, an DEFAULT_HOTSPOT of 1 should be used:
In order to avoid confusion with the highlighting, the highlight color should not be used with a connect image:
To install the image, the connectImage field of the ConnectionHandler must be assigned a new Image instance:
This will use the green-dot.gif with a width and height of 14 pixels as the image to trigger new connections. In createIcons the icon field of the handler will be set in order to remember the icon that has been clicked for creating the new connection. This field will be available under selectedIcon in the connect method, which may be overridden to take the icon that triggered the new connection into account. This is useful if more than one icon may be used to create a connection.
Events
InternalEvent.START
Fires when a new connection is being created by the user. The
state
property contains the state of the source cell.InternalEvent.CONNECT
Fires between begin- and endUpdate in connect. The
cell
property contains the inserted edge, theevent
andtarget
properties contain the respective arguments that were passed to connect (where target corresponds to the dropTarget argument). Finally, theterminal
property corresponds to the target argument in connect or the clone of the source terminal if createTarget is enabled.Note that the target is the cell under the mouse where the mouse button was released. Depending on the logic in the handler, this doesn't necessarily have to be the target of the inserted edge. To print the source, target or any optional ports IDs that the edge is connected to, the following code can be used. To get more details about the actual connection point, Graph.getConnectionConstraint can be used. To resolve the port IDs, use <Transactions.getCell>.
InternalEvent.RESET
Fires when the reset method is invoked.