Example #1
0
        /// #########################################################################################
        ///  Update a card's charts
        private async Task UpdateCard(int i)
        {
            try {
                string crypto = App.pinnedCoins[i];
                vm.PriceCards[i].Info.CurrencySym = App.currencySymbol;

                /// Save the current timeSpan for navigating to another page
                vm.PriceCards[i].Chart.TimeSpan = timeSpan;

                /// Colors
                var brush = vm.PriceCards[i].Chart.ChartStroke;
                brush = ColorConstants.GetCoinBrush(crypto);
                vm.PriceCards[i].Chart.ChartStroke = brush;

                /// Get Historic and create List of ChartData for the chart
                var histo = await Ioc.Default.GetService <ICryptoCompare>().GetHistoric_(crypto, timeUnit, limit, aggregate);

                var chartData = new List <ChartPoint>();
                foreach (var h in histo)
                {
                    chartData.Add(new ChartPoint()
                    {
                        Date   = h.DateTime,
                        Value  = h.Average,
                        Volume = h.volumeto,
                        High   = h.high,
                        Low    = h.low,
                        Open   = h.open,
                        Close  = h.close
                    });
                }
                vm.PriceCards[i].Chart.ChartData = chartData;
                var temp = GraphHelper.AdjustLinearAxis(new ChartStyling(), timeSpan);
                vm.PriceCards[i].Chart.LabelFormat   = temp.LabelFormat;
                vm.PriceCards[i].Chart.Minimum       = temp.Minimum;
                vm.PriceCards[i].Chart.MajorStepUnit = temp.MajorStepUnit;
                vm.PriceCards[i].Chart.MajorStep     = temp.MajorStep;
                vm.PriceCards[i].Chart.TickInterval  = temp.TickInterval;

                /// Calculate min-max to adjust axis
                var MinMax = GraphHelper.GetMinMaxOfArray(chartData.Select(d => d.Value).ToList());
                vm.PriceCards[i].Chart.PricesMinMax = GraphHelper.OffsetMinMaxForChart(MinMax.Min, MinMax.Max);
                vm.PriceCards[i].Chart.VolumeMax    = GraphHelper.GetMaxOfVolume(chartData);

                /// Calculate the price difference
                double oldestPrice = histo[0].Average;
                double newestPrice = histo[histo.Count - 1].Average;
                vm.PriceCards[i].Info.Prices = (oldestPrice, newestPrice);

                /// Sum total volume from historic
                vm.PriceCards[i].Info.VolumeToTotal   = histo.Sum(h => h.volumeto);
                vm.PriceCards[i].Info.VolumeFromTotal = histo.Sum(h => h.volumefrom);
                double total = histo.Sum(h => h.volumeto);

                /// Show that loading is done
                vm.PriceCards[i].Info.IsLoading = false;
            } catch (Exception) {  }
        }
Example #2
0
        private async Task UpdateCoin()
        {
            var crypto = vm.Coin.Name;

            vm.CurrencySymbol = Currencies.GetCurrencySymbol(App.currency);

            /// Colors
            vm.Chart.ChartStroke = ColorConstants.GetCoinBrush(crypto);

            /// Get Historic and create List of ChartData for the chart (plus LinearAxis)
            var histo = await Ioc.Default.GetService <ICryptoCompare>().GetHistoric_(crypto, timeUnit, limit, aggregate);

            var chartData = new List <ChartPoint>();

            foreach (var h in histo)
            {
                chartData.Add(new ChartPoint()
                {
                    Date   = h.DateTime,
                    Value  = h.Average,
                    Volume = h.volumeto,
                    High   = h.high,
                    Low    = h.low,
                    Open   = h.open,
                    Close  = h.close
                });
            }
            vm.Chart.ChartData = chartData;
            var temp = GraphHelper.AdjustLinearAxis(new ChartStyling(), timeSpan);

            vm.Chart.LabelFormat   = temp.LabelFormat;
            vm.Chart.Minimum       = temp.Minimum;
            vm.Chart.MajorStepUnit = temp.MajorStepUnit;
            vm.Chart.MajorStep     = temp.MajorStep;
            vm.Chart.TickInterval  = temp.TickInterval;

            vm.Coin.VolumeToTotal = histo.Sum(x => x.volumeto);

            /// Calculate min-max to adjust axis
            var MinMax = GraphHelper.GetMinMaxOfArray(chartData.Select(d => d.Value).ToList());

            vm.Chart.PricesMinMax = GraphHelper.OffsetMinMaxForChart(MinMax.Min, MinMax.Max);
            vm.Chart.VolumeMax    = GraphHelper.GetMaxOfVolume(chartData);

            /// Calculate the price difference
            double oldestPrice = histo.FirstOrDefault()?.Average ?? 0;
            double newestPrice = histo.LastOrDefault()?.Average ?? 0;

            vm.Coin.Prices = (oldestPrice, newestPrice);

            vm.Coin.IsLoading = false;
        }
Example #3
0
        /// <summary>
        /// Generates the a Secondary Tile's background
        /// </summary>
        internal static async Task <Grid> SecondaryTileGrid(string crypto, List <HistoricPrice> hist = null)
        {
            var grid = new Grid()
            {
                Background = new SolidColorBrush(Color.FromArgb(0, 128, 128, 128)),
                Width      = 300,
                Height     = 150,
            };

            try {
                if (hist == null)
                {
                    hist = await Ioc.Default.GetService <ICryptoCompare>().GetHistoric_(crypto, "hour", 168);
                }

                var polyline = new Polyline();
                polyline.Stroke            = ColorConstants.GetCoinBrush(crypto);
                polyline.Fill              = ColorConstants.GetCoinBrush(crypto, 50);
                polyline.FillRule          = FillRule.Nonzero;
                polyline.StrokeThickness   = 1.5;
                polyline.VerticalAlignment = VerticalAlignment.Bottom;

                var    points  = new PointCollection();
                int    i       = 0;
                var    ordered = hist.OrderByDescending(x => x.Average);
                double min     = ordered.LastOrDefault().Average;
                double max     = ordered.FirstOrDefault().Average;
                foreach (var h in hist.GetRange(hist.Count - 150, 150))
                {
                    points.Add(new Point(2 * ++i, 90 - (90 * ((h.Average - min) / (max - min)))));
                }
                points.Add(new Point(2 * i, 90));
                points.Add(new Point(0, 90));
                polyline.Points            = points;
                polyline.VerticalAlignment = VerticalAlignment.Bottom;


                grid.Children.Add(polyline);
                return(grid);
            }
            catch (Exception ex) {
                Analytics.TrackEvent("SecondaryTileGrid-error",
                                     new Dictionary <string, string>()
                {
                    { "Exception", ex.Message }
                });
                return(grid);
            }
        }
 protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
 {
     vm.Chart.ChartStroke = ColorConstants.GetCoinBrush(vm.Info.Name);
 }