DHTMLX Diagram 3.1 with Mind Maps, Configurable Per-Shape Toolbar, Custom Event Handlers, and TypeScript Support

DHTMLX Diagram has been updated to version 3.1. We have incorporated plenty of feedback from the users of our JavaScript diagramming component into the release. Now you can create and customize mind maps, edit them on the fly via the mind map editor, fine-tune a per-shape toolbar, and add custom event handlers to custom shapes. Besides, built-in type definitions become available to help you code diagrams faster.

Test the new trial version 3.1 free for 30 days and explore the release details in our article.

Brand-New Mind Map Diagram

The keynote of the release 3.1 is the introduction of a new diagram type – mind map. Mind maps are intended for the visualization of information with multiple hierarchically arranged concepts branching off from the core idea. This diagram type can be applied to structure business, scientific, technical, and any other kinds of data.

DHTMLX Mind MapCheck the sample >

Creating mind maps using the DHTMLX Diagram library is now possible due to a new type of shapes specific to mind maps called the “topic” shapes. They are the default type of shapes in DHTMLX mind maps.

DHTMLX mind map topic shape

The library’s API allows configuring topic shapes according to your requirements. You can adjust the shapes’ size, offset, background and border color, text decoration and alignment as well as apply your own CSS classes to shapes.

To arrange shapes in the right hierarchical order, you can either specify the parent id of each shape via the parent configuration property or link shapes to each other using the configuration properties of the connector object. The from and to properties of the connector object enable you to define which shapes to link with a particular connector. Besides, you can choose if a connector is a dashed or solid line with the help of the optional type property:

const data = [
       // shapes
    { id: "1", text: "49 emotions" },
    { id: "2", text: "Positive and lively" },
    { id: "3", text: "Quiet positive" },
    { id: "4", text: "Caring" },
    { id: "5", text: "Reactive" },
    // connectors
    { "id": "1-2", "from": "1", "to": "2", "type": "dash" },
    { "id": "1-3", "from": "1", "to": "3", "type": "dash" },
    { "id": "1-4", "from": "1", "to": "4", "type": "line" },
    { "id": "1-5", "from": "1", "to": "5", "type": "line" },
];

DHTMLX mind map connectors

While a solid line is the default connector type, you can alter it via the defaultLinkType property of the diagram object:

const diagram = new dhx.Diagram(document.body, {
    type: "mindmap",
    defaultLinkType: "line"        
});

DHTMLX mind maps provide an opportunity to arrange child shapes both to the right and to the left of the root shape. For this purpose, we have introduced the typeConfig option, which determines the direction of mind map branches. The direction attribute of the typeConfig option can be set to left or right:

const diagram = new dhx.Diagram(document.body, {
    type: "mindmap",
    typeConfig: {
        direction: "right",
    }
});
diagram.data.parse(data);

DHTMLX mindmap with right directionCheck the sample >

If you would like to place some shapes to the left and some to the right, you can make use of the side attribute of the typeConfig object. The side attribute allows indicating which shapes to be drawn to the left and to the right of the root shape by specifying their ids:

const diagram = new dhx.Diagram(document.body, {
    type: "mindmap",
    typeConfig: {
        side: {
            left: ["2", "3"],
            right: ["4", "5"],
        }
    }
});
diagram.data.parse(data);

DHTMLX mindmap with left and right branchesCheck the sample >

When configuring a mind map, you can also decide which child shapes to show and which to hide. The open attribute shows child shapes of a particular parent shape being true by default. With the help of the openDir attribute you can specify more precisely whether to show child shapes to the left or right of the parent shape:

const data = [
    {
        "id": "1", "text": "49 emotions",
        "openDir": {
            left: true,
            right: false,
        }
    },
    { "id": "2", "text": "Positive and lively", "parent": "1" },
    { "id": "3", "text": "Quiet positive", "parent": "1" },
    { "id": "4", "text": "Caring", "parent": "1" },
    { "id": "5", "text": "Reactive", "parent": "1" },
];

Hiding mind map branches - DHTMLX Diagram

Custom Shapes in Mind Maps

The DHTMLX Diagram library makes it possible to mix various shapes in one diagram. Thus, you can create a mind map and add org chart shapes or any other diagram shapes into it. All you need to do is to specify the desired type of shape in the shape configuration object:

const data = [
    // create an "img-card" shape of Org Chart with the related configuration
    { id: "1", text: "Chairman & CEO", type: "img-card", img: "../avatar-06.jpg" },
    // create default "topic" shapes of Mind Map
    { id: "2", text: "Manager", parent: "1" },
    { id: "2.1", text: "Marketer", parent: "2" },
    { id: "2.2", text: "Team Lead ", parent: "2" },
    // more options
];
 
// initializing the mind map
const diagram = new dhx.Diagram(document.body, {
    type: "mindmap",
});
diagram.data.parse(data);

DHTMLX mixed mind map

You can also change the default type of shapes via the defaultShapeType configuration option of the diagram. The new default type will be applied to all shapes except the ones where another type is specified in the shape configuration object:

const diagram = new dhx.Diagram(document.body, {
    type: "mindmap",
    defaultShapeType: "rectangle"
});
 
