Drag and drop nodes over other elements
18 Nov 20186 minutes to read
Diagram provides support to drop a node/connector over another node/connector. The drop event is raised to notify that an element is dropped over another one and it is disabled, by default. It can be enabled with the constraints property.
User handles
- User handles are used to add some frequently used commands around the selector. To create user handles, define and add them to the
userHandlescollection of theselectedItemsproperty. - The name property of user handle is used to define the name of the user handle and its further used to find the user handle at runtime and do any customization.
Alignment
User handles can be aligned relative to the node boundaries. It has margin, offset, side, horizontalAlignment, and verticalAlignment settings. It is quite tricky when all four alignments are used together but gives more control over alignment.
Offset
The offset property of userHandles is used to align the user handle based on fractions. 0 represents top/left corner, 1 represents bottom/right corner, and 0.5 represents half of width/height.
Side
The side property of userHandles is used to align the user handle by using the Top, Bottom, Left, and Right options.
Horizontal and vertical alignments
The horizontalAlignment property of userHandles is used to set how the user handle is horizontally aligned at the position based on the offset. The verticalAlignment property is used to set how user handle is vertically aligned at the position.
Margin
Margin is an absolute value used to add some blank space in any one of its four sides. The userHandles can be displaced with the margin property.
Notification for the mouse button clicked
The diagram component notifies the mouse button clicked. For example, whenever the right mouse button is clicked, the clicked button is notified as right. The mouse click is notified with,
| Notification | Description |
|---|---|
| Left | When the left mouse button is clicked, left is notified |
| Middle | When the mouse wheel is clicked, middle is notified |
| Right | When the right mouse button is clicked, right is notified |
function click(arg) {
//Obtains the clicked mouse button
var button = arg.button
}Appearance
The appearance of the user handle can be customized by using the size, borderColor, backgroundColor, visible, pathData, and pathColor properties of the userHandles.
function getTool(action) {
var tool;
if (action === 'clone') {
tool = new CloneTool(diagram.commandHandler);
}
return tool;
}
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
/* jshint proto: true */
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var CloneTool = (function (_super) {
__extends(CloneTool, _super);
function CloneTool() {
return _super !== null && _super.apply(this, arguments) || this;
}
CloneTool.prototype.mouseDown = function (args) {
var newObject;
if (diagram.selectedItems.nodes.length > 0) {
newObject = ej.diagrams.cloneObject(diagram.selectedItems.nodes[0]);
}
else {
newObject = ej.diagrams.cloneObject(diagram.selectedItems.connectors[0]);
}
newObject.id += ej.diagrams.randomId();
diagram.paste([newObject]);
args.source = diagram.nodes[diagram.nodes.length - 1];
args.sourceWrapper = args.source.wrapper;
_super.prototype.mouseDown.call(this, args);
this.inAction = true;
};
return CloneTool;
}(ej.diagrams.MoveTool));