windowsforms-devexpress-dot-xtratreemap-dot-itreemapcolorizer-dot-getitemcolor-x28-devexpress-dot-treemap-dot-itreemapitem-devexpress-dot-xtratreemap-dot-treemapitemgroupinfo-x29.md
Returns the color for the specified item with the specified tree location.
Namespace : DevExpress.XtraTreeMap
Assembly : DevExpress.XtraTreeMap.v25.2.dll
NuGet Package : DevExpress.TreeMap
Color GetItemColor(
ITreeMapItem item,
TreeMapItemGroupInfo group
)
Function GetItemColor(
item As ITreeMapItem,
group As TreeMapItemGroupInfo
) As Color
| 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.
|
| Type | Description |
|---|---|
| Color |
A Color value that is the color of the specified item.
|
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());
}
}
}
void ConfigureTreeMapColorizer() {
var colorizer = new CustomColorizer { Palette = Palette.Office2013Palette };
treeMap.Colorizer = colorizer;
}
Private Sub ConfigureTreeMapColorizer()
Dim colorizer = New CustomColorizer With {.Palette = Palette.Office2013Palette}
treeMap.Colorizer = colorizer
End Sub
Imports DevExpress.TreeMap
Imports DevExpress.XtraTreeMap
Imports System
Imports System.Drawing
Namespace CustomColorizerSample
Friend Class CustomColorizer
Implements ITreeMapColorizer
Private palette_Renamed As Palette = Palette.Office2016Palette
Public Property Palette() As Palette
Get
Return palette_Renamed
End Get
Set(ByVal value As Palette)
If palette_Renamed.Equals(value) Then
Return
End If
palette_Renamed = value
RaiseColorizerChanged()
End Set
End Property
Public Event ColorizerChanged As ColorizerChangedEventHandler Implements ITreeMapColorizer.ColorizerChanged
Public Function GetItemColor(ByVal item As ITreeMapItem, ByVal group As TreeMapItemGroupInfo) As Color Implements ITreeMapColorizer.GetItemColor
If item.Children.Count = 0 Then
Dim itemColor As Color = Palette(group.ItemIndex Mod Palette.Count)
Dim itemWeight As Double = (item.Value - group.MinValue) / (group.MaxValue - group.MinValue)
If Double.IsNaN(itemWeight) Then
itemWeight = 1
End If
Return Color.FromArgb(CInt((itemWeight * 255)), itemColor.R, itemColor.G, itemColor.B)
Else
Return Palette(Palette.Count - 1 - (group.GroupIndex + group.GroupLevel + group.ItemIndex) Mod Palette.Count)
End If
End Function
Private Sub RaiseColorizerChanged()
If ColorizerChangedEvent Is Nothing Then
Return
End If
ColorizerChangedEvent.Invoke(Me, New ColorizerChangedEventArgs())
End Sub
End Class
End Namespace
See Also