Skip to content

Commit

Permalink
Added userControl (ExchangeRateWatcher), used in charts screen, minor…
Browse files Browse the repository at this point in the history
… UI enhancements
  • Loading branch information
Rbn3D committed Aug 20, 2017
1 parent a83ef20 commit 7607177
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 58 deletions.
Binary file added RepoImages/Screen3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions WpfTest/Currency/Currency.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using static WpfTest.Currency.CurrencySymbol;

namespace WpfTest
{
public class Currency
{
public string Name { get; set; }

public bool Enabled { get; set; } = true;

public Color Color { get; set; }

public double CurrentTrend { get; set; } = 0d;

public int Volatility { get; set; } = 50;

public Series ChartSerie { get; set; }

public CurrencySymbol Symbol { get; set; }

public string Format(double ammount)
{
if (Symbol.Location == SymbolLocation.Left)
{
return String.Format("{0} {1:0.00}", Symbol.Symbol, ammount);
}
else
{
return String.Format("{0:0.00} {1}", ammount, Symbol.Symbol);
}
}

public class CurrencySymbol
{
public enum SymbolLocation
{
Left, Right
}
public String Symbol { get; set; }
public SymbolLocation Location { get; set; } = SymbolLocation.Right;
}
}
}
14 changes: 14 additions & 0 deletions WpfTest/Currency/CurrencyPair.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfTest
{
public class CurrencyPair
{
public Currency BaseCurrency { get; set; }
public Currency TargetCurrency { get; set; }
}
}
13 changes: 13 additions & 0 deletions WpfTest/Helper/MathR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace WpfTest
{
Expand Down Expand Up @@ -36,6 +37,18 @@ public static double Lerp(double value1, double value2, double ammount)
return value1 + (value2 - value1) * MathR.Clamp01(ammount);
}

public static Color Lerp(Color color1, Color color2, double ammount)
{
var col = new Color();

col.R = (byte) Lerp((int) color1.R, (int)color2.R, ammount);
col.G = (byte) Lerp((int) color1.G, (int)color2.G, ammount);
col.B = (byte) Lerp((int) color1.B, (int)color2.B, ammount);
col.A = (byte) Lerp((int) color1.A, (int)color2.A, ammount);

return col;
}

