-
Notifications
You must be signed in to change notification settings - Fork 204
/
GettingStarted.cs
213 lines (183 loc) · 6.89 KB
/
GettingStarted.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#region Copyright Syncfusion Inc. 2001-2024.
// Copyright Syncfusion Inc. 2001-2024. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// [email protected]. Any infringement will be prosecuted under
// applicable laws.
#endregion
using System;
using Syncfusion.SfTreeMap.iOS;
using System.Collections.Generic;
#if __UNIFIED__
using UIKit;
using CoreGraphics;
using Foundation;
#else
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using nint = System.Int32;
using nuint = System.Int32;
using CGSize = System.Drawing.SizeF;
using CGRect = System.Drawing.RectangleF;
using nfloat = System.Single;
#endif
namespace SampleBrowser
{
public class GettingStarted : SampleView
{
#region Fields
SFTreeMap tree ;
UILabel label;
UIView view;
#endregion
public GettingStarted ()
{
// TreeMap Initialization
view = new UIView();
label = new UILabel();
tree = new SFTreeMap ();
tree.WeightValuePath = (NSString)"Population";
tree.ColorValuePath = (NSString)"Growth";
tree.Levels.Add (new SFTreeMapFlatLevel (){ GroupPath = (NSString)"Continent", HeaderStyle = new SFStyle(){Color = UIColor.DarkGray}, HeaderHeight = 22, ShowHeader =true });
// Leaf Item Settings
tree.LeafItemSettings = new SFLeafItemSetting ();
tree.LeafItemSettings.LabelStyle = new SFStyle () { Font = UIFont.SystemFontOfSize (12), Color = UIColor.White };
tree.LeafItemSettings.LabelPath = (NSString)"Region";
tree.LeafItemSettings.ShowLabels = true;
tree.LeafItemSettings.Gap = 2;
tree.LeafItemSettings.BorderColor=UIColor.Gray;
tree.LeafItemSettings.BorderWidth = 1;
//Color Mappings
NSMutableArray ranges = new NSMutableArray ();
ranges.Add (new SFRange () {
LegendLabel = (NSString)"1 % Growth",
From = 0,
To = 1,
Color = UIColor.FromRGB (0x77, 0xD8, 0xD8)
});
ranges.Add (new SFRange () {
LegendLabel = (NSString)"2 % Growth",
From = 0,
To = 2,
Color = UIColor.FromRGB (0xAE, 0xD9, 0x60)
});
ranges.Add (new SFRange () {
LegendLabel = (NSString)"3 % Growth",
From = 0,
To = 3,
Color = UIColor.FromRGB (0xFF, 0xAF, 0x51)
});
ranges.Add (new SFRange () {
LegendLabel = (NSString)"4 % Growth",
From = 0,
To = 4,
Color = UIColor.FromRGB (0xF3, 0xD2, 0x40)
});
tree.LeafItemColorMapping = new SFRangeColorMapping () { Ranges = ranges };
// Legend Settings
CGSize legendSize = new CGSize (this.Frame.Size.Width, 60);
CGSize iconSize = new CGSize (17, 17);
UIColor legendColor = UIColor.Gray;
tree.LegendSettings = new SFLegendSetting () {
LabelStyle = new SFStyle () {
Font = UIFont.SystemFontOfSize (12),
Color = legendColor
},
IconSize = iconSize,
ShowLegend = true,
Size = legendSize
};
GetPopulationData ();
tree.DataSource = PopulationDetails;
CustomLabelTooltipSetting tooltipSetting = new CustomLabelTooltipSetting();
tree.ShowTooltip = true;
tree.TooltipSettings = tooltipSetting;
AddSubview (view);
}
public override void LayoutSubviews()
{
// Popup Window
label.Text = "Getting Started";
label.Frame = new CGRect(0, 0, 300, 30);
base.LayoutSubviews();
view.Frame = new CGRect(0, 0, Frame.Size.Width, Frame.Size.Height);
tree.Frame = new CGRect(0, 0, Frame.Size.Width - 6, Frame.Size.Height);
view.AddSubview(tree);
label.Frame = new CGRect(0, 0, Frame.Size.Width, 40);
tree.LegendSettings.Size = new CGSize(this.Frame.Size.Width, 60);
SetNeedsDisplay();
}
void GetPopulationData()
{
NSMutableArray array = new NSMutableArray();
array.Add(getDictionary("Asia", "Indonesia", 3, 237641326));
array.Add(getDictionary("Asia", "Russia", 2, 152518015));
array.Add(getDictionary("North America", "United States", 4, 315645000));
array.Add(getDictionary("North America", "Mexico", 2, 112336538));
array.Add(getDictionary("North America", "Canada", 1, 35056064));
array.Add(getDictionary("South America", "Colombia", 1, 47000000));
array.Add(getDictionary("South America", "Brazil", 3, 193946886));
array.Add(getDictionary("Africa", "Nigeria", 2, 170901000));
array.Add(getDictionary("Africa", "Egypt", 1, 83661000));
array.Add(getDictionary("Europe", "Germany", 1, 81993000));
array.Add(getDictionary("Europe", "France", 1, 65605000));
array.Add(getDictionary("Europe", "UK", 1, 63181775));
PopulationDetails = array;
}
NSDictionary getDictionary(string continent,string region,double growth,double population)
{
object[] objects= new object[4];
object[] keys=new object[4];
keys.SetValue ("Continent", 0);
keys.SetValue ("Region", 1);
keys.SetValue ("Growth", 2);
keys.SetValue ("Population", 3);
objects.SetValue ((NSString)continent, 0);
objects.SetValue ((NSString)region, 1);
objects.SetValue (growth, 2);
objects.SetValue (population, 3);
return NSDictionary.FromObjectsAndKeys (objects, keys);
}
public NSMutableArray PopulationDetails {
get;
set;
}
}
public class CustomLabelTooltipSetting : TooltipSetting
{
public CustomLabelTooltipSetting()
{
}
public override UIView GetView(object shapeData)
{
NSArray array = (NSArray)shapeData;
NSDictionary dic = new NSDictionary();
for (nuint i = 0; i < array.Count; i++)
{
dic = array.GetItem<NSDictionary>(i);
}
UIView view = new UIView();
NSString topText = (NSString)(dic["Region"]);
NSString bottomText = (NSString)(dic["Growth"].ToString() + "%");
UILabel topLabel = new UILabel();
topLabel.Text = topText;
topLabel.Font = UIFont.SystemFontOfSize(12);
topLabel.TextColor = UIColor.White;
topLabel.TextAlignment = UITextAlignment.Center;
UILabel bottomLabel = new UILabel();
bottomLabel.Text = bottomText;
bottomLabel.Font = UIFont.SystemFontOfSize(12);
bottomLabel.TextColor = UIColor.White;
bottomLabel.TextAlignment = UITextAlignment.Center;
view.AddSubview(topLabel);
view.AddSubview(bottomLabel);
CGSize expectedLabelSize1 = topText.GetSizeUsingAttributes(new UIStringAttributes() { Font = topLabel.Font });
CGSize expectedLabelSize2 = bottomText.GetSizeUsingAttributes(new UIStringAttributes() { Font = bottomLabel.Font });
view.Frame = new CGRect(0.0f, 0.0f, Math.Max(expectedLabelSize1.Width, expectedLabelSize2.Width), 35.0f);
topLabel.Frame = new CGRect(0.0f, 0.0f, Math.Max(expectedLabelSize1.Width, expectedLabelSize2.Width), 15.0f);
bottomLabel.Frame = new CGRect(0.0f, 20.0f, Math.Max(expectedLabelSize1.Width, expectedLabelSize2.Width), 15.0f);
return view;
}
}
}