JavaScript/jQuery TreeMap Options

This section describes properties that configure the contents, behavior and appearance of the TreeMap UI component.

See Also

childrenField

Specifies the name of the data source field that provides nested items for a group. Applies to hierarchical data sources only.

Type:

String

Default Value: 'items'

In hierarchical data sources, objects normally have at least one nested array of objects. To specify the field providing this array, assign its name to the childrenField property. Such hierarchical objects will be visualized by groups of tiles.

See Also
  • dataSource - specifies the origin of data for the UI component.
  • valueField - specifies the data source field that provides values for tiles.
  • labelField - specifies the data source field that provides texts for tile and group labels.

colorField

Specifies the name of the data source field that provides colors for tiles.

Type:

String

Default Value: 'color'

There are several approaches to colorizing tiles.

  • Colorizing each tile uniquely into the color specified directly in the data object.
  • Colorizing tiles using the colorizer.
  • Specifying a single color for all tiles using the tile.color property.

You can use the first approach only if objects of your data source contain a field providing colors. If so, assign the name of this field to the colorField property. The colors must have one of the following formats:

This approach has the highest priority among the others. To get familiar with the other two approaches, see the colorizer and tile.color property descriptions.

colorizer

Manages the color settings.

Type:

Object

There are several approaches to colorizing tiles.

  • Colorizing each tile uniquely into the color specified directly in the data object.
  • Colorizing tiles using the colorizer.
  • Specifying a single color for all tiles using the tile.color property.

If for some reason you cannot use the first approach, colorize tiles using the colorizer object. It offers three colorization algorithms: "discrete", "gradient" and "range". For more information on how to use each algorithm, refer to the type property description.

To find out how else you can colorize tiles, see the colorField and tile.color property descriptions.

View Demo

dataSource

Binds the UI component to data.

Cannot be used in themes.

The TreeMap works with collections of objects.

Objects that have a plain structure are visualized by tiles. For example, the following array of objects produces four tiles:

let data = [
    { name: "Apples", value: 10 },
    { name: "Oranges", value: 13 },
    { name: "Cucumbers", value: 4 },
    { name: "Tomatoes", value: 8 }
];

Objects that have a hierarchical structure are visualized by groups of tiles. For example, the following array arranges the tiles from the previous code in two groups: "Fruits" and "Vegetables".

let data = [{
    name: "Fruits",
    items: [
        { name: "Apples", value: 10 },
        { name: "Oranges", value: 13 }
    ]
}, {
    name: "Vegetables",
    items: [
        { name: "Cucumbers", value: 4 },
        { name: "Tomatoes", value: 8 }
    ]
}];

View Demo

For both structures, set the valueField and labelField; for the hierarchical structure, also set the childrenField.

A plain data array can imply a hierarchical structure. An example of such array is given below. In this case, set the idField and parentField in addition to the valueField and labelField.

let data = [
    { id: 1, name: "Fruits"},
    { parent: 1, name: "Apples", value: 10 },
    { parent: 1, name: "Oranges", value: 13 },

    { id: 2, name: "Vegetables" },
    { parent: 2, name: "Cucumbers", value: 4 },
    { parent: 2, name: "Tomatoes", value: 8 }
];

let treeMapOptions = {
    // ...
    idField: "id",
    parentField: "parent"
};

View Demo

