Exemplo n.º 1
0
        public List <SelectedCountry> BuildInteractiveObject()
        {
            List <Country>         countriesSeen     = new List <Country>();
            List <string>          countriesObject   = new List <string>();
            List <SelectedCountry> countriesSelected = new List <SelectedCountry>();
            var         userCurrentUser = User.Identity.Name;
            UserProfile selectedUser;

            selectedUser = _context.UserProfile.Where(p => p.Email == User.Identity.Name).Single();
            var countryFound = _context.CountriesVisited.Where(c => c.UserId == selectedUser.Id).ToList();

            foreach (CountryVisited cv in countryFound)
            {
                Country countryFoundCountry = _context.Countries.Where(c => c.Name == cv.CountryName).Single();
                countriesSeen.Add(countryFoundCountry);
            }
            foreach (Country co in countriesSeen)
            {
                SelectedCountry addCountry = new SelectedCountry();
                addCountry.id             = co.Code;
                addCountry.showAsSelected = true;
                countriesSelected.Add(addCountry);
            }
            return(countriesSelected);
        }
Exemplo n.º 2
0
        private void UpdatePlot()
        {
            var pm = new PlotModel(this.year.ToString(), "data from gapminder.org")
            {
                LegendPosition = LegendPosition.RightBottom
            };
            var ss = new ScatterSeries
            {
                MarkerType            = MarkerType.Circle,
                MarkerFill            = OxyColors.Transparent,
                MarkerStroke          = OxyColors.Blue,
                MarkerStrokeThickness = 1
            };

            var piX     = typeof(Statistics).GetProperty("GdpPerCapitaPpp");
            var piY     = typeof(Statistics).GetProperty("LifeExpectancyAtBirth");
            var piSize  = typeof(Statistics).GetProperty("Population");
            var piColor = typeof(Statistics).GetProperty("GeographicRegion");

            foreach (var kvp in Countries)
            {
                Country country = kvp.Value;
                double  x       = country.FindValue(year, piX);
                double  y       = country.FindValue(year, piY);
                double  size    = country.FindValue(year, piSize);

                if (double.IsNaN(x) || double.IsNaN(y))
                {
                    continue;
                }
                ss.Points.Add(new ScatterPoint(x, y, double.NaN, double.NaN, country.Name));

                //double radius = 4;
                //if (!double.IsNaN(size))
                //    radius = Math.Sqrt(size)*0.1;
                //if (radius < 4) radius = 4;
                //if (radius > 40) radius = 40;
                //ss.MarkerSizes.Add(radius);
                //   Debug.WriteLine(countryName+": "+stats.Population);
            }
            pm.Series.Add(ss);
            if (SelectedCountry != null)
            {
                var ls = new LineSeries(SelectedCountry.Name);
                ls.LineJoin = OxyPenLineJoin.Bevel;
                foreach (var p in SelectedCountry.Statistics)
                {
                    if (double.IsNaN(p.GdpPerCapitaPpp) || double.IsNaN(p.LifeExpectancyAtBirth))
                    {
                        continue;
                    }
                    ls.Points.Add(new DataPoint(p.GdpPerCapitaPpp, p.LifeExpectancyAtBirth));
                }
                pm.Series.Add(ls);
                var    ss2 = new ScatterSeries();
                double x   = SelectedCountry.FindValue(year, piX);
                double y   = SelectedCountry.FindValue(year, piY);
                ss2.Points.Add(new ScatterPoint(x, y, 10));
                ss2.MarkerFill = OxyColor.FromAColor(120, OxyColors.Red);
                ss2.MarkerType = MarkerType.Circle;
                pm.Series.Add(ss2);
            }
            pm.Axes.Add(new LinearAxis(AxisPosition.Left, 19, 87, "Life expectancy (years)"));
            pm.Axes.Add(new LogarithmicAxis(AxisPosition.Bottom, 200, 90000, "Income per person (GDP/capita, PPP$ inflation-adjusted)"));
            PlotModel = pm;
        }