# diagram-mind-map

> Horizontal mind-map diagram with custom user handles, draggable branches, and add/delete tools.

**Framework:** aspnet-mvc  **Component:** Diagram  **Variant:** mind-map

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/aspnet-mvc/diagram-mind-map.json
```

**Install Package(s)**

```bash
Install-Package Syncfusion.AspNetMvc.Diagram
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/diagram-mind-map/Diagram.cshtml

```cshtml
@using Syncfusion.EJ2;
@using EJ2MVCSampleBrowser.Models;

@section ControlsSection{
    <div class="control-section" style="width: 100%;height:100%; float:left; padding:0px">
        <div class="diagram-control">
            @(Html.EJS().Diagram("diagram").Width("100%").Height("550px").GetCustomTool("getTool").Created("diagramCreated").SelectionChange("selectionChange").GetNodeDefaults("getNodeDefaults")
                .GetConnectorDefaults("getConnectorDefaults").DataSourceSettings(ss => ss.Id("Id").ParentId("ParentId").DataSource(new DataManager() { Data = (List<MindMapDetails>)ViewData["Nodes"] }))
                .Layout(l => l.Type(Syncfusion.EJ2.Diagrams.LayoutType.MindMap).GetBranch("getBranch")).ScrollSettings(s => s.Padding(new Syncfusion.EJ2.Diagrams.DiagramMargin { Left=50,Right=50  })).SnapSettings(s => s.Constraints(Syncfusion.EJ2.Diagrams.SnapConstraints.None)).SelectedItems((Syncfusion.EJ2.Diagrams.DiagramSelector)ViewData["selectedItems"])
                .Render()
            )

            <input id="palette" style="visibility: hidden;position: absolute" type="color" name="favcolor" value="#000000">
            @(Html.EJS().SymbolPalette("palette").Render())

        </div>
    </div>
   
    <script>
        var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__; var __extends = (this && this.__extends) || (function () {
            var extendStatics = Object.setPrototypeOf ||
                /* jshint proto: true */
                ({ __proto__: [] } instanceof Array && function (der, b) { der.__proto__ = b; }) ||
                function (der, b) { for (var p in b) if (b.hasOwnProperty(p)) der[p] = b[p]; };
            return function (der, b) {
                extendStatics(der, b);
                function __() { this.constructor = der; }
                der.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
            };
        })();

        function getBranch(node, nodes) {
            return node.data.Branch;
        }

        function selectionChange(arg) {
            var diagram = document.getElementById("diagram").ej2_instances[0];
            if (arg.state === 'Changing') {
                if (arg.newValue[0]) {
                    for (var i = 0; i < diagram.selectedItems.userHandles.length; i++) {
                        diagram.selectedItems.userHandles[i].visible = true;
                    } /* tslint:disable:no-string-literal */
                    if ((arg.newValue[0].data.Branch === 'Left') ||
                        /* tslint:disable:no-string-literal */
                        (arg.newValue[0].data.Branch === 'subLeft')) {
                        hideUserHandle('leftHandle');
                        changeUserHandlePosition('leftHandle');
                        /* tslint:disable:no-string-literal */
                    } else if ((arg.newValue[0].data.Branch === 'Right') ||
                        /* tslint:disable:no-string-literal */
                        (arg.newValue[0].data.Branch === 'subRight')) {
                        hideUserHandle('rightHandle');
                        changeUserHandlePosition('rightHandle');
                    } else if (arg.newValue[0].data.Branch === 'Root') {
                        hideUserHandle('delete');
                    }
                } else {
                    hideUserHandle('leftHandle');
                    hideUserHandle('rightHandle');
                    hideUserHandle('delete');
                }
            }
        }
        function diagramCreated() {
            var diagram = document.getElementById("diagram").ej2_instances[0];
            diagram.layout.orientation = "Horizontal";
        }

        function getNodeDefaults(obj, diagram) {
            obj.constraints = ej.diagrams.NodeConstraints.Default & ~ej.diagrams.NodeConstraints.Drag;
            if ((obj.data.Branch === 'Left') || (obj.data.Branch === 'Right') || (obj.data.Branch === 'Root')) {
                obj.shape = { type: 'Basic', shape: 'Ellipse' }; obj.borderColor = 'black'; /* tslint:disable:no-string-literal */
                obj.style = {
                    fill: (obj.data.Branch === 'Root') ? '#E74C3C' : '#F39C12', strokeColor: 'none',
                    strokeWidth: 2
                };
                obj.annotations = [{
                    content: (obj.data.Label), margin: { left: 10, right: 10, top: 10, bottom: 10 },
                    style: { color: 'white' }
                }];
                var port = [{
                    id: 'port1', offset: { x: 0, y: 0.5 }, visibility: "Hidden",
                    style: { fill: 'black' }
                },
                {
                    id: 'port2', offset: { x: 1, y: 0.5 }, visibility: "Hidden",
                    style: { fill: 'black' }
                },
                ];
                for (var i = 0; i < port.length; i++) {
                    obj.ports.push(new ej.diagrams.PointPort(obj, 'ports', port[i], true));
                }
                hideUserHandle('Top');

            } else {
                var color; /* tslint:disable:no-string-literal */
                if ((obj.data.Branch === 'Right') || (obj.data.Branch === 'subRight')) {
                    color = '#8E44AD';
                } else {
                    color = '#3498DB';
                }
                obj.shape = {
                    type: 'Native', content: '<g><line x1="0" x2="100" y1="20" y2="20" stroke-width="5" stroke= '
                    + color + ' ' + ' ></line>'
                    + '<rect x="0" y="0"   width="100" height="20" fill="transparent" stroke="none"></rect></g>'
                };
                obj.shape = { type: 'Basic', shape: 'Rectangle' };
                obj.style = { fill: color, strokeWidth: 0 };
                obj.minWidth = 100;
                obj.height = 4;
                var port = [
                    {
                        id: 'port1', offset: { x: 0, y: 0.5 }, visibility: "Hidden",
                        style: { fill: 'black' }
                    },
                    {
                        id: 'port2', offset: { x: 1, y: 0.5 }, visibility: "Hidden",
                        style: { fill: 'black' }
                    },
                ];
                for (var i = 0; i < port.length; i++) {
                    obj.ports.push(new ej.diagrams.PointPort(obj, 'ports', port[i], true));
                }
                obj.annotations = [{
                    content: obj.data.Label, offset: { x: .5, y: 0 }, verticalAlignment: 'Bottom'
                }];
                obj.shape.margin = { left: 0, right: 0, top: 0, bottom: 0 };
            }
            return obj;
        }

        function getConnectorDefaults(connector, diagram) {
            connector.type = 'Bezier';
            connector.targetDecorator = { shape: 'None' };
            var sourceNode = getObject(connector.sourceID); var targetNode = getObject(connector.targetID);
            /* tslint:disable:no-string-literal */
            if ((targetNode.data.Branch === 'Right') || (targetNode.data.Branch === 'subRight')) {
                connector.sourcePortID = sourceNode.ports[0].id;
                connector.targetPortID = targetNode.ports[1].id;
                connector.style = { strokeWidth: 5, strokeColor: '#8E44AD' };
                /* tslint:disable:no-string-literal */
            } else if ((targetNode.data.Branch === 'Left') || (targetNode.data.Branch === 'subLeft')) {
                connector.sourcePortID = sourceNode.ports[1].id;
                connector.targetPortID = targetNode.ports[0].id;
                connector.style = { strokeWidth: 5, strokeColor: '#3498DB' };
            }
            connector.constraints &= ~ej.diagrams.ConnectorConstraints.Select;
            return connector;
        }

        function hideUserHandle(name) {
            var diagram = document.getElementById("diagram").ej2_instances[0];
            for (var i = 0; i < diagram.selectedItems.userHandles.length; i++) {
                var handle = diagram.selectedItems.userHandles[i];
                if (handle.name === name) {
                    handle.visible = false;
                }
            }
        }

        function changeUserHandlePosition(change) {
            var diagram = document.getElementById("diagram").ej2_instances[0];
            for (var i = 0; i < diagram.selectedItems.userHandles.length; i++) {
                var handle = diagram.selectedItems.userHandles[i];
                if (handle.name === 'delete' && change === 'leftHandle') {
                    applyHandle(handle, 'Left', 1, { top: 0, bottom: 0, left: 0, right: 10 }, 'Left', 'Top');

                } else if (handle.name === 'delete' && change === 'rightHandle') {
                    applyHandle(handle, 'Right', 1, { top: 0, bottom: 0, left: 10, right: 0 }, 'Right', 'Top');
                }
            }
        }
        //set the value for UserHandle element.
        function applyHandle(handle, side, offset, margin, halignment, valignment) {
            handle.side = side;
            handle.offset = offset;
            handle.margin = margin;
            handle.horizontalAlignment = halignment;
            handle.verticalAlignment = valignment;
        }

        function addNode(branch) {
            var obj = {};
            obj.id = ej.diagrams.randomId();
            obj.data = { Branch: branch };
            /* tslint:disable:no-string-literal */
            obj.data.Label = 'Node';
            return obj;
        }

        function getObject(objId) {
            var diagram = document.getElementById("diagram").ej2_instances[0];
            var nd;
            for (var i = 0; i < diagram.nodes.length; i++) {
                var node = diagram.nodes[i]
                if (node.id === objId) {
                    return node;
                }
            }
            return nd;
        }

        function addConnector(source, target) {
            var connector = {};
            connector.id = ej.diagrams.randomId();
            connector.sourceID = source.id; connector.targetID = target.id;
            return connector;
        }

        function getTool(action) {
            var diagram = document.getElementById("diagram").ej2_instances[0];
            if (action === 'leftHandle') {
                return new LeftExtendTool(diagram.commandHandler);
            } else if (action === 'rightHandle') {
                return new RightExtendTool(diagram.commandHandler);
            } else if (action === 'delete') {
                return new DeleteClick(diagram.commandHandler);
            }
        }

        var LeftExtendTool = (function (_super) {
            __extends(LeftExtendTool, _super);
            function LeftExtendTool() {
                return _super !== null && _super.apply(this, arguments) || this;
            }
            LeftExtendTool.prototype.mouseDown = function (args) {
                _super.prototype.mouseDown.call(this, args);
                this.inAction = true;
            };
            LeftExtendTool.prototype.mouseUp = function (args) {
                if (this.inAction) {
                    var diagram = document.getElementById("diagram").ej2_instances[0];
                    var selectedElement = this.commandHandler.getSelectedObject();
                    if (selectedElement[0]) {
                        if (selectedElement[0] instanceof ej.diagrams.Node) {
                            var branch = '';
                            if (selectedElement[0].data.Branch === 'Root') {
                                branch = 'Right';
                            }
                            else if (selectedElement[0].data.Branch === 'Right' ||
                                selectedElement[0].data.Branch === 'subRight') {
                                branch = 'subRight';
                            }
                            var node = addNode(branch);
                            node.data['Id'] = node.id;
                            var connector = addConnector(selectedElement[0], node);
                            diagram.clearSelection();
                            var nd = diagram.add(node);
                            diagram.add(connector);
                            diagram.doLayout();
                            diagram.bringIntoView(nd.wrapper.bounds);
                            diagram.startTextEdit(nd);
                        }
                    }
                }
            };
            return LeftExtendTool;
        }(ej.diagrams.ToolBase));

        function update(selectedObject, node) {
            var diagram = document.getElementById("diagram").ej2_instances[0];
            var connector = addConnector(selectedObject, node);
            diagram.clearSelection();
            var nd = diagram.add(node);
            diagram.add(connector);
            diagram.doLayout();
            diagram.startTextEdit(nd);
        }

        var RightExtendTool = (function (_super) {
            __extends(RightExtendTool, _super);
            function RightExtendTool() {
                return _super !== null && _super.apply(this, arguments) || this;
            }
            RightExtendTool.prototype.mouseDown = function (args) {
                _super.prototype.mouseDown.call(this, args);
                this.inAction = true;
            };
            RightExtendTool.prototype.mouseUp = function (args) {
                if (this.inAction) {
                    var diagram = document.getElementById("diagram").ej2_instances[0];
                    var selectedObject = this.commandHandler.getSelectedObject();
                    if (selectedObject[0]) {
                        if (selectedObject[0] instanceof ej.diagrams.Node) {
                            var branch = '';
                            if (selectedObject[0].data.Branch === 'Root') {
                                branch = 'Left';
                            }
                            else if (selectedObject[0].data.Branch === 'Left' ||
                                selectedObject[0].data.Branch === 'subLeft') {
                                branch = 'subLeft';
                            }
                            var node = addNode(branch);
                            node.data.Id = node.id;
                            var connector = addConnector(selectedObject[0], node);
                            diagram.clearSelection();
                            var nd = diagram.add(node);
                            diagram.add(connector);
                            diagram.doLayout();
                            diagram.bringIntoView(nd.wrapper.bounds);
                            diagram.startTextEdit(nd);
                        }
                    }
                }
            };
            return RightExtendTool;
        }(ej.diagrams.ToolBase));

        var DeleteClick = (function (_super) {
            __extends(DeleteClick, _super);
            function DeleteClick() {
                return _super !== null && _super.apply(this, arguments) || this;
            }
            DeleteClick.prototype.mouseDown = function (args) {
                _super.prototype.mouseDown.call(this, args);
                this.inAction = true;
            };
            DeleteClick.prototype.mouseUp = function (args) {
                var diagram = document.getElementById("diagram").ej2_instances[0];
                if (this.inAction) {
                    var selectedObject = this.commandHandler.getSelectedObject();
                    if (selectedObject[0]) {
                        if (selectedObject[0] instanceof ej.diagrams.Node) {
                            var node = selectedObject[0];
                            this.removeSubChild(node, diagram);
                        }
                        diagram.doLayout();
                    }
                }
            };
            DeleteClick.prototype.removeSubChild = function (node, diagram) {
                for (var i = node.outEdges.length - 1; i >= 0; i--) {
                    var connector = diagram.getObject(node.outEdges[i]);
                    var childNode = diagram.getObject(connector.targetID);
                    if (childNode.outEdges.length > 0) {
                        this.removeSubChild(childNode, diagram);
                    }
                    else {
                        diagram.remove(childNode);
                    }
                }
                diagram.remove(node);
            };
            return DeleteClick;
        }(ej.diagrams.ToolBase));

        function onchange(params) {
            var diagram = document.getElementById("diagram").ej2_instances[0];
            if (selectedObject[0].data.Branch === 'Root' || selectedObject[0].data.Branch === 'Left' || selectedObject[0].data.Branch === 'Right') {
                selectedObject[0].style.fill = args.target.value;
                diagram.dataBind();
            } else {
                selectedObject[0].annotations[0].style.color = args.target.value;
                diagram.dataBind();
            }
        }

    </script>
}

```