Depending on your data source, bind the TreeMap to data as follows.

  • Data Array
    Assign the array to the dataSource property.

  • Read-Only Data in JSON Format
    Set the dataSource property to the URL of a JSON file or service that returns JSON data.

  • OData
    Implement an ODataStore.

  • Web API, PHP, MongoDB
    Use one of the following extensions to enable the server to process data according to the protocol DevExtreme UI components use:

    Then, use the createStore method to configure access to the server on the client as shown below. This method is part of DevExtreme.AspNet.Data.

    jQuery
    JavaScript
    $(function() {
        let serviceUrl = "https://url/to/my/service";
        $("#treeMapContainer").dxTreeMap({
            // ...
            dataSource: DevExpress.data.AspNet.createStore({
                key: "ID",
                loadUrl: serviceUrl + "/GetAction"
            })
        })
    });
    Angular
    app.component.ts
    app.component.html
    app.module.ts
    import { Component } from '@angular/core';
    import CustomStore from 'devextreme/data/custom_store';
    import { createStore } from 'devextreme-aspnet-data-nojquery';
    
    @Component({
        selector: 'app-root',
        templateUrl: './app.component.html',
        styleUrls: ['./app.component.css']
    })
    export class AppComponent {
        store: CustomStore;
        constructor() {
            let serviceUrl = "https://url/to/my/service";
            this.store = createStore({
                key: "ID",
                loadUrl: serviceUrl + "/GetAction"
            })
        }
    }
    <dx-tree-map ...
        [dataSource]="store">
    </dx-tree-map>
    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { AppComponent } from './app.component';
    
    import { DxTreeMapModule } from 'devextreme-angular';
    
    @NgModule({
        declarations: [
            AppComponent
        ],
        imports: [
            BrowserModule,
            DxTreeMapModule
        ],
        providers: [],
        bootstrap: [AppComponent]
    })
    export class AppModule { }
    Vue
    App.vue
    <template> 
        <DxTreeMap ...
            :data-source="store" />
    </template>
    
    <script>
    import CustomStore from 'devextreme/data/custom_store';
    import { createStore } from 'devextreme-aspnet-data-nojquery';
    import { DxTreeMap } from 'devextreme-vue/tree-map';
    
    export default {
        components: {
            DxTreeMap
        },
        data() {
            const serviceUrl = "https://url/to/my/service";
            const store = createStore({
                key: "ID",
                loadUrl: serviceUrl + "/GetAction"
            });
            return {
                store
            }
        }
    }
    </script>
    React
    App.js
    import React from 'react';
    
    import CustomStore from 'devextreme/data/custom_store';
    import { createStore } from 'devextreme-aspnet-data-nojquery';
    import TreeMap from 'devextreme-react/tree-map';
    
    const serviceUrl = "https://url/to/my/service";
    const store = createStore({
        key: "ID",
        loadUrl: serviceUrl + "/GetAction"
    });
    
    class App extends React.Component {
        render() {
            return (
                <TreeMap ...
                    dataSource={store} />
            );
        }
    }
    export default App;
  • Any other data source
    Implement a CustomStore.

Regardless of the data source on the input, the TreeMap always wraps it in the DataSource object. This object allows you to sort, filter, group, and perform other data shaping operations. To get its instance, call the getDataSource() method.

NOTE

Review the following notes about data binding:

  • Data field names cannot be equal to this and should not contain the following characters: ., :, [, and ].

  • The stores and DataSource have methods to process and update data. However, the methods do not allow you to perform particular tasks (for example, replace the entire dataset, reconfigure data access at runtime). For such tasks, create a new array, store, or DataSource and assign it to the dataSource property as shown in the articles about changing properties in jQuery, Angular, React, and Vue.

disabled

Specifies whether the UI component responds to user interaction.

Type:

Boolean

Default Value: false
Cannot be used in themes.

elementAttr

Specifies the global attributes to be attached to the UI component's container element.

Type: any
Default Value: {}

jQuery
$(function(){
    $("#treeMapContainer").dxTreeMap({
        // ...
        elementAttr: {
            id: "elementId",
            class: "class-name"
        }
    });
});
Angular
HTML
TypeScript
<dx-tree-map ...
    [elementAttr]="{ id: 'elementId', class: 'class-name' }">
</dx-tree-map>
import { DxTreeMapModule } from "devextreme-angular";
// ...
export class AppComponent {
    // ...
}
@NgModule({
    imports: [
        // ...
        DxTreeMapModule
    ],
    // ...
})
Vue
App.vue
<template>
    <DxTreeMap ...
        :element-attr="treeMapAttributes">
    </DxTreeMap>
</template>

<script>
import DxTreeMap from 'devextreme-vue/tree-map';

export default {
    components: {
        DxTreeMap
    },
    data() {
        return {
            treeMapAttributes: {
                id: 'elementId',
                class: 'class-name'
            }
        }
    }
}
</script>
React
App.js
import React from 'react';

import TreeMap from 'devextreme-react/tree-map';

class App extends React.Component {
    treeMapAttributes = {
        id: 'elementId',
        class: 'class-name'
    }

    render() {
        return (
            <TreeMap ...
                elementAttr={this.treeMapAttributes}>
            </TreeMap>
        );
    }
}
export default App;

export

Configures the exporting and printing features.

Type:

Object

These features allow a user to export your UI component into a document or print it. When exporting is enabled, the "Exporting/Printing" button appears in the UI component. A click on it invokes a drop-down menu that lists exporting and printing commands. The following formats are supported for exporting into: PNG, PDF, JPEG, SVG and GIF.

