Treemaps are space-filling visualizations of hierarchical data. Each node in the Treemap is represented as a rectangle, whose size depends on some attribute of the data. For example, if I am representing the high-volume trades in a day, I could have a Treemap that shows different sized rectangles based on the volume of each trade. Larger rectangles will represent the large trades and smaller rectangles, the not so large trades. The most popular of the treemap implementations use a squarified treemap algorithm that produces more squarish rectangles, resulting in better aspect ratios.
In my current SilverLight project we required a variety of features that were not present in any of the online implementations. Features like multi-level treemaps, zooming, progressive reveal of information, selection events, filtering, dynamic views, etc were something we found missing in existing implementations. We wanted a single control that had all of these features. Instead of starting from scratch we took inspiration from the following places:
A new custom control: TreeMapView
TreeMapView is the custom control I built that has many of the features mentioned earlier. Its built in SilverLight 3 and as expected does a lot of stuff via data-binding. It uses Visual State Manager (VSM) extensively for showing state changes and animating transitions. Some of the common features include:
Multi-level hierarchies: It can represent multiple levels of hierarchy, so you can visualize treemaps within treemaps! The figure below shows three levels of treemaps.
Fine grained styling: One can style the root nodes, internal nodes and leaf nodes separately. It is very common to use a different style for the root level nodes, since you want them to stand out when you first see the map. Similarly, the leaf nodes require special visual treatment which is supported.
Drill downs: It is impossible to show every level legibly in one view but drill-downs make this easier. You can click and go deeper into the hierarchy and see more detail as you drill in. This is the notion of progressive reveal, which is taken care using special states. You can style the progressive reveal using VSM, giving you have complete power in choosing how and what to style and show (reveal).
Breadcrumb trail: The breadcrumb trail is useful when you are doing drill downs. The TreeMapView publishes a list of items indicating the path along a subtree. This path changes as you drill in/out. You can style this path and provide navigation support for your drill downs.
Filters: When viewing large datasets, filters make it easier to hone into the stuff you are interested. Again, the filtered state of the treemap can by stylized using VSM. The figure below shows one possible way of styling filtered items. Colored items are the ones that match the criteria.
Dynamic views: A treemap sizes the boxes based on some attribute of the data. You can change this attribute on the fly (by bindings) and see different views of the data. Quickly switching between different views gives you a better perspective of the kind of the data you are visualizing.
Coloring the tiles: This is a primary requirement of any treemap control. The color of a box indicates the weight of some attribute. You have complete control over this using bindings and converters. You can bind to the attribute you want to use for coloring the tile and use a converter to provide the different colors.
Virtualization: As you start visualizing large datasets, you cannot afford to create controls for every item. Virtualization helps in reducing the number of controls and improves the performance for this scenario. Since custom virtualization is not supported natively in SilverLight, I had to write my own version based on my experience with WPF. In principle it is similar to Deep Zoom.
Mouse hovers: Hovers can be styled using ToolTips
Selections: You can click a tile to select it, which automatically updates the SelectedItem property and also raises the SelectionChanged event. Selections can be styled via VSM.
Usage
The programming model is fairly straightforward and using it is also simple. Here is a Xaml snippet that shows the usage:
<Controls1:TreeMapView x:Name="TM" Controls:DockPanel.Dock="Left" SizeBinding="{Binding Quantity}" HeaderBinding="{Binding Name}" ColorBinding="{Binding Status, Converter={StaticResource Converter}}" ItemsSource="{Binding Traders}" ChildItemsSourceBinding="{Binding ChildTraders}" ItemStyle="{StaticResource DefaultItemStyle}" ContainerStyle="{StaticResource DefaultItemStyle}" RootContainerStyle="{StaticResource DefaultItemStyle}" />
The TreeMapView creates instances of TreeMapTile for each item in a level. TreeMapTiles can contain child tiles to give you the nested view. The ChildItemsSourceBinding property of the TreeMapView can be used to create nested levels. SizeBinding is used to size the tiles and ColorBinding determines the color of each tile. Typically you would use the ColorBinding with a converter to map the data to a brush. ItemStyle is the style used for leaf tiles. ContainerStyle is for internal nodes and RootContainerStyle is for the top level tiles.
Video
Here is a quick video showing all of these features in action:

Hello and thanks – this is looking great. Is there any chance that you will port this to WPF?
Good job. Will you publish the control source?
@Herba I tried to build it in a way so that it can be consumed in both WPF and SilverLight. The only catch is that you need to reference the WPF Toolkit for the VisualStateManager
@Marcos I am not sure how soon I can publish the source. It still needs some performance tuning and some refactoring. I’ll let you know on this blog
[...] A treemap is an increasingly popular control for displaying trends in data because you can put a lot of information in a small space and still make it relatively easily understood. There are nice write-ups of the treemap here and here [...]
Do you plan to post the source code?
does your book discuss binding to hierarchicaldatatemplate to visually create different tree representations visually (not just treeview)?
below i present 2 different scenarios …
—————
Example: leopard-desktop-stack
http://appledifferent.com/wordpress/wp-content/leopard-desktop-stack.jpg
what would be the pseudo code/approach to create this? Would this all be done with styles?
another use case:
codeproject has this article:
http://www.codeproject.com/KB/WPF/LayeredTreeDraw.aspx?msg=2956342
except i want my model not have to inherit from his node objects.
I could actually use that control for a tool i’m building:
http://www.robusthaven.com/data/products/npeg/npeg-ide.jpg
parse tree renders in a treeview using:
<HierarchicalDataTemplate DataType="{x:Type model:ParseTreeElement}" ItemsSource="{Binding Path=Children}">
<ContentPresenter Grid.Row="1" Content="{Binding Path=Expression}" Margin="5,0,0,0" />
</HierarchicalDataTemplate>
however the real power of wpf would come when i show a directed graph control of the parse tree (step 1).
Should i inherit from treeview or create a custom directedgraphpanel?
I don’t want to do this all with styles. Instead, I want to use standard algorithms as discussed in codeproject article.
I would like the behavior of the treeview control but a rendering panel using algorithms presented in codeproject article.
how would the approach look for in this scenario?
thanks
leblanc,
The Leopard Stacks is just a custom ItemsControl (or ListBox) with a customized ItemsPanel and ItemTemplate. A custom panel is needed for the bent look, displacing the items horizontally as you move up. The ItemTemplate takes care of the icon/tooltip.
For the custom TreeView, I suggest looking at Josh Smith’s article: http://www.codeproject.com/KB/WPF/CustomTreeViewLayout.aspx
Hi,
When do you plan to release this?? I have seen the demo of this control.Eagerly waiting for this control.
What kind of datasource’s can this control take??Should the datasource necessarily be hierarchical for the control to show nested hierarchies.
Any update on when this great control will be released?
[...] A treemap is an increasingly popular control for displaying trends in data because you can put a lot of information in a small space and still make it relatively easily understood. There are nice write-ups of the treemap here and here [...]
does your treemap support the domaindatasource and groupdescriptor property?
Hi Pavan, Good idea for use Treemap.