Skip to content

Commit 0055ec0

Browse files
committed
updated code
1 parent f3dee0b commit 0055ec0

File tree

5 files changed

+101
-41
lines changed

5 files changed

+101
-41
lines changed

MarketCap/MainPage.xaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@
77

88
<Border Margin="25" Padding="{OnPlatform Default=8, Android=7,iOS=7}" StrokeThickness="3" Stroke="Gray" StrokeShape="RoundRectangle 15">
99
<chart:SfCartesianChart HorizontalOptions="Fill" VerticalOptions="FillAndExpand">
10+
<chart:SfCartesianChart.Resources>
11+
<ResourceDictionary>
12+
<x:String x:Key="UpTrendIcon">M3.2999878,20.999992 L3.2999878,31.099993 0,31.099993 0,24.300009z
13+
M7.4000244,16.900018 L7.4000244,31.099993 4.0999756,31.099993 4.0999756,20.30001z
14+
M16.400024,16.499994 L18.599976,18.700004 19.700012,17.599998 19.700012,31.099993 16.400024,31.099993z
15+
M23.799988,13.600001 L23.799988,31.199999 20.5,31.199999 20.5,16.900018z
16+
M11.5,12.800013 L11.5,31.099993 8.2000122,31.099993 8.2000122,16.1z
17+
M12.299988,12.400019 L15.599976,15.700006 15.599976,31.099993 12.299988,31.099993z
18+
M27.900024,9.499996 L27.900024,31.199999 24.599976,31.199999 24.599976,12.800013z
19+
M28.700012,9.1000021 L29,9.1000021 32,12.100001 32,31.099993 28.700012,31.099993z
20+
M31.400024,0 L31.099976,7.2000096 28.900024,4.9999983 18.200012,15.700006
21+
17.900024,15.999993 11.700012,9.8000143 0.70001221,20.80001 0.70001221,15.800012
22+
11.599976,4.8000167 17.900024,11.100002 26.400024,2.6000052 24.200012,0.4000244z</x:String>
23+
</ResourceDictionary>
24+
</chart:SfCartesianChart.Resources>
1025
<chart:SfCartesianChart.Title>
1126
<Grid>
1227
<Grid.RowDefinitions>
@@ -17,7 +32,7 @@
1732
<ColumnDefinition Width="Auto"/>
1833
</Grid.ColumnDefinitions>
1934

20-
<Path Data="M3.2999878,20.999992L3.2999878,31.099993 0,31.099993 0,24.300009z M7.4000244,16.900018L7.4000244,31.099993 4.0999756,31.099993 4.0999756,20.30001z M16.400024,16.499994L18.599976,18.700004 19.700012,17.599998 19.700012,31.099993 16.400024,31.099993z M23.799988,13.600001L23.799988,31.199999 20.5,31.199999 20.5,16.900018z M11.5,12.800013L11.5,31.099993 8.2000122,31.099993 8.2000122,16.1z M12.299988,12.400019L15.599976,15.700006 15.599976,31.099993 12.299988,31.099993z M27.900024,9.499996L27.900024,31.199999 24.599976,31.199999 24.599976,12.800013z M28.700012,9.1000021L29,9.1000021 32,12.100001 32,31.099993 28.700012,31.099993z M31.400024,0L31.099976,7.2000096 28.900024,4.9999983 18.200012,15.700006 17.900024,15.999993 11.700012,9.8000143 0.70001221,20.80001 0.70001221,15.800012 11.599976,4.8000167 17.900024,11.100002 26.400024,2.6000052 24.200012,0.4000244z" Fill="#FF000000" Margin="10,15,10,0">
35+
<Path Data="{StaticResource UpTrendIcon}" Fill="#FF000000" Margin="10,15,10,0">
2136
<Path.RenderTransform>
2237
<TransformGroup>
2338
<TransformGroup.Children>

MarketCap/MarketCap.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
5555
</ItemGroup>
5656