See Also

group

Configures groups.

Type:

Object

A group is an element that collects several tiles in it. In terms of data, it is a node that has children in the current context. Groups appear only if the data source implies a hierarchical structure.

The following list provides an overview of group features that you can configure using the group object.

  • Labels
    Each group is identified by a label. Its appearance can be changed using the fields of the label object. If the group's width is too small, the label will be hidden.
  • Headers' Height
    Group headers contain labels. To specify the height of the group headers, use the headerHeight property.
  • Color
    There are several approaches to colorizing the group headers. Refer to the color property description to find information about all of them.
  • Hover and Selection Styles
    A group can be in the hover or selected state. In these states, its style changes to the one specified by the hoverStyle or selectionStyle object respectively. A group can also enter the hover or selected state when a nested tile enters it. To enable this feature, assign true to the interactWithGroup property of the root configuration object.
  • Border's Appearance
    Specify the fields of the border object to configure group borders.

An object assigned to the group field configures all groups in the UI component. To customize a specific group, pass a similar object to the customize(options) method of the node represented by the group.

hoverEnabled

Specifies whether tiles and groups change their style when a user pauses on them.

Type:

Boolean

Default Value: undefined

NOTE
When the user pauses on a group, not only the group changes its style, but also tiles that belong to that group. However, the isHovered() method, which checks the tiles' state, will return false although visually they have entered the hover state.
See Also

idField

Specifies the name of the data source field that provides IDs for items. Applies to plain data sources only.

Type:

String

Default Value: undefined

In certain cases, you may have a plain data source that implies a hierarchical structure. For example, the following code declares a data source that, despite being plain, can be rearranged into a hierarchy of two groups with two items in each.

JavaScript
var treeMapOptions = {
    // ...
    dataSource: [
        // Group 1
        { id: 1, name: 'Fruits'},
        { parent: 1, name: 'Apples', value: 10 },
        { parent: 1, name: 'Oranges', value: 13 },

        // Group 2
        { id: 2, name: 'Vegetables' },
        { parent: 2, name: 'Cucumbers', value: 4 },
        { parent: 2, name: 'Tomatoes', value: 8 }
    ]
};

Note that in this data source, objects that have children have the "id" field whose value is unique. Their children have the "parent" field pointing at the parent's ID. The "id" and "parent" fields can have other names, but in any case, they must be assigned to the idField and parentField properties.

JavaScript
var treeMapOptions = {
    // ...
    idField: 'id',
    parentField: 'parent'
};

View Demo

interactWithGroup

Specifies whether the user will interact with a single tile or its group.

Type:

Boolean

Default Value: false

By default, the click, hoverChanged and selectionChanged events are fired for the tile that has been clicked, paused on or selected. If you need these events to be passed on to the parent group of the tile, set the interactWithGroup property to true. This setting impacts appearance as well. For example, when the user pauses on a tile, the whole group to which the tile belongs will apply the hover style.

labelField

Specifies the name of the data source field that provides texts for tile and group labels.

Type:

String

Default Value: 'name'

Each tile or group of tiles is accompanied by a text label. Usually, a label displays the name of the tile or the group. However, you can put any desired text into it. For this purpose, call the label(label) method of the node whose label must be changed. You can call this method, for example, when all nodes are initialized or when they are being rendered.

If you need to change the appearance of all labels, use the tile.label and group.label objects. To change the appearance of a particular label, use the customize(options) function of the node to which the label belongs.

See Also
  • dataSource - specifies the origin of data for the UI component.
  • valueField - specifies the data source field that provides values for tiles.
  • childrenField - specifies the data source field that provides nested items for a group.

layoutAlgorithm

Specifies the layout algorithm.

Type:

String

|

Function

Function parameters:
e:

Object

Data for implementing a custom layout algorithm.

Object structure:
Name Type Description
items

Array<any>

A set of items to distribute. Each object in this array contains the value and rect fields.
By default, rect is undefined. It must be assigned an array of the following format: [x1, y1, x2, y2], where (x1, y1) and (x2, y2) are coordinates of two diagonally-opposite points defining a rectangle.

rect

Array<Number>

The rectangle available for subdivision.
Contains the X and Y coordinates of two diagonally-opposite points in the following format: [x1, y1, x2, y2].

sum