const data = [
    { id: "1", text: "Chairman & CEO", type: "card" },    
    { id: "2", text: "Manager", parent: "1" },
    { id: "3", text: "Technical Director", parent: "1" },
    { id: "4", text: "CCO", parent: "1" },
    { id: "5", text: "Product Manager", parent: "1" }
];

DHTMLX mind map with rectangle shapes

Moreover, you can create an entirely custom mind map by adding custom shapes via the addShape() method and making them the default ones. In the example below, we have created a sitemap with landing page previews instead of topic shapes and custom HTML content inside shapes: icon, which opens a popup, icon with an embedded link to a landing page, and custom text, which appears when a user clicks on a shape:

const diagram = new dhx.Diagram(document.body, {
    type: "mindmap",
    // specifies the new shape type as a type for all shapes
    defaultShapeType: "flowView"
});
 
function template({ title, view, cr, br, conversion, link }){
    ...
}

function openModalInfo(title, text) {
     ...
}
 
diagram.addShape("flowView", {
    template: template,
    eventHandlers: {
        onclick: {
            info: function(event, item) {
                openModalInfo(item.title, item.info);
            }
        }
    }
});

const customShape = [
    // an appropriate data set
];
 
diagram.data.parse(customShape);

DHTMLX custom mind mapCheck the sample >

This custom mind map is available as a CSS template in the DHTMLX collection of templates.

Mind Map Editor

Together with the introduction of a brand-new diagram type DHTMLX Diagram receives a new editor specifically designed for working with mind maps. The mind map editor provides all the possibilities available in the diagram and org chart editors. It has two panels: one at the top and one to the right of the editing area.

DHTMLX mind map editorCheck the sample >

In order to create a mind map editor, you need to specify the editor type in the editor configuration object:

var editor = new dhx.DiagramEditor(document.body, {
    type: "mindmap"
});

A wide range of API properties enables you to configure the editor to meet your needs. You can manipulate editor controls and what’s more, customize the right panel to equip it with the necessary editing options. It may especially come in useful when you would like to edit a custom mind map like in the example below.
DHTMLX custom mind map editorCheck the sample >

Custom Per-Shape Toolbar in Editors

Starting with v3.1, you can customize a per-shape toolbar in all DHTMLX Diagram editors.

In the case of the mind map editor, the default toolbar consists of four controls for adding a new child shape, creating a new shape to the right of the root shape and to the left of the root shape, and removing a shape.

To make customization possible, we have added the shapeToolbar configuration property, which allows manipulating toolbar controls and creating custom ones. If this property is specified to true, the toolbar will contain all the default controls specific to the editor you work with. To modify the toolbar, you can include only those controls that you need via the shapeToolbar property. The order in which you specify the controls determines how they are displayed in the toolbar.

In the example below, we have left two controls in the toolbar: one for removing a shape and another for adding a shape.

const editor = new dhx.DiagramEditor(document.body, {
    type: "mindmap",
    shapeToolbar: ["remove", "add"]
});

DHTMLX mindmap toolbar

You can not only fine-tune the toolbar by rearranging or disabling some controls but also add custom ones. The best way to add a custom control to the toolbar is to enable the default configuration of the toolbar by specifying the shapeToolbar property to true and to set an icon object in the shapeToolbar array. The icon object contains the id of the icon and the HTML content of the icon:

const editor = new dhx.DiagramEditor(document.body, {
    type: "mindmap",
    shapeToolbar: [      
 true,
{ id: "download", content:"<i class='dxi dxi-download'></i>" }    
    ]
});

DHTMLX mindmap with custom toolbar

Thus, v3.1 gives you full control over the configuration of a per-shape toolbar in all editors (diagram, org chart, and mind map) and enables you to customize editors extensively.

Custom Event Handlers

From now on, DHTMLX Diagram is able to handle user interactions with custom shapes due to the ability to add custom event handlers. For that purpose, we have introduced the new eventHandlers attribute of the addShape() method.

In the example below, we add an event handler to listen to the clicks on the icon with the info class, after which a modal window opens:

diagram.addShape("template", {
    template: template,
    defaults: {
        height: 190,
        width: 97
    },
    eventHandlers: {
        onclick: {
            info: function(event, item) {
                openModalInfo(item.title, item.info);
            }
        }
    }
});

DHTMLX custom events in mindmapCheck the sample >

TypeScript Support

And the icing on the cake is TypeScript support provided by the DHTMLX Diagram library starting with v3.1. From now on, you can fall back on built-in type definitions and apply type suggestions, type checking, and autocompletion to speed up coding and make it clean and steady. Check the sample >

Other Features and Updates

The release brings out new events of the editor object: BeforeShapeIconClick and AfterShapeIconClick, BeforeShapeMove and AfterShapeMove. They serve to track such user actions as clicking per-shape toolbar controls and moving shapes. Learn more in the Diagram Editor API reference.

V3.1 also delivers the ability to control the CSS styles of diagrams when they are exported via the export service. From now on, you can disable the export of CSS styles or include only the styles you need to export them together with your diagram.

We aspire to provide you with the complete toolkit for creating mind maps and customizing them to fit your requirements. Feel free to send us your feedback as well as your questions if any arise.

We invite everyone to try out DHTMLX Diagram and mind mapping during a free 30-day trial period. Current clients may download the latest version in their Client’s Area.

Stay tuned!

Related Materials:

Advance your web development with DHTMLX

Gantt chart
Event calendar
Diagram library
30+ other JS components