### src/components/diagram-mind-map/DiagramController.cs

```cs
using EJ2MVCSampleBrowser.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Diagrams;

namespace EJ2MVCSampleBrowser.Models
{
    public class MindMapDetails
    {
        public string Id;
        public string ParentId;
        public string Text;
        public string Branch;
        public static List<MindMapDetails> GetAllRecords()
        {
            return new List<MindMapDetails>
            {
                new MindMapDetails { Id = "1",  ParentId = "",  Text = "Creativity",      Branch = "Root" },
                new MindMapDetails { Id = "2",  ParentId = "1", Text = "Brainstorming",   Branch = "Right" },
                new MindMapDetails { Id = "3",  ParentId = "1", Text = "Complementing",   Branch = "Left"  },
                new MindMapDetails { Id = "4",  ParentId = "1", Text = "Conceptualizing", Branch = "Right" },
                new MindMapDetails { Id = "5",  ParentId = "1", Text = "Visualizing",     Branch = "Left"  },
                new MindMapDetails { Id = "6",  ParentId = "2", Text = "Mapping",         Branch = "Right" },
                new MindMapDetails { Id = "7",  ParentId = "2", Text = "Outlining",       Branch = "Right" },
                new MindMapDetails { Id = "8",  ParentId = "2", Text = "Sorting",         Branch = "Right" },
                new MindMapDetails { Id = "9",  ParentId = "2", Text = "Prioritizing",    Branch = "Right" },
                new MindMapDetails { Id = "10", ParentId = "3", Text = "Synthesizing",    Branch = "Left"  }
            };
        }
    }
}

namespace EJ2MVCSampleBrowser.Controllers.Diagram
{
    public partial class DiagramController : Controller
    {
        // GET: MindMap
        public ActionResult MindMap()
        {
            ViewData["Nodes"] = MindMapDetails.GetAllRecords();

            List<DiagramUserHandle> handle = new List<DiagramUserHandle>();
            handle.Add(new DiagramUserHandle()
            {
                Name = "leftHandle",
                PathData = "M11.924,6.202 L4.633,6.202 L4.633,9.266 L0,4.633 L4.632,0 L4.632,3.551 L11.923,3.551 L11.923,6.202Z",
                Visible = true,
                BackgroundColor = "black",
                Offset = 1,
                Side = Side.Left,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                Margin = new DiagramMargin() { Left = 0, Right = 10, Top = 0, Bottom = 0 },
                PathColor = "white"
            });
            DiagramSelector userHandle = new DiagramSelector();
            userHandle.Constraints = SelectorConstraints.UserHandle;
            userHandle.UserHandles = handle;
            ViewData["selectedItems"] = userHandle;

            return View("~/Views/Home/diagram/mind-map/Diagram.cshtml");
        }
    }
}
```