Number

The sum total value of all nodes on the current level.

Default Value: 'squarified'
Accepted Values: 'sliceanddice' | 'squarified' | 'strip'

Layout algorithms determine the position and size of tiles and groups. Therefore, the chosen algorithm plays the definitive role in the resulting look of the UI component. TreeMap provides the following algorithms out of the box.

  • Squarified
    This algorithm lays the items out so that the aspect ratio will be closer to 1. In other words, this algorithm tries to make items as square as possible.

    For more information about this algorithm, refer to the Squarified Treemaps paper.

  • Strip
    This algorithm is a modification of the "Squarified" algorithm. At the beginning, the algorithm has an available area divided into several strips and a set of items to distribute between the strips. Throughout the layout process, a current strip is maintained. For each item to be arranged, the algorithm checks whether or not adding the item to the current strip improves the average aspect ratios of the rectangles in the current strip. If so, the item is added to the current strip. Otherwise, it is added to the next strip.

    The direction of the strips depends on the size of the available area. If the width is greater than the height, the strips are lined up horizontally. If vice versa, vertically.

    For more information on this algorithm, see the Ordered and Quantum Treemaps: Making Effective Use of 2D Space to Display Hierarchies paper.

  • Slice and Dice
    This algorithm uses parallel lines to divide an available area into rectangles representing items. In case of a hierarchical structure, each rectangle representing an item is divided once more into smaller rectangles representing its children, and so on.

    To learn more about this algorithm, refer to the Tree Visualization with Tree-Maps: a 2D Space-Filling Approach paper.

DevExpress DevExtreme HTML5 TreeMap Squarified SliceAndDice Strip

If none of the predefined algorithms satisfy your needs, implement your own algorithm. For this purpose, assign a function to the layoutAlgorithm property. Basically, this function should calculate the coordinates of two diagonally-opposite points defining a rectangle and assign them to the needed item. To access a set of items to distribute, use the items field of the function's parameter. All available fields of the parameter are listed in the header of this description.

JavaScript
var treeMapOptions = {
    // ...
    layoutAlgorithm: function (e) {
        // ...
        e.items.forEach(function(item) {
            // ...
            // Calculating the rectangle for the current item here
            // ...
            item.rect = rectPoints;
        });
    }
};

In addition, you can change the layout direction. For this purpose, use the layoutDirection property.

View Demo

layoutDirection

Specifies the direction in which the items will be laid out.

Type:

String

Default Value: 'leftTopRightBottom'
Accepted Values: 'leftBottomRightTop' | 'leftTopRightBottom' | 'rightBottomLeftTop' | 'rightTopLeftBottom'

The value of this property determines the start and end point of the layout. See the image below to spot the difference between the available layout directions.

DevExpress DevExtreme HTML5 TreeMap LayoutDirection

NOTE
If you use a custom layout algorithm, this property will be ignored.

loadingIndicator

Configures the loading indicator.

Type:

Object

When the UI component is bound to a remote data source, it can display a loading indicator while data is loading.

DevExtreme Charts - Loading indicator

To enable the automatic loading indicator, set the enabled property to true.

If you want to change the loading indicator's visibility, use the show property or the showLoadingIndicator() and hideLoadingIndicator() methods.

maxDepth

Specifies how many hierarchical levels must be visualized.

Type:

Number

Default Value: undefined

If you have a structure with deep nesting level, displaying all levels at once produces visual clutter. To reduce it, specify the number of levels that can be visualized at a time using the maxDepth property.

DevExpress DevExtreme HTML5 TreeMap

When you set this property, data that occupies the lowest levels may become unavailable to the user. For such cases, implement the drill down feature.

onClick

A function that is executed when a node is clicked or tapped.

Type:

Function

|

String

Function parameters:
e:

Object

Information about the event.

Object structure:
Name Type Description
component

TreeMap

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

event

Event (jQuery or EventObject)

The event that caused the function to execute. It is an EventObject or a jQuery.Event when you use jQuery.

model any

The model data. Available only if you use Knockout.

node

TreeMap Node

The clicked node; described in the Node section.

Default Value: null
Cannot be used in themes.

This function is often used to implement item selection as shown in the following code:

jQuery
JavaScript
$(function () {
    $("#treeMapContainer").dxTreeMap({
        // ...
        onClick: function (e) {
            e.node.select(!e.node.isSelected());
        }
    });
});
Angular
HTML
TypeScript
<dx-tree-map ...
    (onClick)="selectItem($event)">
