コード例 #1
0
        private void SetupPagesByCountryModel()
        {
            Model3DGroup modelGroup = new Model3DGroup();

            // get the range of colours for the for the countries

            // set up lookups of the countries with numbers read
            int maxBooksPages;
            int maxBooksLogPages;
            Dictionary <string, long> countryToReadLookUp;
            Dictionary <string, uint> countryToPagesLookUp;
            Dictionary <string, uint> countryToLogPagesLookUp;

            SetupCountyPagesLookups(out maxBooksPages, out maxBooksLogPages,
                                    out countryToReadLookUp, out countryToPagesLookUp, out countryToLogPagesLookUp);
            _countryToLogPagesLookUp = countryToLogPagesLookUp;

            // set up a palette based on this
            List <OxyColor> colors;
            OxyPalette      faintPalette;
            uint            numColours = 1 + countryToLogPagesLookUp.Values.OrderByDescending(x => x).FirstOrDefault();

            OxyPlotUtilities.SetupFaintPaletteForRange((int)numColours, out colors, out faintPalette, 128);

            List <OxyColor> stdColors      = OxyPlotUtilities.SetupStandardColourSet();
            int             geographyIndex = 0;

            foreach (var authorCountry in _mainModel.AuthorCountries.OrderByDescending(x => x.TotalBooksReadFromCountry))
            {
                var name    = authorCountry.Country;
                var country = _mainModel.Nations.Where(w => w.Name == name).FirstOrDefault();
                if (country != null)
                {
                    AddNationPagesPins(modelGroup, colors, authorCountry, name, country);
                }

                if (_mainModel.Nations != null && _mainModel.Nations.Count > 0)
                {
                    geographyIndex = AddNationsCountryGeographyPlane(modelGroup, stdColors, geographyIndex, name);
                }
            }

            AddGeographiesForNationsWithoutBooksRead(modelGroup);

            PagesByCountryModel = modelGroup;
        }
        private PlotModel SetupWorldCountriesMapPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Countries of the World and Books Read"
            };

            SetupLatitudeAndLongitudeAxes(newPlot);

            // make up a lit of the countries with books read
            int maxBooksRead = -1;
            Dictionary <string, int> countryToReadLookUp = new Dictionary <string, int>();

            foreach (var authorCountry in _mainModel.AuthorCountries)
            {
                maxBooksRead = Math.Max(authorCountry.TotalBooksReadFromCountry, maxBooksRead);
                countryToReadLookUp.Add(authorCountry.Country, authorCountry.TotalBooksReadFromCountry);
            }
            List <OxyColor> colors;
            OxyPalette      faintPalette;

            maxBooksRead =
                OxyPlotUtilities.SetupFaintPaletteForRange(maxBooksRead, out colors, out faintPalette, 128);

            foreach (Models.Database.Nation nation in _mainModel.Nations)
            {
                Models.Geography.CountryGeography country = nation.Geography;
                if (country != null)
                {
                    AddCountryGeographyToPlot(newPlot, countryToReadLookUp, colors, country);
                }
            }

            newPlot.Axes.Add(new LinearColorAxis
            {
                Position = AxisPosition.Right, Palette = faintPalette, Title = "Books Read", Maximum = maxBooksRead, Minimum = 0
            });

            // finally update the model with the new plot
            return(newPlot);
        }
