Skip to main content

ITreeMapColorizer.GetItemColor(ITreeMapItem, TreeMapItemGroupInfo) Method

Returns the color for the specified item with the specified tree location.

Namespace: DevExpress.XtraTreeMap

Assembly: DevExpress.XtraTreeMap.v24.1.dll

NuGet Package: DevExpress.TreeMap

Declaration

Color GetItemColor(
    ITreeMapItem item,
    TreeMapItemGroupInfo group
)

Parameters

Name Type Description
item ITreeMapItem

An object of a class implementing the ITreeMapItem interface. It is the object for which the color is obtained.

group TreeMapItemGroupInfo

A TreeMapItemGroupInfo value specifying information about the item position in a group.

Returns

Type Description
Color

A Color value that is the color of the specified item.

Example

To implement a custom colorizer, design a class implementing the ITreeMapColorizer interface and implement the interface ITreeMapColorizer.GetItemColor method. After that, an instance of the class can be assigned to the TreeMapControl.Colorizer property.

using DevExpress.TreeMap;
using DevExpress.XtraTreeMap;
using System;
using System.Drawing;

namespace CustomColorizerSample {
    class CustomColorizer : ITreeMapColorizer {
        Palette palette = Palette.Office2016Palette;

        public Palette Palette {
            get { return palette; }
            set {
                if(palette.Equals(value)) return;
                palette = value;
                RaiseColorizerChanged();
            }
        }

        public event ColorizerChangedEventHandler ColorizerChanged;

        public Color GetItemColor(ITreeMapItem item, TreeMapItemGroupInfo group) {
            if(item.Children.Count == 0) {
                Color itemColor = Palette[group.ItemIndex % Palette.Count];
                double itemWeight = (item.Value - group.MinValue) / (group.MaxValue - group.MinValue);
                if(Double.IsNaN(itemWeight)) itemWeight = 1;

                return Color.FromArgb(
                    (int)(itemWeight * 255),
                    itemColor.R,
                    itemColor.G,
                    itemColor.B
                );
            }
            else
                return Palette[Palette.Count - 1 - (group.GroupIndex + group.GroupLevel + group.ItemIndex) % Palette.Count];

        }

        void RaiseColorizerChanged() {
            if(ColorizerChanged == null) return;
            ColorizerChanged.Invoke(this, new ColorizerChangedEventArgs());
        }
    }
}
See Also