</dx-tree-map>
import { DxTreeMapModule } from "devextreme-angular";
// ...
export class AppComponent {
    selectItem (e) {
        e.node.select(!e.node.isSelected());
    }
}
@NgModule({
    imports: [
        // ...
        DxTreeMapModule
    ],
    // ...
})
Vue
App.vue
<template>
    <DxTreeMap ...
        @click="selectItem">
    </DxTreeMap>
</template>

<script>
import DxTreeMap from 'devextreme-vue/tree-map';

export default {
    components: {
        DxTreeMap
    },
    methods: {
        selectItem (e) {
            e.node.select(!e.node.isSelected())
        }
    }
}
</script>
React
App.js
import React from 'react';

import TreeMap from 'devextreme-react/tree-map';

class App extends React.Component {
    render() {
        return (
            <TreeMap ...
                onClick={this.selectItem}>
            </TreeMap>
        );
    }

    selectItem (e) {
        e.node.select(!e.node.isSelected())
    }
}

export default App;

To identify whether the clicked node is a single tile or a group of tiles, use the node's isLeaf() method.

onDisposing

A function that is executed before the UI component is disposed of.

Type:

Function

Function parameters:
e:

Object

Information about the event.

Object structure:
Name Type Description
component

TreeMap

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

model any

Model data. Available only if you use Knockout.

Default Value: null

onDrawn

A function that is executed when the UI component's rendering has finished.

Type:

Function

Function parameters:
e:

Object

Information about the event.

Object structure:
Name Type Description
component

TreeMap

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

model any

The model data. Available only if you use Knockout.

Default Value: null
Cannot be used in themes.

onDrill

A function that is executed when a user drills up or down.

Type:

Function

Function parameters:
e:

Object

Information about the event.

Object structure:
Name Type Description
component

TreeMap

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

model any

The model data. Available only if you use Knockout.

node

TreeMap Node

The Node object.

Default Value: null
Cannot be used in themes.

Although not provided out-of-the-box, the drill down capability is easy to implement using the API methods. Learn how to do this from the drillDown() method description.

View Demo

onExported

A function that is executed after the UI component is exported.

Type:

Function

Function parameters:
e:

Object

Information about the event.

Object structure:
Name Type Description
component

TreeMap

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

model any

The model data. Available only if you use Knockout.

Default Value: null

onExporting

A function that is executed before the UI component is exported.

Type:

Function

Function parameters:
e:

Object

Information about the event.

Object structure:
Name Type Description
cancel

Boolean

Allows you to prevent exporting.

component

TreeMap

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

fileName

String

The name of the file to which the UI component is about to be exported.

format

String

The resulting file format. One of PNG, PDF, JPEG, SVG and GIF.

model any

The model data. Available only if you use Knockout.

Default Value: null

onFileSaving

A function that is executed before a file with exported UI component is saved to the user's local storage.

Type:

Function

Function parameters:
e:

Object

Information about the event.

Object structure:
Name Type Description
cancel

Boolean

Allows you to prevent file saving.

component

TreeMap

The UI component's instance.

data

BLOB

Exported data as a BLOB.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

fileName

String

The name of the file to be saved.

format

String

The format of the file to be saved.
Possible Values: 'PNG' | 'PDF' | 'JPEG' | 'SVG' | 'GIF'

Default Value: null

onHoverChanged

A function that is executed after the pointer enters or leaves a node.

Type:

Function

Function parameters:
e:

Object

Information about the event.

Object structure:
Name Type Description
component

TreeMap

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

model any

The model data. Available only if you use Knockout.

node

TreeMap Node

The node whose hover state has been changed; described in the Node section.

Default Value: null
Cannot be used in themes.

To identify whether the pointer has entered or left the node, call the node's isHovered() method. To identify whether the node is a single tile or a group of tiles, use the node's isLeaf() method.

onIncidentOccurred

A function that is executed when an error or warning occurs.

Type:

Function

Function parameters:
e:

Object

Information about the event.

Object structure:
Name Type Description
component

TreeMap

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

model any

The model data. Available only if you use Knockout.

target any

Information on the occurred incident.

Default Value: null

The UI component notifies you of errors and warnings by passing messages to the browser console. Each message contains the incident's ID, a brief description, and a link to the Errors and Warnings section where further information about this incident can be found.