コード例 #3
0
        private void SetupBooksReadByCountryModel()
        {
            Model3DGroup modelGroup = new Model3DGroup();

            // get the range of colours for the for the countries
            int range = _mainModel.AuthorCountries.Count > 0 ?
                        _mainModel.AuthorCountries.Select(s => s.TotalBooksReadFromCountry).Max() : 5;
            OxyPalette      faintPalette;
            List <OxyColor> colors;

            OxyPlotUtilities.SetupFaintPaletteForRange(range, out colors, out faintPalette, 128);

            List <OxyColor> stdColors      = OxyPlotUtilities.SetupStandardColourSet();
            int             geographyIndex = 0;

            foreach (var authorCountry in _mainModel.AuthorCountries.OrderByDescending(x => x.TotalBooksReadFromCountry))
            {
                var name    = authorCountry.Country;
                var country = _mainModel.WorldCountries.Where(w => w.Country == name).FirstOrDefault();
                if (country != null)
                {
                    AddCountryBooksEllipsoid(modelGroup, colors, authorCountry, name, country);
                }

                if (_mainModel.CountryGeographies != null && _mainModel.CountryGeographies.Count > 0)
                {
                    geographyIndex = AddCountryGeographyPlane(modelGroup, stdColors, geographyIndex, name);
                }
            }

            AddGeographiesForCountriesWithoutBooksRead(modelGroup);

            double       maxHeight = Math.Log(range);
            TubeVisual3D path      = GetPathForMeanReadingLocation(maxHeight);

            modelGroup.Children.Add(path.Content);

            BooksReadByCountryModel = modelGroup;
        }
        /// <summary>
        /// Sets up the plot model to be displayed.
        /// </summary>
        /// <returns>The plot model.</returns>
        protected override PlotModel SetupPlot()
        {
            // Create the plot model
            PlotModel newPlot = new PlotModel {
                Title = "Countries of the World with Pages read"
            };

            SetupLatitudeAndLongitudeAxes(newPlot);

            // make up a lit of the countries with books read
            int maxBooksPages    = 0;
            int maxBooksLogPages = 0;
            Dictionary <string, long> countryToReadLookUp     = new Dictionary <string, long>();
            Dictionary <string, uint> countryToPagesLookUp    = new Dictionary <string, uint>();
            Dictionary <string, uint> countryToLogPagesLookUp = new Dictionary <string, uint>();

            foreach (AuthorCountry authorCountry in BooksReadProvider.AuthorCountries)
            {
                int totalPagesInThousands = (int)((long)authorCountry.TotalPagesReadFromCountry / 1000);
                if (totalPagesInThousands < 1)
                {
                    totalPagesInThousands = 1;
                }

                double ttl =
                    (authorCountry.TotalPagesReadFromCountry > 1)
                    ? authorCountry.TotalPagesReadFromCountry : 10;
                uint logPages = (uint)(10.0 * Math.Log10(ttl));

                maxBooksPages    = Math.Max(totalPagesInThousands, maxBooksPages);
                maxBooksLogPages = Math.Max((int)logPages, maxBooksLogPages);
                countryToReadLookUp.Add(authorCountry.Country, totalPagesInThousands);
                countryToPagesLookUp.Add(authorCountry.Country, authorCountry.TotalPagesReadFromCountry);
                countryToLogPagesLookUp.Add(authorCountry.Country, logPages - 10);
            }

            List <OxyColor> colors;
            OxyPalette      faintPalette;

            maxBooksPages =
                OxyPlotUtilities.SetupFaintPaletteForRange(maxBooksLogPages, out colors, out faintPalette, 128);

            foreach (CountryGeography country in GeographyProvider.CountryGeographies)
            {
                if (country?.Name == null)
                {
                    continue;
                }

                OxyColor color     = OxyColors.LightGray;
                string   tagString = "";

                if (countryToReadLookUp.ContainsKey(country.Name))
                {
                    color     = colors[(int)countryToLogPagesLookUp[country.Name]];
                    tagString = "\nPages Read = " + countryToPagesLookUp[country.Name].ToString();
                }

                int i = 0;

                // just do the 5 biggest bits per country (looks enough)
                foreach (PolygonBoundary boundary in country.LandBlocks.OrderByDescending(b => b.TotalArea))
                {
                    AreaSeries areaSeries = new AreaSeries
                    {
                        Color          = color,
                        Title          = country.Name,
                        RenderInLegend = false,
                        Tag            = tagString
                    };

                    List <PolygonPoint> points = boundary.Points;
                    if (points.Count > PolygonReducer.MaxPolygonPoints)
                    {
                        points = PolygonReducer.AdaptativePolygonReduce(points, PolygonReducer.MaxPolygonPoints);
                    }

                    foreach (PolygonPoint point in points)
                    {
                        double ptX;
                        double ptY;
                        point.GetCoordinates(out ptX, out ptY);
                        DataPoint dataPoint = new DataPoint(ptX, ptY);

                        areaSeries.Points.Add(dataPoint);
                    }

                    areaSeries.TrackerFormatString = "{0}\nLat/Long ( {4:0.###} ,{2:0.###} )" + tagString;
                    newPlot.Series.Add(areaSeries);

                    i++;
                    if (i > 10)
                    {
                        break;
                    }
                }
            }

            newPlot.Axes.Add(new LinearColorAxis {
                Position = AxisPosition.Right, Palette = faintPalette, Title = "Thousand Pages Read",
                Maximum  = maxBooksPages, Minimum = 0
            });

            // finally update the model with the new plot
            return(newPlot);
        }