Search results

Interaction

Selection

Selector provides a visual representation of selected elements. It behaves like a container and allows to update the size, position, and rotation angle of the selected elements through interaction and by using program. Single or multiple elements can be selected at a time.

Single selection

An element can be selected by clicking that element. During single click, all previously selected items are cleared. The following image shows how the selected elements are visually represented.

Single Selection

  • While selecting the diagram elements, the following events can be used to do your customization.
  • When selecting/unselecting the diagram elements, the selectionChange event gets triggered.

Selecting a group

When a child element of any group is clicked, its contained group is selected instead of the child element. With consecutive clicks on the selected element, selection is changed from top to bottom in the hierarchy of parent group to its children.

Multiple selection

Multiple elements can be selected with the following ways:

  • Ctrl+Click

During single click, any existing item in the selection list be cleared, and only the item clicked recently is there in the selection list. To avoid cleaning the old selected item, Ctrl key must be on hold when clicking.

Multiple Selection

  • Selection rectangle/rubber band selection

Clicking and dragging the diagram area allows to create a rectangular region. The elements that are covered under the rectangular region are selected at the end.

Multiple Rubberband Selection

Select/Unselect elements using program

The client-side methods select and clearSelection help to select or clear the selection of the elements at runtime. The following code example illustrates how to select or clear the selection of an item using program.

Get the current selected items from the nodes and connectors collection of the selectedItems property of the diagram model.

Select entire elements in diagram programmatically

The client-side method selectAll used to select all the elements such as nodes/connectors in the diagram. Refer to the following link which shows how to use selectAll method on the diagram.

Drag

  • An object can be dragged by clicking and dragging it. When multiple elements are selected, dragging any one of the selected elements move every selected element.
  • When you drag the elements in the diagram, the positionChange event gets triggered and to do customization in this event.

Drag

Resize

  • Selector is surrounded by eight thumbs. When dragging these thumbs, selected items can be resized.
  • When one corner of the selector is dragged, opposite corner is in a static position.
  • When a node is resized, the sizeChange event gets triggered.

Resize

Note: While dragging and resizing, the objects are snapped towards the nearest objects to make better alignments. For better alignments, refer to Snapping.

Rotate

  • A rotate handler is placed above the selector. Clicking and dragging the handler in a circular direction lead to rotate the node.
  • The node is rotated with reference to the static pivot point.
  • Pivot thumb (thumb at the middle of the node) appears while rotating the node to represent the static point.

Rotate

Connection editing

  • Each segment of a selected connector is editable with some specific handles/thumbs.

Note: For connector editing, you have to inject the ConnectorEditing module.

End point handles

Source and target points of the selected connectors are represented with two handles. Clicking and dragging those handles help you to adjust the source and target points.

Drag End Point Handles

  • If you drag the connector end points, then the following events can be used to do your customization.
  • When the connector source point is changed, the sourcePointChange event gets triggered.
  • When the connector target point is changed, the targetPointChange event gets triggered.
  • When you connect connector with ports/node or disconnect from it, the connectionChange event gets triggered.

Straight segment editing

  • End point of each straight segment is represented by a thumb that enables to edit the segment.
  • Any number of new segments can be inserted into a straight line by clicking, when Shift and Ctrl keys are pressed (Ctrl+Shift+Click).

Straight Segment Editing Addition

  • Straight segments can be removed by clicking the segment end point, when Ctrl and Shift keys are pressed (Ctrl+Shift+Click).

Straight Segment Editing Remove

Orthogonal thumbs

  • Orthogonal thumbs allow you to adjust the length of adjacent segments by clicking and dragging it.
  • When necessary, some segments are added or removed automatically, when dragging the segment. This is to maintain proper routing of orthogonality between segments.

orthogonal Segment Edit

Bezier thumbs

  • Bezier segments are annotated with two thumbs to represent the control points. Control points of the curve can be configured by clicking and dragging the control thumbs.

Bezier Segement Thumb

Drag and drop nodes over other elements

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 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 userHandles collection of the selectedItems property.
  • 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.

Appearance

The appearance of the user handle can be customized by using the size, borderColor, backgroundColor, visible, pathData, and pathColor properties of the userHandles.

node.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Diagrams;
using System.Drawing;

namespace EJ2MVCSampleBrowser.Controllers.Diagram {
    public partial class DiagramController: Controller {
        // GET: Nodes
        public ActionResult Nodes() {
            List < DiagramNode > nodes = new List < DiagramNode > ();
            List < DiagramNodeAnnotation > Node1 = new List < DiagramNodeAnnotation > ();
            nodes.Add(new DiagramNode() {
                Id = "node1",
                    Width = 100,
                    Height = 100,
                    Style = new NodeStyleNodes() {
                        Fill = "darkcyan"
                    },
                    Shape = new { type = "Basic", shape = "Rectangle" },
                    OffsetX = 100,
                    OffsetY = 100,
            });
            ViewBag.nodes = nodes;

            List<DiagramUserHandle> Userhandle = new List<DiagramUserHandle>();
            Userhandle.Add(new DiagramUserHandle()
            {
                Name = "clone",
                PathData = "M60.3,18H27.5c-3,0-5.5,2.4-5.5,5.5v38.2h5.5V23.5h32.7V18z M68.5,28.9h-30c-3," +
        "0-5.5,2.4-5.5,5.5v38.2c0,3,2.4,5.5,5.5,5.5h30c3,0,5.5-2.4,5.5-5.5V34.4C73.9,31.4,71.5,28.9,68.5,28.9z " +
        "M68.5,72.5h-30V34.4h30V72.5z",
                Visible = true,
                Offset = 0,
                Side = Side.Bottom,
                Margin = new DiagramMargin() { Left = 0, Right = 0, Top = 0, Bottom = 0 }
            });

            ViewBag.userhandle = Userhandle;
            ViewBag.getTool = "getTool";
            return View();
        }
    }
}
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));

Zoom pan

  • When a large diagram is loaded, only certain portion of the diagram is visible. The remaining portions are clipped. Clipped portions can be explored by scrolling the scrollbars or panning the diagram.
  • Diagram can be zoomed in or out by using Ctrl + mouse wheel.
  • When the diagram is zoomed or panned, the scrollChange event gets triggered.

Zoom Pan

Keyboard

Diagram provides support to interact with the elements with key gestures. By default, some in-built commands are bound with a relevant set of key combinations.

The following table illustrates those commands with the associated key values.

Shortcut Key Command Description
Ctrl + A selectAll Select all nodes/connectors in the diagram.
Ctrl + C copy Copy the diagram selected elements.
Ctrl + V paste Pastes the copied elements.
Ctrl + X cut Cuts the selected elements.
Ctrl + Z undo Reverses the last editing action performed on the diagram.
Ctrl + Y redo Restores the last editing action when no other actions have occurred since the last undo on the diagram.
Delete delete Deletes the selected elements.
Ctrl/Shift + Click on object Multiple selection (Selector binds all selected nodes/connectors).
Up Arrow nudge(“up”) nudgeUp: Moves the selected elements towards up by one pixel.
Down Arrow nudge(“down”) nudgeDown: Moves the selected elements towards down by one pixel.
Left Arrow nudge(“left”) nudgeLeft: Moves the selected elements towards left by one pixel.
Right Arrow nudge(“right”) nudgeRight: Moves the selected elements towards right by one pixel.
Ctrl + MouseWheel zoom Zoom (Zoom in/Zoom out the diagram).
F2 startLabelEditing Starts to edit the label of selected element.
Esc endLabelEditing Sets the label mode as view and stops editing.

See Also