The onIncidentOccurred function allows you to handle errors and warnings the way you require. The object passed to it contains the target field. This field provides information about the occurred incident and contains the following properties:

  • id
    The incident's ID. The full list of IDs can be found in the Errors and Warnings section.
  • type
    The incident's type: "error" or "warning".
  • args
    The argument of the incident's message. Depends on the incident. For example, it may be the name of the data source field that was specified incorrectly, or the name of the property that was not set properly.
  • text
    The text passed to the browser's console. Includes the args content, if there is any.
  • widget
    The name of the UI component that produced the error or warning.
  • version
    The used DevExtreme version.

onInitialized

A function used in JavaScript frameworks to save the UI component instance.

Type:

Function

Function parameters:
e:

Object

Information about the event.

Object structure:
Name Type Description
component

TreeMap

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

Default Value: null

See Also

onNodesInitialized

A function that is executed only once, after the nodes are initialized.

Type:

Function

Function parameters:
e:

Object

Information about the event.

Object structure:
Name Type Description
component

TreeMap

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

model any

The model data. Available only if you use Knockout.

root

TreeMap Node

The root node; described in the Node section.

Default Value: null
Cannot be used in themes.

Use this function to change the node structure. The root node is available via the root field of the function's parameter. Using the root node's getAllNodes(), getAllChildren() and getChild(index) methods, you can access any other node.

onNodesRendering

A function that is executed before the nodes are displayed and each time the collection of active nodes is changed.

Type:

Function

Function parameters:
e:

Object

Information about the event.

Object structure:
Name Type Description
component

TreeMap

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

model any

The model data. Available only if you use Knockout.

node

TreeMap Node

In most cases, the root node. When drilling down, the node of the highest displayed level.
Described in the Node section.

Default Value: null
Cannot be used in themes.

onOptionChanged

A function that is executed after a UI component property is changed.

Type:

Function

Function parameters:
e:

Object

Information about the event.

Object structure:
Name Type Description
model any

Model data. Available only if you use Knockout.

fullName

String

The path to the modified property that includes all parent properties.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

component

TreeMap

The UI component's instance.

name

String

The modified property if it belongs to the first level. Otherwise, the first-level property it is nested into.

value any

The modified property's new value.

Default Value: null

The following example shows how to subscribe to component property changes:

jQuery
index.js
$(function() {
    $("#treeMapContainer").dxTreeMap({
        // ...
        onOptionChanged: function(e) {
            if(e.name === "changedProperty") {
                // handle the property change here
            }
        }
    });
});
Angular
app.component.html
app.component.ts
app.module.ts
<dx-tree-map ...
    (onOptionChanged)="handlePropertyChange($event)"> 
</dx-tree-map>
import { Component } from '@angular/core'; 

@Component({ 
    selector: 'app-root', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'] 
}) 

export class AppComponent { 
    // ...
    handlePropertyChange(e) {
        if(e.name === "changedProperty") { 
            // handle the property change here
        }
    }
}
import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule } from '@angular/core'; 
import { AppComponent } from './app.component'; 
import { DxTreeMapModule } from 'devextreme-angular'; 

@NgModule({ 
    declarations: [ 
        AppComponent 
    ], 
    imports: [ 
        BrowserModule, 
        DxTreeMapModule 
    ], 
    providers: [ ], 
    bootstrap: [AppComponent] 
}) 

export class AppModule { }  
Vue
App.vue
<template> 
    <DxTreeMap ...
        @option-changed="handlePropertyChange"
    />            
</template> 

<script>  
import 'devextreme/dist/css/dx.light.css'; 
import DxTreeMap from 'devextreme-vue/tree-map'; 

export default { 
    components: { 
        DxTreeMap
    }, 
    // ...
    methods: { 
        handlePropertyChange: function(e) {
            if(e.name === "changedProperty") {
                // handle the property change here
            }
        }
    } 
} 
</script> 
React
App.js
import React from 'react';  
import 'devextreme/dist/css/dx.light.css'; 

import TreeMap from 'devextreme-react/tree-map'; 

const handlePropertyChange = (e) => {
    if(e.name === "changedProperty") {
        // handle the property change here
    }
}

export default function App() { 
    return ( 
        <TreeMap ...
            onOptionChanged={handlePropertyChange}
        />        
    ); 
} 

onSelectionChanged

A function that is executed when a node is selected or selection is canceled.

Type:

Function

