This is a migrated thread and some comments may be shown as answers.

Mapping when all types are the same

1 Answer 66 Views
TreeMap and PivotMap
This is a migrated thread and some comments may be shown as answers.
ultramods
Top achievements
Rank 1
ultramods asked on 01 Feb 2012, 10:13 AM
I would like to create treemaps dynamically using only one type of object which will represent the hierarchy.

My object looks like this:

public class Asset
{
public Asset Parent {get;set;}
public string Name {get;set;}
public int Type {get;set;} 
public List<Asset> Children {get;set;}  
public List<PropertyProperties {get;set;}  
}

public class Property
{
public string Name {get;set;}
public double Value {get;set;}  
}

I have attached a drawing of a typical model that I will be binding to the treemap.

For this example I would like to create a treemap that will have Type Well as the leaf, size is "Oil Prod" and color is "WHP"

My questions are:
1: How can I do the mapping when all the types are the same (all asset) I want to specify at run time (through some config object) which asset is the leaf based on the asset type (Well) e.g asset.Type == "Well".

2: How can I map to a size or color value when it's in a list of properties e.g. size = asset.Properties.Where(p => p.Name == "Oil Prod").FirstOrDefault().

Thank you in advance for any help.

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 06 Feb 2012, 11:02 AM
Hi,

RadTreeMap can be bound to objects of the same type with no problem. You can check out this online example that demonstrates a File / Folder scenario. Your treemap markup can look like this:

<telerik:RadTreeMap Name="treemap">
    <telerik:RadTreeMap.TypeDefinitions>
        <telerik:TypeDefinition TargetTypeName="Asset" ChildrenPath="Children"
                                ValuePath="Value" LabelPath="Name" />
    </telerik:RadTreeMap.TypeDefinitions>
</telerik:RadTreeMap>

Each time the treemap will construct a node it will get the information from the type definition, and because in your case you have only 1 type you need only 1 type definition.

In the above markup we have bound the ValuePath to property called Value. This property is a read only property that runs a LINQ expression over the Properties collection. Here is some code:
public class Asset
{
    public Asset Parent { get; set; }
 
    public string Name { get; set; }
 
    public int Type { get; set; }
 
    public List<Asset> Children { get; set; }
 
    public List<Property> Properties { get; set; }
 
    public double Value
    {
        get
        {
            return this.Properties.Sum(c => c.Value);
        }
    }
}

You can modify this expression in any way you want. For example you can run one expression for parent nodes and other for leaf nodes.

Hope this helps!
All the best,
Yavor
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
TreeMap and PivotMap
Asked by
ultramods
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or