You do not normally need to create an instance of this tool because one already exists as the ToolManager.draggingTool, which you can modify.
The Tool.name of this tool is "Dragging".
Optional
init: Partial<DraggingTool>Gets or sets the collection of Parts that this tool has copied. The value is a GMap mapping Parts to DraggingInfo Objects that have a "point" property remembering the original location of that Part. The value is null when moving instead of copying.
draggedParts provides the map of Parts that are being moved and from which this collection was copied.
Gets or sets whether for a copying operation the extended selection is copied or only the selected parts. The default value is true. Setting this property does not raise any events.
The CommandHandler.copiesConnectedLinks property serves a similar role for the CommandHandler.copySelection command, when the user types control-C to copy the currently selected parts.
The cursor to show when a drop is allowed and will result in a copy. This defaults to 'copy'. Read more about cursors at Diagram.currentCursor
Gets or sets the Part found at the mouse point. This is normally set by a call to standardMouseSelect.
On touch gestures only, this property gets or sets the time in milliseconds for which the mouse must be stationary before this tool can be started. The default value is 100 milliseconds. Setting this property does not raise any events.
Gets or sets the DraggingTool's DraggingOptions instance, which controls several dragging properties.
Several DraggingTool properties are just convenience properties:
Setting any of these properties really sets the corresponding dragOptions property.
Setting this property does not raise any events.
Gets or sets the collection of Parts being moved. The value is a GMap mapping Parts to DraggingInfo Objects that have a "point" property remembering the original location of that Part.
copiedParts provides the map of Parts that have been copied during a copying operation, if any.
Gets or sets whether the user can drag a single Link, disconnecting it from its connected nodes and possibly connecting it to valid ports when the link is dropped. The default value is false. Setting this property does not raise any events.
In order to avoid too many cases of having both ends of a dragged Link connect to the same node (if allowed), it is commonplace to decrease the LinkingBaseTool.portGravity to a smaller value such as 10 or 20.
This property is a convenience getter/setter, and sets a value on dragOptions.
Gets or sets whether moving or copying a node also includes all of the node's tree children and their descendants, along with the links to those additional nodes. The default value is false. Setting this property does not raise any events.
The CommandHandler.copiesTree property serves a similar role for the CommandHandler.copySelection command, when the user types control-C to copy the currently selected parts.
This property is a convenience getter/setter, and sets a value on dragOptions.
Gets or sets the size of the grid cell used when snapping during a drag if the value of isGridSnapEnabled is true. By default this property is the Size(NaN, NaN), which causes this tool to use the Panel.gridCellSize value of the Diagram.grid. Setting this property does not raise any events.
This property is a convenience getter/setter, and sets a value on dragOptions.
Gets or sets the Spot that specifies what point in the grid cell dragged parts snap to, if the value of isGridSnapEnabled is true. By default this property is Spot.TopLeft: node locations will snap exactly to the grid point. Setting this property does not raise any events.
This property is a convenience getter/setter, and sets a value on dragOptions.
Gets or sets the snapping grid's origin point, in document coordinates, if the value of isGridSnapEnabled is true. By default this property is the Point(NaN, NaN), which causes this tool to use the Panel.gridOrigin value from the Diagram.grid. Setting this property does not raise any events.
This property is a convenience getter/setter, and sets a value on dragOptions.
In 3.0 this is superceded by Router.isRealtime, and setting this property attempts to set that property on the "AvoidsLinks" Router.
Gets or sets whether link routing takes some short-cuts during dragging. When false Links whose routing is AvoidsNodes are not routed to avoid Nodes, in order to improve dragging performance. The default value is true.
Gets or sets whether for any internal copying operation is permitted by control-drag-and-drop. This property affects the behavior of mayCopy, but does not affect whether copied objects may be dropped into this diagram from a different diagram.
The default value is true. Setting this property does not raise any events.
Gets or sets whether the DraggingTool snaps objects to grid points. Whether the snapping movement of the dragged parts occurs during the drag or only upon a drop is determined by the value of isGridSnapRealtime.
This property does not affect dragging disconnected links, but those links to respect the Part.dragComputation, which can be used to snap them.
By default this property is false. Setting this property does not raise any events.
This property is a convenience getter/setter, and sets a value on dragOptions.
Gets or sets whether the DraggingTool snaps objects to grid points during the drag. This property is ignored unless isGridSnapEnabled is true. By default this property is true; when false parts are only snapped to grid locations upon the drop (i.e. mouse-up). Setting this property does not raise any events.
This property is a convenience getter/setter, and sets a value on dragOptions.
The cursor to show when a drop is allowed and will result in a move. This defaults to the empty string, which refers to the Diagram.defaultCursor. Read more about cursors at Diagram.currentCursor
The cursor to show when a drop is not allowed. This defaults to 'no-drop'. Read more about cursors at Diagram.currentCursor
Gets or sets the mouse point from which parts start to move. The value is a Point in document coordinates. This property is normally set to the diagram's mouse-down point in doActivate, but may be set to a different point if parts are being copied from a different control. Setting this property does not raise any events.
Virtual
Override
canThis tool can run if the diagram allows selection and moves/copies/dragging-out, if the mouse has moved far enough away to be a drag and not a click, and if findDraggablePart has found a selectable part at the mouse-down point.
This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.
Virtual
computeThis just calls CommandHandler.computeEffectiveCollection and remains for compatibility.
This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.
Potential options for the collection computation
a Map mapping Parts to DraggingInfo Objects that have a "point" property remembering the original location of that Part.
Virtual
computeThis method computes the new location for a Node or simple Part, given a new desired location and an optional Map of dragged parts, taking any grid-snapping into consideration, any Part.dragComputation function, and any Part.minLocation and Part.maxLocation.
This just calls Diagram.computeMove and remains for compatibility.
This method may be overridden, but should usually be overridden on Diagram. Please read the Introduction page on Extensions for how to override methods and how to call this base method.
the Node or simple Part that is being moved
the proposed new location
Optional
draggedparts: Map<Part, DraggingInfo>an optional Map mapping Parts to DraggingInfo Objects that have a "point" property remembering the original location of that Part.
Optional
result: Pointan optional Point that is modified and returned
the possibly grid-snapped computed Point that is within the minimum and maximum permitted locations
Override
doStart the dragging operation. This calls computeEffectiveCollection and saves the result as draggedParts.
This starts a "Drag" transaction. Depending on what happens, the transaction may be finished as a "Move" or a "Copy" transaction, or it may be rolled-back if the tool is cancelled.
Normally when this method is called the value of currentPart will be null, in which case this will call Tool.standardMouseSelect which will set currentPart. But if when this method is called the value of currentPart has already been set because the programmer wants the user to start dragging that Part, then this method will not need to call Tool.standardMouseSelect because the Part(s) to be selected and dragged have already been determined by the caller.
Override
doOverride
doVirtual
doPerform any additional side-effects during a drag, whether an internal move or copy or an external drag, that may affect the existing non-moved object(s).
This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.
a Point in document coordinates.
the GraphObject at the point, excluding what is being dragged or temporary objects; the argument may be null if the drag is occurring in the background of the diagram. Use GraphObject.part to get the Node or Part at the root of the visual tree of the stationary object.
Virtual
doPerform any additional side-effects after a drop, whether an internal move or copy or an external drop, that may affect the existing non-moved object(s).
This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.
a Point in document coordinates.
the GraphObject where the drop occurred, excluding what was dropped or temporary objects; the argument may be null if the drop occurred in the background of the diagram. Use GraphObject.part to get the Node or Part at the root of the visual tree of the stationary object.
Override
doOverride
doOverride
doMove the draggedParts (or if copying, the copiedParts) to follow the current mouse point.
If this creates any temporary parts, by default it adds them to the Tool layer.
This calls doDragOver for any side-effects on stationary parts.
Override
doOn a mouse-up finish moving or copying the effective selection.
This calls doDropOnto for any side-effects on stationary parts.
This also updates the diagram's bounds, raises a "SelectionCopied" or "SelectionMoved" DiagramEvent, and stops this tool.
This method also raises the "ChangingSelection" and "ChangedSelection" diagram events. Changes are performed in a "Drag" transaction, but the "ChangedSelection" event is raised outside the transaction.
Virtual
findReturn the selectable and movable/copyable Part at the mouse-down point. This is called by canStart to decide if this tool is ready to run.
This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.
Virtual
mayThis predicate is true when the diagram allows objects to be copied and inserted, and some object in the selection is copyable, and the user is holding down the Control key (Option key on Mac).
This method may be overridden, although in most cases it is easiest to set Part.copyable. Please read the Introduction page on Extensions for how to override methods and how to call this base method.
Virtual
mayThis predicate is true when the diagram allows objects to be moved, and some object in the selection is movable.
This method may be overridden, although in most cases it is easiest to set Part.movable. Please read the Introduction page on Extensions for how to override methods and how to call this base method.
Virtual
moveMove a collection Map of Parts by a given offset.
If check is true this respects the Part.canMove predicate for Nodes or simple Parts when this is the Diagram.currentTool. It also respects isGridSnapEnabled in order to try to automatically snap part locations to a grid. And it also uses the Part.dragComputation function, if any, to determine the new location for each part.
The first argument is a GMap as produced by computeEffectiveCollection, not a List or GSet or Iterator of Parts. Call Diagram.moveParts if you want to move a simple collection of Parts without having to create the argument Map.
a Map mapping Parts to DraggingInfo Objects that have a "point" property remembering the original location of that Part.
The offset, before snapping, to move parts. This offset reflects the total amount moved during tool operation, based on original Part locations remembered when the DraggingTool activated.
Optional
check: booleanWhether to check Part.canMove on each part. The default value is false.
Virtual
Override
standardThis override prevents the Control modifier unselecting an already selected part. This also remembers the selectable currentPart at the current mouse point.
This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.
Virtual
Override
stopThis calls the super Tool.stopTransaction method, and if the result is true
,
attempts to optimize the transaction by removing all changes except the first and last
by calling Transaction.optimize.
This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.
the result of the call to rollback or commit the transaction.
The DraggingTool is used to move or copy selected parts with the mouse. This sets the Part.location property; you may want to save the location to the model by using a TwoWay Binding on the "location" property in your Parts/Nodes/Groups templates.
Dragging the selection moves parts for which Part.canMove is true. If the user holds down the Control key (Option key on Mac), this tool will make a copy of the parts being dragged, for those parts for which Part.canCopy is true.
When the drag starts it calls computeEffectiveCollection to find the actual collection of Parts to be dragged. Normally this collection includes not only the Diagram.selection, but also parts that belong to those selected parts, such as members of groups. If dragsTree is true, the effective collection also includes all of the nodes and links that constitute the subtree starting from selected nodes. The result of computeEffectiveCollection is not a GSet but a GMap which remembers the original Part.location for all of the dragged parts. This map is saved as the value of draggedParts.
During the drag if the user holds down the Control/Option key this tool makes a copy of the draggedParts and proceeds to drag it around. (It only copies the Diagram.selection, not the whole effective collection, if copiesEffectiveCollection is false.) The collection of copied parts is held by copiedParts. It too is a GMap remembering the original locations of the parts. copiedParts will be null when this tool is moving (not copying) at the moment.
Each Part's movement is limited by the Diagram.computeMove method. By default it limits the Part.location to be within the bounds given by Part.minLocation and Part.maxLocation. (Those default to minus Infinity to plus Infinity.) As a further convenience, the value of NaN in minLocation and maxLocation cause Diagram.computeMove to use the part's current location. So, for example, an easy way to declare that the user may only drag a node horizontally is to just set:
If you set isGridSnapEnabled to true, dragged or copied parts will be snapped to points on a grid. The snapping occurs continuously during a drag unless you set isGridSnapRealtime to false. Normally the grid points come from the Diagram.grid, even if that grid is not GraphObject.visible. However you can override those grid's properties for the snapping grid cell size and offset by setting the properties here: gridSnapCellSize and gridSnapOrigin. This computes the point to snap to for each dragged part. The resulting point is used as the new Part.location.
For the most general control over where a part may be dragged, either set the Part.dragComputation property or override Diagram.computeMove. For the common case of wanting to keep member nodes within the Group that they are members of, you can do something like:
Note that this expects there to be a "SHAPE" object within the Group's visual tree that delimits where the part may be dragged within the group. This also expects that Group.computesBoundsIncludingLinks is false. Then in your node template(s), just set:
This tool does not utilize any Adornments or tool handles. If the drag is successful, it raises the "SelectionMoved" or "SelectionCopied" DiagramEvent and produces a "Move" or a "Copy" transaction.
If you want to programmatically start a new user's dragging of a particular existing node, you can make sure that node is selected, set the currentPart property, and then start and activate the tool.