Function parameters:
e:

Object

Information about the event.

Object structure:
Name Type Description
component

TreeMap

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

model any

The model data. Available only if you use Knockout.

node

TreeMap Node

The node whose selection state has been changed; described in the Node section.

Default Value: null
Cannot be used in themes.

To identify whether the selection has been applied or canceled, call the node's isSelected() method. To identify whether the clicked node is a single tile or a group of tiles, use the node's isLeaf() method.

parentField

Specifies the name of the data source field that provides parent IDs for items. Applies to plain data sources only.

Type:

String

Default Value: undefined

In certain cases, you may have a plain data source that implies a hierarchical structure. For example, the following code declares a data source that, despite being plain, can be rearranged into a hierarchy of two groups with two items in each.

JavaScript
var treeMapOptions = {
    // ...
    dataSource: [
        // Group 1
        { id: 1, name: 'Fruits'},
        { parent: 1, name: 'Apples', value: 10 },
        { parent: 1, name: 'Oranges', value: 13 },

        // Group 2
        { id: 2, name: 'Vegetables' },
        { parent: 2, name: 'Cucumbers', value: 4 },
        { parent: 2, name: 'Tomatoes', value: 8 }
    ]
};

Note that in this data source, objects that have children have the "id" field whose value is unique. Their children have the "parent" field pointing at the parent's ID. The "id" and "parent" fields can have other names, but in any case they must be assigned to the idField and parentField properties.

JavaScript
var treeMapOptions = {
    // ...
    idField: 'id',
    parentField: 'parent'
};

View Demo

pathModified

Notifies the UI component that it is embedded into an HTML page that uses a tag modifying the path.

Type:

Boolean

Default Value: false
Cannot be used in themes.

If you place the UI component on a page that uses a tag modifying the path (<base>, <iframe>, etc.), some of the UI component elements may get mixed up or disappear. To solve this problem, set the pathModified property to true.

See Also

redrawOnResize

Specifies whether to redraw the UI component when the size of the parent browser window changes or a mobile device rotates.

Type:

Boolean

Default Value: true
Cannot be used in themes.

When this property is set to true, the UI component will be redrawn automatically in case the size of its parent window changes.

NOTE
To redraw the UI component after the size of its container has changed, call the render() method of the UI component's instance.

rtlEnabled

Switches the UI component to a right-to-left representation.

Type:

Boolean

Default Value: false
Cannot be used in themes.

When this property is set to true, the UI component text flows from right to left, and the layout of elements is reversed. To switch the entire application/site to the right-to-left representation, assign true to the rtlEnabled field of the object passed to the DevExpress.config(config) method.

JavaScript
DevExpress.config({
    rtlEnabled: true
});
NOTE
In a right-to-left representation, SVG elements have the direction attribute with the rtl value. This might cause problems when rendering left-to-right texts. Use this property if you have only right-to-left texts.

selectionMode

Specifies whether a single or multiple nodes can be in the selected state simultaneously.

Type:

String

Default Value: undefined
Accepted Values: 'multiple' | 'none' | 'single'

In a single mode, only one node can be in the selected state at one moment. When the user selects another node, the formerly selected node becomes unselected. In a multiple mode, any number of nodes can be in the selected state.

To implement selection, assign the following or similar callback function to the onClick property.

JavaScript
var treeMapOptions = {
    // ...
    onClick: function (e) {
        e.node.select(!e.node.isSelected());
    }    
};

When entering the selected state, a tile or a group of tiles changes its appearance. You can configure it using the group | selectionStyle and tile.selectionStyle objects.

To control the selection feature in code, use the isSelected, select(state) and clearSelection() methods. In addition, you can perform certain actions when a node enters/leaves the selected state. For this purpose, implement the onSelectionChanged event handler.

size

Specifies the UI component's size in pixels.

Type:

Object

Default Value: undefined

The UI component occupies its container's entire area by default. Use the size object to specify the UI component's size if it should be different from that of its container. Assign 0 to size object's height and width properties to hide the UI component.

jQuery
index.js
$(function() {
    $("#treeMapContainer").dxTreeMap({
        // ...
        size: {
            height: 300,
            width: 600
        }
    });
});
Angular
app.component.html
app.component.ts
app.module.ts
<dx-tree-map ... >
    <dxo-size
        [height]="300"
        [width]="600">
    </dxo-size>
