Skip to content

Commit bcfc41d

Browse files
authored
Merge pull request #1 from YogaPriyaShanmugam/YogaPriyaShanmugam/TreeMap_GettingStarted_Android
TreeMap getting started sample.
2 parents 13b3f8b + 622db8f commit bcfc41d

30 files changed

Lines changed: 7157 additions & 0 deletions

TreeMapSample.sln

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 15
4+
VisualStudioVersion = 15.0.28307.168
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TreeMapSample", "TreeMapSample\TreeMapSample.csproj", "{E06A90FC-6A36-4580-96E9-4A838E82FF2D}"
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+
{E06A90FC-6A36-4580-96E9-4A838E82FF2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E06A90FC-6A36-4580-96E9-4A838E82FF2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E06A90FC-6A36-4580-96E9-4A838E82FF2D}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{E06A90FC-6A36-4580-96E9-4A838E82FF2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{E06A90FC-6A36-4580-96E9-4A838E82FF2D}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{E06A90FC-6A36-4580-96E9-4A838E82FF2D}.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 = {4280D5F1-DED4-4307-A12C-77F6DE1FB00E}
26+
EndGlobalSection
27+
EndGlobal
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Any raw assets you want to be deployed with your application can be placed in
2+
this directory (and child directories) and given a Build Action of "AndroidAsset".
3+
4+
These files will be deployed with you package and will be accessible using Android's
5+
AssetManager, like this:
6+
7+
public class ReadAsset : Activity
8+
{
9+
protected override void OnCreate (Bundle bundle)
10+
{
11+
base.OnCreate (bundle);
12+
13+
InputStream input = Assets.Open ("my_asset.txt");
14+
}
15+
}
16+
17+
Additionally, some Android functions will automatically load asset files:
18+
19+
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");

TreeMapSample/MainActivity.cs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
using Android.App;
2+
using Android.OS;
3+
using Android.Support.V7.App;
4+
using Android.Runtime;
5+
using Android.Widget;
6+
using Org.Json;
7+
using Com.Syncfusion.Treemap;
8+
using Android.Graphics;
9+
10+
namespace TreeMapSample
11+
{
12+
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
13+
public class MainActivity : AppCompatActivity
14+
{
15+
protected override void OnCreate(Bundle savedInstanceState)
16+
{
17+
base.OnCreate(savedInstanceState);
18+
19+
SfTreeMap treeMap = new SfTreeMap(this);
20+
treeMap.ColorValuePath = "Growth";
21+
treeMap.WeightValuePath = "Population";
22+
treeMap.LayoutType = Com.Syncfusion.Treemap.Enums.LayoutType.Squarified;
23+
treeMap.ShowTooltip = true;
24+
25+
LeafItemSetting leafItemSetting = new LeafItemSetting();
26+
leafItemSetting.ShowLabels = true;
27+
leafItemSetting.Gap = 2;
28+
leafItemSetting.LabelPath = "Country";
29+
treeMap.LeafItemSettings = leafItemSetting;
30+
31+
TreeMapFlatLevel flatLevel = new TreeMapFlatLevel();
32+
flatLevel.HeaderHeight = 20;
33+
flatLevel.GroupPath = "Continent";
34+
flatLevel.GroupGap = 5;
35+
flatLevel.ShowHeader = true;
36+
flatLevel.GroupStrokeColor = Color.Gray;
37+
flatLevel.GroupStrokeWidth = 1;
38+
flatLevel.HeaderStyle = new Style() { TextColor = Color.Black };
39+
treeMap.Levels.Add(flatLevel);
40+
41+
LegendSetting legendSettings = new LegendSetting();
42+
legendSettings.ShowLegend = true;
43+
legendSettings.LegendSize = new Size(700, 45);
44+
legendSettings.LabelStyle = new Style() { TextColor = Color.Black };
45+
treeMap.LegendSettings = legendSettings;
46+
47+
RangeColorMapping rangeColorMapping = new RangeColorMapping();
48+
49+
Range range1 = new Range();
50+
range1.From = 0;
51+
range1.To = 1;
52+
range1.Color = Color.ParseColor("#77D8D8");
53+
range1.LegendLabel = "1 % Growth";
54+
55+
Range range2 = new Range();
56+
range2.From = 0;
57+
range2.To = 2;
58+
range2.Color = Color.ParseColor("#AED960");
59+
range2.LegendLabel = "2 % Growth";
60+
61+
Range range3 = new Range();
62+
range3.From = 0;
63+
range3.To = 3;
64+
range3.Color = Color.ParseColor("#FFAF51");
65+
range3.LegendLabel = "3 % Growth";
66+
67+
Range range4 = new Range();
68+
range4.From = 0;
69+
range4.To = 4;
70+
range4.Color = Color.ParseColor("#F3D240");
71+
range4.LegendLabel = "4 % Growth";
72+
73+
rangeColorMapping.Ranges.Add(range1);
74+
rangeColorMapping.Ranges.Add(range2);
75+
rangeColorMapping.Ranges.Add(range3);
76+
rangeColorMapping.Ranges.Add(range4);
77+
78+
treeMap.LeafItemColorMapping = rangeColorMapping;
79+
treeMap.DataSource = GetDataSource();
80+
81+
SetContentView(treeMap);
82+
}
83+
84+
JSONArray GetDataSource()
85+
{
86+
JSONArray array = new JSONArray();
87+
array.Put(getJsonObject("Asia", "Indonesia", 3, 237641326));
88+
array.Put(getJsonObject("Asia", "Russia", 2, 152518015));
89+
array.Put(getJsonObject("North America", "United States", 4, 315645000));
90+
array.Put(getJsonObject("North America", "Mexico", 2, 112336538));
91+
array.Put(getJsonObject("North America", "Canada", 1, 35056064));
92+
array.Put(getJsonObject("South America", "Colombia", 1, 47000000));
93+
array.Put(getJsonObject("South America", "Brazil", 3, 193946886));
94+
array.Put(getJsonObject("Africa", "Nigeria", 2, 170901000));
95+
array.Put(getJsonObject("Africa", "Egypt", 1, 83661000));
96+
array.Put(getJsonObject("Europe", "Germany", 1, 81993000));
97+
array.Put(getJsonObject("Europe", "France", 1, 65605000));
98+
array.Put(getJsonObject("Europe", "UK", 1, 63181775));
99+
100+
return array;
101+
}
102+
103+
JSONObject getJsonObject(string continent, string country, double growth, double population)
104+
{
105+
JSONObject obj = new JSONObject();
106+
107+
obj.Put("Continent", continent);
108+
obj.Put("Country", country);
109+
obj.Put("Growth", growth);
110+
obj.Put("Population", population);
111+
112+
return obj;
113+
}
114+
115+
}
116+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:versionCode="1"
4+
android:versionName="1.0"
5+
package="TreeMapSample.TreeMapSample">
6+
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="27" />
7+
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
8+
</application>
9+
</manifest>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
using Android.App;
5+
6+
// General Information about an assembly is controlled through the following
7+
// set of attributes. Change these attribute values to modify the information
8+
// associated with an assembly.
9+
[assembly: AssemblyTitle("TreeMapSample")]
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyConfiguration("")]
12+
[assembly: AssemblyCompany("")]
13+
[assembly: AssemblyProduct("TreeMapSample")]
14+
[assembly: AssemblyCopyright("Copyright © 2018")]
15+
[assembly: AssemblyTrademark("")]
16+
[assembly: AssemblyCulture("")]
17+
[assembly: ComVisible(false)]
18+
19+
// Version information for an assembly consists of the following four values:
20+
//
21+
// Major Version
22+
// Minor Version
23+
// Build Number
24+
// Revision
25+
//
26+
// You can specify all the values or you can default the Build and Revision Numbers
27+
// by using the '*' as shown below:
28+
// [assembly: AssemblyVersion("1.0.*")]
29+
[assembly: AssemblyVersion("1.0.0.0")]
30+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Images, layout descriptions, binary blobs and string dictionaries can be included
2+
in your application as resource files. Various Android APIs are designed to
3+
operate on the resource IDs instead of dealing with images, strings or binary blobs
4+
directly.
5+
6+
For example, a sample Android app that contains a user interface layout (main.axml),
7+
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
8+
would keep its resources in the "Resources" directory of the application:
9+
10+
Resources/
11+
drawable/
12+
icon.png
13+
14+
layout/
15+
main.axml
16+
17+
values/
18+
strings.xml
19+
20+
In order to get the build system to recognize Android resources, set the build action to
21+
"AndroidResource". The native Android APIs do not operate directly with filenames, but
22+
instead operate on resource IDs. When you compile an Android application that uses resources,
23+
the build system will package the resources for distribution and generate a class called "R"
24+
(this is an Android convention) that contains the tokens for each one of the resources
25+
included. For example, for the above Resources layout, this is what the R class would expose:
26+
27+
public class R {
28+
public class drawable {
29+
public const int icon = 0x123;
30+
}
31+
32+
public class layout {
33+
public const int main = 0x456;
34+
}
35+
36+
public class strings {
37+
public const int first_string = 0xabc;
38+
public const int second_string = 0xbcd;
39+
}
40+
}
41+
42+
You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main
43+
to reference the layout/main.axml file, or R.strings.first_string to reference the first
44+
string in the dictionary file values/strings.xml.

0 commit comments

Comments
 (0)