57+
<ItemGroup>
58+
<MauiAsset Remove="Resources\Raw\MarketData.csv" />
59+
</ItemGroup>
60+
5761
<ItemGroup>
5862
<None Remove="Resources\Images\Australia.png" />
5963
<None Remove="Resources\Images\australia1.png" />
@@ -180,6 +184,7 @@
180184
<EmbeddedResource Include="Resources\Images\UnitedKingdom.png" />
181185
<EmbeddedResource Include="Resources\Images\UnitedStates.png" />
182186
<EmbeddedResource Include="Resources\Images\Vietnam.png" />
187+
<EmbeddedResource Include="Resources\Raw\MarketData.csv" />
183188
</ItemGroup>
184189

185190
<ItemGroup>
@@ -189,4 +194,5 @@
189194
<PackageReference Include="Syncfusion.Maui.Charts" Version="*" />
190195
</ItemGroup>
191196

197+
192198
</Project>

MarketCap/Model/MarkerCapModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6+
using IImage = Microsoft.Maui.Graphics.IImage;
67

78
namespace MarketCap
89
{
910
public class MarketCapModel
1011
{
1112
public string Name { get; set; }
12-
public Microsoft.Maui.Graphics.IImage? ImageIcon { get; set; }
13+
public IImage? ImageIcon { get; set; }
1314
public double Company { get; set; }
1415
public double Size { get; set; }
1516
public double Gdp { get; set; }
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Name,Size,Gdp,Company,ImageIcon
2+
United States,54000,194.5,4642,UnitedStates
3+
China,10088,65.1,5346,China
4+
Japan,6245,146.2,3865,Japan
5+
India,5522,140.1,5451,India
6+
France,3894,84.9,457,France
7+
Canada,3265,160.7,3534,Canada
8+
Saudi Arabia,2875,347,269,SaudiArabia
9+
United Kingdom,2584,100,1646,UnitedKingdom
10+
Germany,2182,60,429,Germany
11+
Taiwan,2020,267.1,1627,Taiwan
12+
South Korea,1884,133.5,2446,SouthKorea
13+
Iran,1743,390.1,546,Iran
14+
Australia,1723,129.3,1976,Australia
15+
Netherlands,1705,132.3,103,Netherlands
16+
Switzerland,1640,267.6,236,Switzerland
17+
Spain,1334,82.2,1472,Spain
18+
South Africa,1230,348.3,237,SouthAfrica
19+
Sweden,1009,162,832,Sweden
20+
United Arab Emirates,873,172.3,153,UnitedArabEmirates
21+
Brazil,863,68.4,361,Brazil
22+
Denmark,799,195,178,Denmark
23+
Indonesia,778,46.3,903,Indonesia
24+
Italy,747,36.5,290,Italy
25+
Belgium,715,108.8,117,Belgium
26+
Singapore,619,132.7,425,Singapore
27+
Thailand,604,122,810,Thailand
28+
Russia,530,46.8,195,Russia
29+
Mexico,454,31,133,Mexico
30+
Malaysia,381,93.7,963,Malaysia
31+
Norway,377,71.7,340,Norway
32+
Turkey,330,36.4,461,Turkey
33+
Chile,285,94.8,400,Chile
34+
Finland,269,87.5,134,Finland
35+
Israel,269,51.4,518,Israel
36+
Vietnam,246,62,402,Vietnam

MarketCap/ViewModel/MarketCapViewModel.cs

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,56 @@
11
using Microsoft.Maui.Graphics.Platform;
2-
using System.Collections.ObjectModel;
32
using System.Reflection;
3+
using IImage = Microsoft.Maui.Graphics.IImage;
44

55
namespace MarketCap
66
{
77
public class MarketCapViewModel
88
{
99
public List<MarketCapModel> MarketCapData { get; set; }
10-
public ObservableCollection<Brush> PaletteBrushes { get; set; }
1110

1211
public MarketCapViewModel()
1312
{
14-
MarketCapData = new List<MarketCapModel>();
15-
MarketCapData.Add(new MarketCapModel { Size = 54000, Gdp = 194.5, Company = 4642, Name = "United States", ImageIcon = GetImage("UnitedStates") });
16-
MarketCapData.Add(new MarketCapModel { Size = 10088, Gdp = 65.1, Company = 5346, Name = "China", ImageIcon = GetImage("China") });
17-
MarketCapData.Add(new MarketCapModel { Size = 6245, Gdp = 146.2, Company = 3865, Name = "Japan", ImageIcon = GetImage("Japan") });
18-
MarketCapData.Add(new MarketCapModel { Size = 5522, Gdp = 140.1, Company = 5451, Name = "India", ImageIcon = GetImage("India") });
19-
MarketCapData.Add(new MarketCapModel { Size = 3894, Gdp = 84.9, Company = 457, Name = "France", ImageIcon = GetImage("France") });
20-
MarketCapData.Add(new MarketCapModel { Size = 3265, Gdp = 160.7, Company = 3534, Name = "Canada", ImageIcon = GetImage("Canada") });
21-
MarketCapData.Add(new MarketCapModel { Size = 2875, Gdp = 347.0, Company = 269, Name = "Saudi Arabia", ImageIcon = GetImage("SaudiArabia") });
22-
MarketCapData.Add(new MarketCapModel { Size = 2584, Gdp = 100, Company = 1646, Name = "United Kingdom", ImageIcon = GetImage("UnitedKingdom") });
23-
MarketCapData.Add(new MarketCapModel { Size = 2182, Gdp = 60, Company = 429, Name = "Germany", ImageIcon = GetImage("Germany") });
24-
MarketCapData.Add(new MarketCapModel { Size = 2020, Gdp = 267.1, Company = 1627, Name = "Taiwan", ImageIcon = GetImage("Taiwan") });
25-
MarketCapData.Add(new MarketCapModel { Size = 1884, Gdp = 133.5, Company = 2446, Name = "South Korea", ImageIcon = GetImage("SouthKorea") });
26-
MarketCapData.Add(new MarketCapModel { Size = 1743, Gdp = 390.1, Company = 546, Name = "Iran", ImageIcon = GetImage("Iran") });
27-
MarketCapData.Add(new MarketCapModel { Size = 1723, Gdp = 129.3, Company = 1976, Name = "Australia", ImageIcon = GetImage("Australia") });
28-
MarketCapData.Add(new MarketCapModel { Size = 1705, Gdp = 132.3, Company = 103, Name = "Netherlands", ImageIcon = GetImage("Netherlands") });
29-
MarketCapData.Add(new MarketCapModel { Size = 1640, Gdp = 267.6, Company = 236, Name = "Switzerland", ImageIcon = GetImage("Switzerland") });
30-
MarketCapData.Add(new MarketCapModel { Size = 1334, Gdp = 82.2, Company = 1472, Name = "Spain", ImageIcon = GetImage("Spain") });
31-
MarketCapData.Add(new MarketCapModel { Size = 1230, Gdp = 348.3, Company = 237, Name = "South Africa", ImageIcon = GetImage("SouthAfrica") });
32-
MarketCapData.Add(new MarketCapModel { Size = 1009, Gdp = 162, Company = 832, Name = "Sweden", ImageIcon = GetImage("Sweden") });
33-
MarketCapData.Add(new MarketCapModel { Size = 873, Gdp = 172.3, Company = 153, Name = "United Arab Emirates", ImageIcon = GetImage("UnitedArabEmirates") });
34-
MarketCapData.Add(new MarketCapModel { Size = 863, Gdp = 68.4, Company = 361, Name = "Brazil", ImageIcon = GetImage("Brazil") });
35-
MarketCapData.Add(new MarketCapModel { Size = 799, Gdp = 195, Company = 178, Name = "Denmark", ImageIcon = GetImage("Denmark") });
36-
MarketCapData.Add(new MarketCapModel { Size = 778, Gdp = 46.3, Company = 903, Name = "Indonesia", ImageIcon = GetImage("Indonesia") });
37-
MarketCapData.Add(new MarketCapModel { Size = 747, Gdp = 36.5, Company = 290, Name = "Italy", ImageIcon = GetImage("Italy") });
38-
MarketCapData.Add(new MarketCapModel { Size = 715, Gdp = 108.8, Company = 117, Name = "Belgium", ImageIcon = GetImage("Belgium") });
39-
MarketCapData.Add(new MarketCapModel { Size = 619, Gdp = 132.7, Company = 425, Name = "Singapore", ImageIcon = GetImage("Singapore") });
40-
MarketCapData.Add(new MarketCapModel { Size = 604, Gdp = 122.0, Company = 810, Name = "Thailand", ImageIcon = GetImage("Thailand") });
41-
MarketCapData.Add(new MarketCapModel { Size = 530, Gdp = 46.8, Company = 195, Name = "Russia", ImageIcon = GetImage("Russia") });
42-
MarketCapData.Add(new MarketCapModel { Size = 454, Gdp = 31.0, Company = 133, Name = "Mexico", ImageIcon = GetImage("Mexico") });
43-
MarketCapData.Add(new MarketCapModel { Size = 381, Gdp = 93.7, Company = 963, Name = "Malaysia", ImageIcon = GetImage("Malaysia") });
44-
MarketCapData.Add(new MarketCapModel { Size = 377, Gdp = 71.7, Company = 340, Name = "Norway", ImageIcon = GetImage("Norway") });
45-
MarketCapData.Add(new MarketCapModel { Size = 330, Gdp = 36.4, Company = 461, Name = "Turkey", ImageIcon = GetImage("Turkey") });
46-
MarketCapData.Add(new MarketCapModel { Size = 285, Gdp = 94.8, Company = 400, Name = "Chile", ImageIcon = GetImage("Chile") });
47-
MarketCapData.Add(new MarketCapModel { Size = 269, Gdp = 87.5, Company = 134, Name = "Finland", ImageIcon = GetImage("Finland") });
48-
MarketCapData.Add(new MarketCapModel { Size = 269, Gdp = 51.4, Company = 518, Name = "Israel", ImageIcon = GetImage("Israel") });
49-
MarketCapData.Add(new MarketCapModel { Size = 246, Gdp = 62.0, Company = 402, Name = "Vietnam", ImageIcon = GetImage("Vietnam") });
13+
MarketCapData = new List<MarketCapModel>(ReadCSV());
5014
}
51-
private Microsoft.Maui.Graphics.IImage? GetImage(string resourcePath)
15+
16+
public static IEnumerable<MarketCapModel> ReadCSV()
17+
{
18+
Assembly executingAssembly = typeof(App).GetTypeInfo().Assembly;
19+
Stream inputStream = executingAssembly.GetManifestResourceStream("MarketCap.Resources.Raw.MarketData.csv");
20+
21+
if (inputStream == null)
22+
{
23+
throw new FileNotFoundException("CSV file not found.");
24+
}
25+
26+
string line;
27+
List<string> lines = new();
28+
29+
using StreamReader reader = new(inputStream);
30+
// Skip the header line
31+
reader.ReadLine();
32+
33+
while ((line = reader.ReadLine()) != null)
34+
{
35+
lines.Add(line);
36+
}
37+
38+
return lines.Select(line =>
39+
{
40+
string[] data = line.Split(',');
41+
42+
return new MarketCapModel
43+
{
44+
Size = Convert.ToDouble(data[1]),
45+
Gdp = Convert.ToDouble(data[2]),
46+
Company = Convert.ToInt32(data[3]),
47+
Name = data[0],
48+
ImageIcon = GetImage(data[4]) // Assuming the ImageIcon is the 5th column
49+
};
50+
});
51+
}
52+
53+
private static IImage? GetImage(string resourcePath)
5254
{
5355
Assembly assembly = typeof(MainPage).GetTypeInfo().Assembly;
5456
using Stream? stream = assembly.GetManifestResourceStream("MarketCap.Resources.Images." + resourcePath + ".png");

0 commit comments

Comments
 (0)