Skip to content

Commit b146f88

Browse files
committed
fixes.
1 parent bea5839 commit b146f88

17 files changed

+237
-145
lines changed

MyFinance/AppShell.cs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public AppShell(IServiceProvider serviceProvider)
1111
)
1212
.FlyoutBehavior(FlyoutBehavior.Disabled)
1313
.Items(
14-
1514
new TabBar()
1615
.Items(
1716
new Tab()

MyFinance/Enums/ChartType.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace MyFinance.Enums;
2+
3+
public enum ChartType
4+
{
5+
Weekly,
6+
Monthly,
7+
SixMonthly,
8+
Yearly
9+
}

MyFinance/HotReloadHandler.cs

-16
This file was deleted.

MyFinance/MauiProgram.cs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace MyFinance;
1010
[MauiMarkup(typeof(PasswordEdit), typeof(CheckEdit), typeof(DXPopup), typeof(ComboBoxEditBase), typeof(ItemsEditBase))]
1111
[MauiMarkup(typeof(DXImage), typeof(DXButton), typeof(DXViewBase), typeof(DXBorder), typeof(DXContentPresenterBase))]
1212
[MauiMarkup(typeof(DXContentPresenter), typeof(DXCollectionView), typeof(CartesianChart))]
13-
1413
public static class MauiProgram
1514
{
1615
public static MauiApp CreateMauiApp()

MyFinance/MyFinance.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
6666
<PackageReference Include="DevExpress.Maui.Controls" Version="24.1.1-alpha-24085" />
6767
<PackageReference Include="DevExpress.Maui.Editors" Version="24.1.1-alpha-24085" />
68-
<PackageReference Include="FmgLib.MauiMarkup" Version="8.2.3-prev1.0.3" />
68+
<PackageReference Include="FmgLib.MauiMarkup" Version="8.3.0-prev1.0.1" />
6969
<PackageReference Include="LiveChartsCore.SkiaSharpView.Maui" Version="2.0.0-rc2" />
7070
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4" />
7171
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.21" />

MyFinance/Utilities/DateTimeHelper.cs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System.Globalization;
2+
3+
namespace MyFinance.Utilities;
4+
5+
public static class DateTimeHelper
6+
{
7+
public static IList<string> GetDayNames(IList<DateTime> dates)
8+
{
9+
List<string> dayNames = new List<string>();
10+
var culture = new CultureInfo("tr-TR");
11+
12+
foreach (var date in dates)
13+
{
14+
try
15+
{
16+
DateTime dateTime = new DateTime(date.Year, date.Month, date.Day);
17+
string dayName = culture.DateTimeFormat.GetDayName(dateTime.DayOfWeek);
18+
dayNames.Add(dayName);
19+
}
20+
catch (ArgumentOutOfRangeException)
21+
{
22+
dayNames.Add("Invalid day");
23+
}
24+
}
25+
26+
return dayNames;
27+
}
28+
29+
public static IList<string> GetMonthNames(IList<DateTime> dates)
30+
{
31+
List<string> monthNames = new List<string>();
32+
var culture = new CultureInfo("tr-TR");
33+
34+
foreach (var date in dates)
35+
{
36+
try
37+
{
38+
DateTime dateTime = new DateTime(date.Year, date.Month, 1);
39+
string monthName = culture.DateTimeFormat.GetMonthName(date.Month);
40+
monthNames.Add(monthName);
41+
}
42+
catch (ArgumentOutOfRangeException)
43+
{
44+
monthNames.Add("Invalid day");
45+
}
46+
}
47+
48+
return monthNames;
49+
}
50+
}

MyFinance/VMs/OperationGraphVM.cs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace MyFinance.VMs;
2+
3+
public class OperationGraphVM
4+
{
5+
public DateTime Date { get; set; }
6+
public double Amount { get; set; }
7+
public bool IsIncome { get; set; }
8+
}
+132-42
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
namespace MyFinance.ViewModels;
1+
using LiveChartsCore.SkiaSharpView.Painting.Effects;
2+
using LiveChartsCore.SkiaSharpView.Painting;
3+
using SkiaSharp;
4+
using System.Linq;
5+
using LiveChartsCore.Drawing;
6+
7+
namespace MyFinance.ViewModels;
28

39
public partial class ChartPageViewModel : BaseViewModel
410
{
@@ -10,65 +16,149 @@ public partial class ChartPageViewModel : BaseViewModel
1016

1117
[ObservableProperty]
1218
private string totalExpense;
13-
private readonly Random _random = new();
19+
20+
[ObservableProperty]
21+
private Axis[] xAxes;
22+
23+
[ObservableProperty]
24+
private Axis[] yAxes;
25+
26+
[ObservableProperty]
27+
private ISeries[] series;
28+
29+
[ObservableProperty]
30+
private ChartType cType;
31+
32+
33+
private List<OperatonItemsVM> items = new();
34+
1435
public ChartPageViewModel()
1536
{
37+
CType = ChartType.Weekly;
1638
TotalBalance = "25,291.50 ₺";
1739
TotalExpense = "2,367.82 ₺";
1840
TotalIncome = "167.82 ₺";
19-
var trend = 100;
20-
var values = new List<int>();
2141

22-
for (var i = 0; i < 100; i++)
23-
{
24-
trend += _random.Next(-30, 50);
25-
values.Add(trend);
26-
}
2742

28-
Series = new ISeries[]
43+
44+
Random random = new Random();
45+
for (int i = 1; i <= 100; i++)
2946
{
30-
new ColumnSeries<int>
31-
{
32-
Values = values
33-
}
34-
};
47+
var amount = random.Next(1, 10000);
48+
items.Add(
49+
new OperatonItemsVM
50+
{
51+
Id = Guid.NewGuid(),
52+
Icon = amount % 2 == 0 ? "loss.png" : "profits.png",
53+
Color = amount % 2 == 0 ? Red : Green,
54+
Date = DateTime.Now.AddDays(-(amount % 7)).ToString("dd.MM.yyyy HH:mm"),
55+
Title = amount % 2 == 0 ? "Borç ödendi" : "Ödeme Alındı",
56+
Description = amount % 2 == 0 ? "Ödemeler yapıldı" : "Yaka parası alındı.",
57+
Amount = $"{amount} ₺"
58+
}
59+
);
60+
}
3561

36-
XAxes = new[] { new Axis() };
62+
Calc(7);
3763
}
3864

39-
public ISeries[] Series { get; }
40-
41-
public Axis[] XAxes { get; }
4265

4366
[RelayCommand]
44-
public void GoToPage1()
67+
public void ChartTypeChanged()
4568
{
46-
var axis = XAxes[0];
47-
axis.MinLimit = -0.5;
48-
axis.MaxLimit = 10.5;
69+
if (CType == ChartType.Weekly)
70+
Calc(7);
71+
else if (CType == ChartType.Monthly)
72+
Calc(30);
73+
else if (CType == ChartType.SixMonthly)
74+
Calc(180);
75+
else if (CType == ChartType.Yearly)
76+
Calc(365);
4977
}
5078

51-
[RelayCommand]
52-
public void GoToPage2()
79+
private void Calc(int days)
5380
{
54-
var axis = XAxes[0];
55-
axis.MinLimit = -0.5;
56-
axis.MaxLimit = 20.5;
57-
}
81+
var graphVals = items
82+
.Where(e => DateTime.Parse(e.Date) > DateTime.Now.AddDays(-days))
83+
.Select(e => new OperationGraphVM { Date = DateTime.Parse(e.Date).Date, Amount = double.Parse(e.Amount.Trim().Trim('₺')), IsIncome = e.Color == Green })
84+
.ToList();
5885

59-
[RelayCommand]
60-
public void GoToPage3()
61-
{
62-
var axis = XAxes[0];
63-
axis.MinLimit = -0.5;
64-
axis.MaxLimit = 30.5;
65-
}
86+
var strokeThickness = 6;
87+
var strokeDashArray = new float[] { 3 * strokeThickness, 2 * strokeThickness };
88+
var effect = new DashEffect(strokeDashArray);
6689

67-
[RelayCommand]
68-
public void SeeAll()
69-
{
70-
var axis = XAxes[0];
71-
axis.MinLimit = null;
72-
axis.MaxLimit = null;
90+
var inVals = graphVals
91+
.Where(x => x.IsIncome)
92+
.GroupBy(e => e.Date)
93+
.OrderBy(g => g.Key.Year)
94+
.ThenBy(g => g.Key.Month)
95+
.ThenBy(g => g.Key.Day)
96+
.Select(e => new OperationGraphVM { Date = e.Key, Amount = e.Sum(x => x.Amount), IsIncome = true })
97+
.ToList();
98+
99+
var outVals = graphVals
100+
.Where(x => !x.IsIncome)
101+
.GroupBy(e => e.Date)
102+
.OrderBy(g => g.Key.Year)
103+
.ThenBy(g => g.Key.Month)
104+
.ThenBy(g => g.Key.Day)
105+
.Select(e => new OperationGraphVM { Date = e.Key, Amount = e.Sum(x => x.Amount), IsIncome = false })
106+
.ToList();
107+
108+
var vals = inVals
109+
.Join(outVals,
110+
i => i.Date,
111+
e => e.Date,
112+
(i, e) => i.Amount - e.Amount)
113+
.ToList();
114+
115+
Series = new ISeries[]
116+
{
117+
new LineSeries<double>
118+
{
119+
Values = inVals.Select(e => e.Amount),
120+
LineSmoothness = 0,
121+
Fill = null
122+
},
123+
124+
new LineSeries<double>
125+
{
126+
Values = outVals.Select(e => e.Amount),
127+
LineSmoothness = 1,
128+
Fill = null
129+
},
130+
131+
new LineSeries<double>
132+
{
133+
Values = vals,
134+
LineSmoothness = 2
135+
}
136+
};
137+
138+
XAxes = new Axis[]
139+
{
140+
new Axis
141+
{
142+
CrosshairLabelsBackground = SKColors.DarkOrange.AsLvcColor(),
143+
CrosshairLabelsPaint = new SolidColorPaint(SKColors.DarkRed, 1),
144+
CrosshairPaint = new SolidColorPaint(SKColors.DarkOrange, 1),
145+
Labels = DateTimeHelper.GetDayNames(graphVals.GroupBy(e => e.Date).Select(e => e.Key).ToList()),
146+
LabelsRotation = 90,
147+
NamePadding = new Padding(0),
148+
Padding = new Padding(0),
149+
NameTextSize = 12
150+
}
151+
};
152+
153+
YAxes = new Axis[]
154+
{
155+
new Axis
156+
{
157+
CrosshairLabelsBackground = SKColors.DarkOrange.AsLvcColor(),
158+
CrosshairLabelsPaint = new SolidColorPaint(SKColors.DarkRed, 1),
159+
CrosshairPaint = new SolidColorPaint(SKColors.DarkOrange, 1),
160+
CrosshairSnapEnabled = true // snapping is also supported
161+
}
162+
};
73163
}
74164
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
namespace MyFinance.ViewModels
1+
namespace MyFinance.ViewModels;
2+
3+
public partial class BaseViewModel : ObservableObject
24
{
3-
public partial class BaseViewModel : ObservableObject
4-
{
5-
}
65
}

MyFinance/Views/AccountPage.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace MyFinance.Views;
22

3-
public partial class AccountPage(AccountPageViewModel viewModel) : BasePage<AccountPageViewModel>(viewModel, "Account Page")
3+
public partial class AccountPage(AccountPageViewModel viewModel) : FmgLibContentPage<AccountPageViewModel>(viewModel)
44
{
55
public override void Build()
66
{

MyFinance/Views/ChartPage.cs

+28-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
namespace MyFinance.Views;
22

3-
public partial class ChartPage(ChartPageViewModel viewModel) : BasePage<ChartPageViewModel>(viewModel, "Chart Page")
3+
public partial class ChartPage(ChartPageViewModel viewModel) : FmgLibContentPage<ChartPageViewModel>(viewModel)
44
{
55
public override void Build()
66
{
77
this
88
.Content(
99
new Grid()
10-
.RowDefinitions(e => e.Star(.6).Star(8.8).Star(.6))
11-
.Margin(5)
10+
.RowDefinitions(e => e.Star(1.3).Star(.7).Star(8))
11+
.Spacing(10)
12+
.Margin(10)
1213
.Children(
1314
new VerticalStackLayout()
1415
.Spacing(-3)
@@ -46,21 +47,34 @@ public override void Build()
4647
)
4748
),
4849

49-
new CartesianChart()
50+
new ComboBoxEdit()
5051
.Row(1)
52+
.SelectedIndex(e => e.Path("CType"))
53+
.SelectionChangedCommand(e => e.Path("ChartTypeChangedCommand"))
54+
.ItemsSource(new List<string>
55+
{
56+
"Haftalık Grafik",
57+
"Aylık Grafik",
58+
"6 Aylık Grafik",
59+
"Yıllık Grafik"
60+
}),
61+
62+
new CartesianChart()
63+
.Row(2)
5164
.Series(e => e.Path("Series"))
5265
.XAxes(e => e.Path("XAxes"))
53-
.ZoomMode(ZoomX),
66+
.YAxes(e => e.Path("YAxes"))
67+
.ZoomMode(ZoomX)
5468

55-
new HorizontalStackLayout()
56-
.Row(2)
57-
.Spacing(10)
58-
.Children(
59-
new Button().Command(e => e.Path("GoToPage1Command")).Text("Weeks"),
60-
new Button().Command(e => e.Path("GoToPage2Command")).Text("Month"),
61-
new Button().Command(e => e.Path("GoToPage3Command")).Text("6 Months"),
62-
new Button().Command(e => e.Path("SeeAllCommand")).Text("Clear")
63-
)
69+
//new HorizontalStackLayout()
70+
//.Row(2)
71+
//.Spacing(10)
72+
//.Children(
73+
// new Button().Command(e => e.Path("GoToPage1Command")).Text("Weeks"),
74+
// new Button().Command(e => e.Path("GoToPage2Command")).Text("Month"),
75+
// new Button().Command(e => e.Path("GoToPage3Command")).Text("6 Months"),
76+
// new Button().Command(e => e.Path("SeeAllCommand")).Text("Clear")
77+
//)
6478
)
6579
);
6680
}

0 commit comments

Comments
 (0)