public static float InverseLerp(float from, float to, float value)
{
if (from < to)
Expand Down
74 changes: 53 additions & 21 deletions WpfTest/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:tk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:local="clr-namespace:WpfTest"
xmlns:uc="clr-namespace:WpfTest.UserControls"
mc:Ignorable="d"
Title="Global Exhange Rates app" Height="720" Width="1280" MinWidth="700" MinHeight="400">
<Window.Resources>
Expand All @@ -22,36 +23,67 @@
<Controls:MetroAnimatedTabControl Margin="50,165,50,50">
<TabItem Header="Live Chart">
<Grid>
<Label Content="Currencies" Width="180" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Margin="0,10,0,0" FontSize="18" HorizontalContentAlignment="Center"/>
<Label Content="Chart" VerticalAlignment="Top" Height="40" Margin="201,10,0,0" FontSize="18" HorizontalContentAlignment="Center"/>
<Border BorderThickness="2" BorderBrush="#FF000000" HorizontalAlignment="Stretch" Margin="200,50,0,0" >
<lvc:CartesianChart
<Grid VerticalAlignment="Top" Height="55" Margin="0,10,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="208"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Width="91" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,14,0,0" Content="Base currency:" FontSize="13" Height="27"/>
<ComboBox Grid.Column="0" Width="80" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="106,14,0,0" Height="27" Name="BaseCurrencyCombo" SelectionChanged="BaseCurrencyCombo_SelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Ellipse Fill="{Binding Color, Converter={StaticResource ColorConverter}}" Width="8" Height="8" Margin="0,2,5,2" />
<Label Content="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<ItemsControl Grid.Column="1" x:Name="ExchangeRateWatchersContainer" HorizontalContentAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<uc:ExchangeRateWatcher TargetCurrency="{Binding TargetCurrency}" BaseCurrency="{Binding BaseCurrency}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
<Grid Margin="0,55,0,0">
<Label Content="Currencies" Width="180" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Margin="0,10,0,0" FontSize="18" HorizontalContentAlignment="Center"/>
<Label Content="Chart" VerticalAlignment="Top" Height="40" Margin="201,10,0,0" FontSize="18" HorizontalContentAlignment="Center"/>
<Border BorderThickness="2" BorderBrush="#FF000000" HorizontalAlignment="Stretch" Margin="206,50,0,0" >
<lvc:CartesianChart
DisableAnimations="True" Name="currencyChart"
DataTooltip="{x:Null}"
AnimationsSpeed="0:0:0.15"
Zoom="Xy"
MouseWheel="CurrencyChart_MouseWheel"
MouseDown="CurrencyChart_MouseDown"
PreviewMouseWheel="CurrencyChart_MouseWheel">
<lvc:CartesianChart.AxisX>
<lvc:Axis Name="AxisX"/>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
</Border>
<lvc:CartesianChart.AxisX>
<lvc:Axis Name="AxisX"/>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
</Border>

<Border BorderThickness="2" BorderBrush="#FF000000" HorizontalAlignment="Left" Margin="0,50,0,0" VerticalAlignment="Stretch" Width="180" >
<ListView Name="currencyList">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Ellipse Fill="{Binding Color, Converter={StaticResource ColorConverter}}" Width="8" Height="8" Margin="0,2,5,2" />
<CheckBox Content="{Binding Name}" IsChecked="{Binding Enabled}" Checked="UpdateCurrenciesEnabledState" Unchecked="UpdateCurrenciesEnabledState"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Border BorderThickness="2" BorderBrush="#FF000000" HorizontalAlignment="Left" Margin="0,50,0,0" VerticalAlignment="Stretch" Width="186" >
<ListView Name="currencyList">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Ellipse Fill="{Binding Color, Converter={StaticResource ColorConverter}}" Width="8" Height="8" Margin="0,2,5,2" />
<CheckBox Content="{Binding Name}" IsChecked="{Binding Enabled}" Checked="UpdateCurrenciesEnabledState" Unchecked="UpdateCurrenciesEnabledState"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

</Border>
</Border>
</Grid>
</Grid>
</TabItem>
<TabItem Header="Exchange calculator" HorizontalAlignment="Center">
Expand Down
73 changes: 36 additions & 37 deletions WpfTest/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public MainWindow()

PopulateIntialChartData();

// Base currency combo
BaseCurrencyCombo.ItemsSource = Currencies;
BaseCurrencyCombo.SelectedItem = Currencies[0];

// Bind Echange rates combos
ExchangeFrom.ItemsSource = Currencies;
ExchangeTo.ItemsSource = Currencies;
Expand Down Expand Up @@ -216,20 +220,40 @@ private void InitializeCurrencies()

var symbolEUR = new CurrencySymbol() { Symbol = "€" };
var symbolUSD = new CurrencySymbol() { Symbol = "$", Location = SymbolLocation.Left };
var symbolGBP = new CurrencySymbol() { Symbol = "£", Location = SymbolLocation.Left };
var symbolBTC = new CurrencySymbol() { Symbol = "BTC" };
var symbolETR = new CurrencySymbol() { Symbol = "ETR" };

double trendEUR = ((double)random.Next(40, 60)) + random.NextDouble();
double trendUSD = ((double)random.Next(40, 60)) + random.NextDouble();
double trendGBP = ((double)random.Next(35, 55)) + random.NextDouble();
double trendBTC = ((double)random.Next(300, 400)) + random.NextDouble();
double trendETR = ((double)random.Next(200, 300)) + random.NextDouble();

mCurrencies.Add(new Currency() { Name = "EUR", Color = Colors.Blue, CurrentTrend = trendEUR, Volatility = 80, Symbol = symbolEUR });
mCurrencies.Add(new Currency() { Name = "USD", Color = Colors.Green, CurrentTrend = trendUSD, Volatility = 70, Symbol = symbolUSD });
mCurrencies.Add(new Currency() { Name = "BTC", Color = Colors.Orange, CurrentTrend = trendBTC, Volatility = 165, Symbol = symbolBTC });
mCurrencies.Add(new Currency() { Name = "ETR", Color = Colors.LightBlue, CurrentTrend = trendETR, Volatility = 150, Symbol = symbolETR });
var eur = new Currency() { Name = "EUR", Color = Colors.Blue, CurrentTrend = trendEUR, Volatility = 80, Symbol = symbolEUR };
var usd = new Currency() { Name = "USD", Color = Colors.Green, CurrentTrend = trendUSD, Volatility = 70, Symbol = symbolUSD };
var gbp = new Currency() { Name = "GBP", Color = Colors.Gray, CurrentTrend = trendGBP, Volatility = 90, Symbol = symbolGBP };
var btc = new Currency() { Name = "BTC", Color = Colors.Orange, CurrentTrend = trendBTC, Volatility = 165, Symbol = symbolBTC };
var etr = new Currency() { Name = "ETR", Color = Colors.LightBlue, CurrentTrend = trendETR, Volatility = 150, Symbol = symbolETR };

mCurrencies.Add(eur);
mCurrencies.Add(usd);
mCurrencies.Add(gbp);
mCurrencies.Add(btc);
mCurrencies.Add(etr);

Currencies = mCurrencies;

// Exchange Rate Watchers
var listRates = new List<CurrencyPair>(6);
listRates.Add(new CurrencyPair() { BaseCurrency = eur, TargetCurrency = usd });
listRates.Add(new CurrencyPair() { BaseCurrency = eur, TargetCurrency = btc });
listRates.Add(new CurrencyPair() { BaseCurrency = usd, TargetCurrency = btc });
listRates.Add(new CurrencyPair() { BaseCurrency = gbp, TargetCurrency = eur });
listRates.Add(new CurrencyPair() { BaseCurrency = usd, TargetCurrency = etr });
listRates.Add(new CurrencyPair() { BaseCurrency = eur, TargetCurrency = etr });

ExchangeRateWatchersContainer.ItemsSource = listRates;
}

