forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SunburstSelection.cs
238 lines (201 loc) · 11.6 KB
/
SunburstSelection.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#region Copyright Syncfusion Inc. 2001-2022.
// Copyright Syncfusion Inc. 2001-2022. 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 System.Collections.Generic;
using Syncfusion.SfSunburstChart.iOS;
using CoreGraphics;
using UIKit;
using System.Collections.ObjectModel;
using System.Drawing;
namespace SampleBrowser
{
public class SunburstSelection : SampleView
{
SfSunburstChart chart;
UIPickerView selectionModePicker;
UIPickerView selectionTypePicker;
UIView option;
public ObservableCollection<SunburstModel> Population_Data { get; set; }
public SunburstSelection()
{
selectionModePicker = new UIPickerView();
selectionTypePicker = new UIPickerView();
option = new UIView();
this.Population_Data = new ObservableCollection<SunburstModel>
{
new SunburstModel { State = "Ontario", Continent = "North America", Country = "Canada", Population = 13210600 },
new SunburstModel { State = "New York", Continent = "North America", Country = "United States", Population = 19378102 },
new SunburstModel { State = "Pennsylvania", Continent = "North America", Country = "United States", Population = 12702379 },
new SunburstModel { State = "Ohio", Continent = "North America", Country = "United States", Population = 11536504 },
new SunburstModel { State = "Buenos Aires", Continent = "South America", Country = "Argentina", Population = 15594428 },
new SunburstModel { State = "Minas Gerais", Continent = "South America", Country = "Brazil", Population = 20593366 },
new SunburstModel { State = "Rio de Janeiro", Continent = "South America", Country = "Brazil", Population = 16369178 },
new SunburstModel { State = "Bahia", Continent = "South America", Country = "Brazil", Population = 15044127 },
new SunburstModel { State = "Rio Grande do Sul", Continent = "South America", Country = "Brazil", Population = 11164050 },
new SunburstModel { State = "Parana", Continent = "South America", Country = "Brazil", Population = 10997462 },
new SunburstModel { State = "Chittagong", Continent = "Asia", Country = "Bangladesh", Population = 28079000 },
new SunburstModel { State = "Rajshahi", Continent = "Asia", Country = "Bangladesh", Population = 18329000 },
new SunburstModel { State = "Khulna", Continent = "Asia", Country = "Bangladesh", Population = 15563000 },
new SunburstModel { State = "Liaoning", Continent = "Asia", Country = "China", Population = 43746323 },
new SunburstModel { State = "Shaanxi", Continent = "Asia", Country = "China", Population = 37327378 },
new SunburstModel { State = "Fujian", Continent = "Asia", Country = "China", Population = 36894216 },
new SunburstModel { State = "Shanxi", Continent = "Asia", Country = "China", Population = 35712111 },
new SunburstModel { State = "Kerala", Continent = "Asia", Country = "India", Population = 33387677 },
new SunburstModel { State = "Punjab", Continent = "Asia", Country = "India", Population = 27704236 },
new SunburstModel { State = "Haryana", Continent = "Asia", Country = "India", Population = 25353081 },
new SunburstModel { State = "Delhi", Continent = "Asia", Country = "India", Population = 16753235 },
new SunburstModel { State = "Jammu", Continent = "Asia", Country = "India", Population = 12548926 },
new SunburstModel { State = "West Java", Continent = "Asia", Country = "Indonesia", Population = 43021826 },
new SunburstModel { State = "East Java", Continent = "Asia", Country = "Indonesia", Population = 37476011 },
new SunburstModel { State = "Banten", Continent = "Asia", Country = "Indonesia", Population = 10644030 },
new SunburstModel { State = "Jakarta", Continent = "Asia", Country = "Indonesia", Population = 10187595 },
new SunburstModel { State = "Tianjin", Continent = "Africa", Country = "Ethiopia", Population = 24000200 },
new SunburstModel { State = "Tianjin", Continent = "Africa", Country = "Ethiopia", Population = 15042531 },
new SunburstModel { State = "Rift Valley", Continent = "Africa", Country = "Kenya", Population = 10006805 },
new SunburstModel { State = "Lagos", Continent = "Africa", Country = "Nigeria", Population = 10006805 },
new SunburstModel { State = "Kano", Continent = "Africa", Country = "Nigeria", Population = 10006805 },
new SunburstModel { State = "Gauteng", Continent = "Africa", Country = "South Africa", Population = 12728400 },
new SunburstModel { State = "KwaZulu-Natal", Continent = "Africa", Country = "South Africa", Population = 10456900 },
new SunburstModel { State = "Ile-de- France", Continent = "Europe", Country = "France", Population = 11694000 },
new SunburstModel { State = "North Rhine-Westphalia", Continent = "Europe", Country = "Germany", Population = 17872863 },
new SunburstModel { State = "Bavaria", Continent = "Europe", Country = "Germany", Population = 12510331 },
new SunburstModel { State = "NBaden-Wurttemberg", Continent = "Europe", Country = "Germany", Population = 10747479 },
new SunburstModel { State = "England", Continent = "Europe", Country = "United Kingdom", Population = 51446600 }
};
chart = new SfSunburstChart();
chart.ItemsSource = Population_Data;
chart.Radius = 0.95;
chart.ValueMemberPath = "Population";
var levels = new SunburstLevelCollection()
{
new SunburstHierarchicalLevel() { GroupMemberPath = "Continent"},
new SunburstHierarchicalLevel() { GroupMemberPath = "Country"},
new SunburstHierarchicalLevel() { GroupMemberPath = "State"}
};
chart.Levels = levels;
chart.Title.IsVisible = true;
chart.Title.Text = "Population Data";
chart.Title.Font= UIFont.SystemFontOfSize(20);
chart.Title.Margin = new UIEdgeInsets(10, 5, 5, 5);
chart.Legend.IsVisible = true;
chart.Legend.LabelStyle.Font= UIFont.SystemFontOfSize(16);
chart.Legend.IconHeight = 12;
chart.Legend.IconWidth = 12;
chart.SelectionSettings.EnableSelection = true;
chart.DataLabel.ShowLabel = true;
this.AddSubview(chart);
CreateOptionView();
this.OptionView = option;
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
chart.Frame = new CGRect(Frame.Location.X, 0, this.Frame.Width, this.Frame.Height);
}
private void CreateOptionView()
{
UILabel selectionMode = new UILabel();
selectionMode.Text = "Selection Mode";
selectionMode.TextAlignment = UITextAlignment.Left;
selectionMode.TextColor = UIColor.Black;
selectionMode.Frame = new CGRect(10, 20, 120, 20);
selectionMode.Font = UIFont.FromName("Helvetica", 14f);
UILabel selectionType = new UILabel();
selectionType.Text = "Selection Type";
selectionType.TextAlignment = UITextAlignment.Left;
selectionType.TextColor = UIColor.Black;
selectionType.Frame = new CGRect(10, 80, 120, 20);
selectionType.Font = UIFont.FromName("Helvetica", 14f);
List<string> position1 = new List<string> { "Opacity", "Color", "Stroke" };
var picker1 = new SelectionPickerModel(position1);
selectionModePicker.Model = picker1;
selectionModePicker.SelectedRowInComponent(0);
selectionModePicker.Frame = new CGRect(140, 10, 150, 40);
picker1.ValueChanged += (sender, e) =>
{
if (picker1.SelectedValue == "Opacity")
{
chart.SelectionSettings.SelectionDisplayMode = SelectionDisplayMode.HighlightByOpacity;
}
else if (picker1.SelectedValue == "Color")
{
chart.SelectionSettings.SelectionDisplayMode = SelectionDisplayMode.HighlightByColor;
}
else if (picker1.SelectedValue == "Stroke")
{
chart.SelectionSettings.SelectionDisplayMode = SelectionDisplayMode.HighlightByStroke;
}
};
List<string> position2 = new List<string> { "Child", "Group", "Parent" , "Single"};
var picker2 = new SelectionPickerModel(position2);
selectionTypePicker.Model = picker2;
selectionTypePicker.SelectedRowInComponent(0);
selectionTypePicker.Frame = new CGRect(140, 70, 150, 40);
picker2.ValueChanged += (sender, e) =>
{
if (picker2.SelectedValue == "Child")
{
chart.SelectionSettings.SelectionType = SelectionType.Child;
}
else if (picker2.SelectedValue == "Group")
{
chart.SelectionSettings.SelectionType = SelectionType.Group;
}
else if (picker2.SelectedValue == "Parent")
{
chart.SelectionSettings.SelectionType = SelectionType.Parent;
}
else if (picker2.SelectedValue == "Single")
{
chart.SelectionSettings.SelectionType = SelectionType.Single;
}
};
this.option.AddSubview(selectionMode);
this.option.AddSubview(selectionType);
this.option.AddSubview(selectionModePicker);
this.option.AddSubview(selectionTypePicker);
}
}
public class SelectionPickerModel : UIPickerViewModel
{
List<string> position;
public EventHandler ValueChanged;
public string SelectedValue;
public SelectionPickerModel(List<string> position)
{
this.position = position;
}
public override nint GetRowsInComponent(UIPickerView pickerView, nint component)
{
return position.Count;
}
public override nint GetComponentCount(UIPickerView pickerView)
{
return 1;
}
public override string GetTitle(UIPickerView pickerView, nint row, nint component)
{
return position[(int)row]; ;
}
public override UIView GetView(UIPickerView pickerView, nint row, nint component, UIView view)
{
UILabel label = new UILabel(new Rectangle(0, 0, 130, 40));
label.TextColor = UIColor.Black;
label.Font = UIFont.FromName("Helvetica", 14f);
label.TextAlignment = UITextAlignment.Center;
label.Text = position[(int)row];
return label;
}
public override void Selected(UIPickerView pickerView, nint row, nint component)
{
var position1 = position[(int)row];
SelectedValue = position1;
ValueChanged?.Invoke(null, null);
}
}
}