-
-
Notifications
You must be signed in to change notification settings - Fork 492
/
Copy pathChatStatisticsOverview.xaml.cs
72 lines (63 loc) · 1.96 KB
/
ChatStatisticsOverview.xaml.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
//
// Copyright Fela Ameghino 2015-2025
//
// Distributed under the GNU General Public License v3.0. (See accompanying
// file LICENSE or copy at https://www.gnu.org/licenses/gpl-3.0.txt)
//
using Telegram.Converters;
using Telegram.Td.Api;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Telegram.Controls
{
public sealed partial class ChatStatisticsOverview : UserControl
{
public ChatStatisticsOverview()
{
InitializeComponent();
}
public string Title
{
get => TitleLabel.Text;
set => TitleLabel.Text = value;
}
private double _percentage;
public double Percentage
{
get => _percentage;
set => SetPercentage(value);
}
private void SetPercentage(double value)
{
_percentage = value;
ValueLabel.Text = string.Format("{0:0.0}%", value);
}
private StatisticalValue _value;
public StatisticalValue Value
{
get => _value;
set => Set(value);
}
private void Set(StatisticalValue value)
{
_value = value;
if (value == null)
{
Visibility = Visibility.Collapsed;
return;
}
ValueLabel.Text = Formatter.ShortNumber((int)value.Value);
var diff = value.Value - value.PreviousValue;
if (diff > 0)
{
VisualStateManager.GoToState(this, "Positive", false);
GrowthLabel.Text = string.Format("+{0} ({1:F2}%)", Formatter.ShortNumber((int)diff), value.GrowthRatePercentage);
}
else if (diff < 0)
{
VisualStateManager.GoToState(this, "Negative", false);
GrowthLabel.Text = string.Format("-{0} ({1:F2}%)", Formatter.ShortNumber(-(int)diff), -value.GrowthRatePercentage);
}
}
}
}