</dx-tree-map>
import { Component } from '@angular/core';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    // ...
}
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';

import { DxTreeMapModule } from 'devextreme-angular';

@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule,
        DxTreeMapModule
    ],
    providers: [ ],
    bootstrap: [AppComponent]
})
export class AppModule { }
Vue
App.vue
<template>
    <DxTreeMap ... >
        <DxSize
            :height="300"
            :width="600"
        />
    </DxTreeMap>
</template>

<script>

import DxTreeMap, {
    DxSize
} from 'devextreme-vue/tree-map';

export default {
    components: {
        DxTreeMap,
        DxSize
    },
    // ...
}
</script>
React
App.js
import React from 'react';

import TreeMap, {
    Size
} from 'devextreme-react/tree-map';

class App extends React.Component {
    render() {
        return (
            <TreeMap ... >
                <Size
                    height={300}
                    width={600}
                />
            </TreeMap>
        );
    }
}
export default App;

Alternatively, you can style the UI component's container using CSS:

jQuery
index.js
styles.css
$(function() {
    $("#treeMap").dxTreeMap({
        // ...
    });
});
#treeMap {
    width: 85%;
    height: 70%;
}
Angular
app.component.html
app.styles.css
<dx-tree-map ...
    id="treeMap">
</dx-tree-map>
#treeMap {
    width: 85%;
    height: 70%;
}
Vue
App.vue
<template>
    <DxTreeMap ...
        id="treeMap">
    </DxTreeMap>
</template>

<script>
import DxTreeMap from 'devextreme-vue/tree-map';

export default {
    components: {
        DxTreeMap
    },
    // ...
}
</script>

<style>
#treeMap {
    width: 85%;
    height: 70%;
}
</style>
React
App.js
styles.css
import React from 'react';

import TreeMap from 'devextreme-react/tree-map';

class App extends React.Component {
    render() {
        return (
            <TreeMap ...
                id="treeMap">
            </TreeMap>
        );
    }
}
export default App;
#treeMap {
    width: 85%;
    height: 70%;
}

theme

Sets the name of the theme the UI component uses.

Type:

String

Default Value: 'generic.light'
Accepted Values: 'generic.dark' | 'generic.light' | 'generic.contrast' | 'generic.carmine' | 'generic.darkmoon' | 'generic.darkviolet' | 'generic.greenmist' | 'generic.softblue' | 'material.blue.light' | 'material.lime.light' | 'material.orange.light' | 'material.purple.light' | 'material.teal.light'

A theme is a UI component configuration that gives the UI component a distinctive appearance. You can use one of the predefined themes or create a custom one. Changing the property values in the UI component's configuration object overrides the theme's corresponding values.

tile

Configures tiles.

Type:

Object

A tile is a rectangle representing a node that has no children in the current context. Several tiles can be collected into a group if the data source implies a hierarchical structure.

The following list provides an overview of tiles' features that you can configure using the tile object.

  • Labels
    Each tile is identified by a label. Its appearance can be changed using the fields of the label object. If the tile's area is too small, the label will be hidden.
  • Color
    There are several approaches to colorizing the tiles. Refer to the color property description to find information about all of them.
  • Hover and Selection Styles
    A tile can be in the hover or selected state. In these states, its style changes to the one specified by the hoverStyle or selectionStyle object respectively. Along with the tile, its parent group can enter the hover or selected state. To enable this feature, assign true to the interactWithGroup property of the root configuration object.
  • Border's Appearance
    Specify the fields of the border object to configure the tile borders.

An object assigned to the tile field configures all tiles in the UI component. To customize a specific tile, pass a similar object to the customize(options) method of the node represented by the tile.

title

Configures the UI component's title.

Type:

Object

|

String

The UI component's title is a short text that usually indicates what is visualized. If you need to specify the title's text only, assign it directly to the title property. Otherwise, set this property to an object with the text and other fields specified.

The title can be accompanied by a subtitle elaborating on the visualized subject using the title.subtitle object.

tooltip

Configures tooltips - small pop-up rectangles that display information about a data-visualizing UI component element being pressed or hovered over with the mouse pointer.

Type:

Object

valueField

Specifies the name of the data source field that provides values for tiles.

Type:

String

Default Value: 'value'

See Also
  • dataSource - specifies the origin of data for the UI component.
  • childrenField - specifies the data source field that provides nested items for a group.
  • labelField - specifies the data source field that provides texts for tile and group labels.