Skip to content

Commit 50df8bc

Browse files
TreeMap hierarchical data visualization sample added
1 parent e9ff422 commit 50df8bc

39 files changed

+1289
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.9.34701.34
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TreeMapVisualizeHierarchicalData", "TreeMapVisualizeHierarchicalData\TreeMapVisualizeHierarchicalData.csproj", "{49D47250-F17B-47E3-81FC-B6E927F0D00F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{49D47250-F17B-47E3-81FC-B6E927F0D00F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{49D47250-F17B-47E3-81FC-B6E927F0D00F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{49D47250-F17B-47E3-81FC-B6E927F0D00F}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{49D47250-F17B-47E3-81FC-B6E927F0D00F}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{49D47250-F17B-47E3-81FC-B6E927F0D00F}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{49D47250-F17B-47E3-81FC-B6E927F0D00F}.Release|Any CPU.Deploy.0 = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(SolutionProperties) = preSolution
22+
HideSolutionNode = FALSE
23+
EndGlobalSection
24+
GlobalSection(ExtensibilityGlobals) = postSolution
25+
SolutionGuid = {2FE862FA-EBF5-42A5-B59B-C4FBA65D4447}
26+
EndGlobalSection
27+
EndGlobal
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:TreeMapVisualizeHierarchicalData"
5+
x:Class="TreeMapVisualizeHierarchicalData.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace TreeMapVisualizeHierarchicalData
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new AppShell();
10+
}
11+
}
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="TreeMapVisualizeHierarchicalData.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:TreeMapVisualizeHierarchicalData"
7+
Shell.FlyoutBehavior="Disabled"
8+
Title="TreeMapVisualizeHierarchicalData">
9+
10+
<ShellContent
11+
Title="Home"
12+
ContentTemplate="{DataTemplate local:MainPage}"
13+
Route="MainPage" />
14+
15+
</Shell>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace TreeMapVisualizeHierarchicalData
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using Syncfusion.Maui.TreeMap;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace TreeMapVisualizeHierarchicalData
9+
{
10+
public class LevelBehavior : Behavior<ContentPage>
11+
{
12+
#region Fields
13+
14+
/// <summary>
15+
/// The tree map instance.
16+
/// </summary>
17+
private SfTreeMap? treeMap;
18+
19+
/// <summary>
20+
/// The radio button for the no group level option.
21+
/// </summary>
22+
private RadioButton? optionButton;
23+
24+
/// <summary>
25+
/// The radio button for the group level option.
26+
/// </summary>
27+
private RadioButton? groupOptionButton;
28+
29+
#endregion
30+
31+
#region Override methods
32+
33+
/// <summary>
34+
/// Invoked when behavior is attached to a view.
35+
/// </summary>
36+
/// <param name="sampleView">The sample view to which the behavior is attached.</param>
37+
protected override void OnAttachedTo(ContentPage sampleView)
38+
{
39+
base.OnAttachedTo(sampleView);
40+
41+
this.treeMap = sampleView.FindByName<SfTreeMap>("treeMap");
42+
}
43+
44+
/// <summary>
45+
/// Invoked when behavior is detached from a view.
46+
/// </summary>
47+
/// <param name="sampleView">The sample view from which the behavior is detached.</param>
48+
protected override void OnDetachingFrom(ContentPage sampleView)
49+
{
50+
base.OnDetachingFrom(sampleView);
51+
if (this.treeMap != null)
52+
{
53+
this.treeMap = null;
54+
}
55+
56+
}
57+
58+
#endregion
59+
60+
}
61+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:treemap="clr-namespace:Syncfusion.Maui.TreeMap;assembly=Syncfusion.Maui.TreeMap"
5+
xmlns:local="clr-namespace:TreeMapVisualizeHierarchicalData"
6+
x:Class="TreeMapVisualizeHierarchicalData.MainPage">
7+
8+
<ContentPage.BindingContext>
9+
<local:PopulationViewModel />
10+
</ContentPage.BindingContext>
11+
<Grid RowDefinitions="0.05*, 0.95*">
12+
<VerticalStackLayout>
13+
<Label Text="American Countries Ordered by Population and Grouped by Continent – 2023"
14+
VerticalTextAlignment="Center"
15+
HorizontalTextAlignment="Center"
16+
FontSize="{OnPlatform Default=14, iOS=14, Android=10 }"
17+
Grid.Row="0"
18+
Padding="3"
19+
FontAttributes="Bold" />
20+
</VerticalStackLayout>
21+
<treemap:SfTreeMap x:Name="treeMap"
22+
DataSource="{Binding PopulationDetails}"
23+
RangeColorValuePath="Population"
24+
PrimaryValuePath="Population"
25+
Margin="8"
26+
Grid.Row="1"
27+
ShowToolTip="True">
28+
<treemap:SfTreeMap.LeafItemSettings>
29+
<treemap:TreeMapLeafItemSettings LabelPath="Country">
30+
<treemap:TreeMapLeafItemSettings.TextStyle>
31+
<treemap:TreeMapTextStyle TextColor="#000000" />
32+
</treemap:TreeMapLeafItemSettings.TextStyle>
33+
</treemap:TreeMapLeafItemSettings>
34+
</treemap:SfTreeMap.LeafItemSettings>
35+
<treemap:SfTreeMap.LeafItemBrushSettings>
36+
<treemap:TreeMapUniformBrushSettings Brush="Orange" />
37+
</treemap:SfTreeMap.LeafItemBrushSettings>
38+
<treemap:SfTreeMap.LegendSettings>
39+
<treemap:TreeMapLegendSettings ShowLegend="True" />
40+
</treemap:SfTreeMap.LegendSettings>
41+
<treemap:SfTreeMap.Levels>
42+
<treemap:TreeMapLevel GroupPath="Continent" />
43+
</treemap:SfTreeMap.Levels>
44+
</treemap:SfTreeMap>
45+
46+
</Grid>
47+
<ContentPage.Behaviors>
48+
<local:LevelBehavior />
49+
</ContentPage.Behaviors>
50+
51+
</ContentPage>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+

2+
namespace TreeMapVisualizeHierarchicalData
3+
{
4+
public partial class MainPage : ContentPage
5+
{
6+
public MainPage()
7+
{
8+
InitializeComponent();
9+
}
10+
11+
}
12+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.Extensions.Logging;
2+
using Syncfusion.Maui.Core.Hosting;
3+
4+
namespace TreeMapVisualizeHierarchicalData
5+
{
6+
public static class MauiProgram
7+
{
8+
public static MauiApp CreateMauiApp()
9+
{
10+
var builder = MauiApp.CreateBuilder();
11+
builder
12+
.ConfigureSyncfusionCore()
13+
.UseMauiApp<App>()
14+
.ConfigureFonts(fonts =>
15+
{
16+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
17+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
18+
});
19+
20+
#if DEBUG
21+
builder.Logging.AddDebug();
22+
#endif
23+
24+
return builder.Build();
25+
}
26+
}
27+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace TreeMapVisualizeHierarchicalData
9+
{
10+
public class PopulationDetails
11+
{
12+
#region Fields
13+
14+
/// <summary>
15+
/// The name of the country.
16+
/// </summary>
17+
private string country;
18+
19+
/// <summary>
20+
/// The continent where the country is located.
21+
/// </summary>
22+
private string continent;
23+
24+
/// <summary>
25+
/// The population of the country.
26+
/// </summary>
27+
private double population;
28+
29+
#endregion
30+
31+
#region Constructor
32+
33+
/// <summary>
34+
/// Initializes a new instance of the <see cref="PopulationDetails"/> class.
35+
/// </summary>
36+
public PopulationDetails()
37+
{
38+
this.country = string.Empty;
39+
this.continent = string.Empty;
40+
}
41+
42+
#endregion
43+
44+
#region Properties
45+
46+
/// <summary>
47+
/// Gets or sets the name of the country.
48+
/// </summary>
49+
public string Country
50+
{
51+
get { return this.country; }
52+
set
53+
{
54+
this.country = value;
55+
this.RaisePropertyChanged(nameof(Country));
56+
}
57+
}
58+
59+
/// <summary>
60+
/// Gets or sets the continent where the country is located.
61+
/// </summary>
62+
public string Continent
63+
{
64+
get { return this.continent; }
65+
set
66+
{
67+
this.continent = value;
68+
this.RaisePropertyChanged(nameof(Continent));
69+
}
70+
}
71+
72+
/// <summary>
73+
/// Gets or sets the population of the country.
74+
/// </summary>
75+
public double Population
76+
{
77+
get { return this.population; }
78+
set
79+
{
80+
this.population = value;
81+
this.RaisePropertyChanged(nameof(Population));
82+
}
83+
}
84+
85+
#endregion
86+
87+
#region Event
88+
89+
/// <summary>
90+
/// Occurs when a property value is changed.
91+
/// </summary>
92+
public event PropertyChangedEventHandler? PropertyChanged;
93+
94+
#endregion
95+
96+
#region PropertyChanged
97+
98+
/// <summary>
99+
/// Method to raise the PropertyChanged event.
100+
/// </summary>
101+
/// <param name="propertyName">The property name.</param>
102+
private void RaisePropertyChanged(string propertyName)
103+
{
104+
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
105+
}
106+
107+
#endregion
108+
}
109+
}

0 commit comments

Comments
 (0)