private void ToggleSwitch_Checked(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -287,44 +311,19 @@ private void ExchangeDecimalValueChanged(object sender, RoutedPropertyChangedEve
{
UpdateEchangeConversion();
}
}

public class Currency
{
public string Name { get; set; }

public bool Enabled { get; set; } = true;

public Color Color { get; set; }

public double CurrentTrend { get; set; } = 0d;

public int Volatility { get; set; } = 50;

public Series ChartSerie { get; set; }

public CurrencySymbol Symbol { get; set; }

public string Format(double ammount)
private void BaseCurrencyCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(Symbol.Location == SymbolLocation.Left)
{
return String.Format("{0} {1:0.00}", Symbol.Symbol, ammount);
}
else
{
return String.Format("{0:0.00} {1}", ammount, Symbol.Symbol);
}
UpdateBaseCurrency((Currency)BaseCurrencyCombo.SelectedValue);
}

public class CurrencySymbol
private void UpdateBaseCurrency(Currency currentBase)
{
public enum SymbolLocation
{
Left, Right
}
public String Symbol { get; set; }
public SymbolLocation Location { get; set; } = SymbolLocation.Right;
var filteredCurrencies = Currencies.Where(c => c != currentBase);
currencyList.ItemsSource = filteredCurrencies;

var filteredSeries = Currencies.Where(c => c != currentBase).Select(c => c.ChartSerie);
currencyChart.Series = filteredSeries.AsSeriesCollection();
}
}
}
16 changes: 16 additions & 0 deletions WpfTest/UserControls/ExchangeRateWatcher.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<UserControl x:Class="WpfTest.UserControls.ExchangeRateWatcher"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfTest.UserControls"
mc:Ignorable="d"
d:DesignHeight="50" d:DesignWidth="162" Width="162">
<Border BorderThickness="1" BorderBrush="LightGray">
<Grid>
<Label Content="&#9650;" FontSize="16" Margin="5,3,0,3" HorizontalAlignment="Left" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Name="ArrowTextBlock"/>
<Label Content="76,00" FontSize="18" Margin="0,16,0,0" HorizontalAlignment="Center" Name="ValueLabel" Width="116" HorizontalContentAlignment="Center"/>
<Label Content="EUR / BTC" FontSize="12" Margin="0,0,0,25" HorizontalAlignment="Center" Name="CurrenciesLabel" Width="116" HorizontalContentAlignment="Center"/>
</Grid>
</Border>
</UserControl>
Loading

0 comments on commit 7607177

Please sign in to comment.