private void AddCountriesForMap(PlotModel newPlot) { foreach (CountryGeography country in GeographyProvider.CountryGeographies) { if (country?.LandBlocks == null || !country.LandBlocks.Any()) { continue; } int i = 0; IOrderedEnumerable <PolygonBoundary> landBlocks = country.LandBlocks.OrderByDescending(b => b.TotalArea); foreach (PolygonBoundary boundary in landBlocks) { AreaSeries areaSeries = new AreaSeries { Color = OxyColors.LightGreen, Title = country.Name, RenderInLegend = false }; 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); } newPlot.Series.Add(areaSeries); // just do the 10 biggest bits per country (looks to be enough) i++; if (i > 10) { break; } } } }
private void AddCountriesForMap(PlotModel newPlot) { foreach (var country in _mainModel.CountryGeographies) { int i = 0; var landBlocks = country.LandBlocks.OrderByDescending(b => b.TotalArea); foreach (var boundary in landBlocks) { var areaSeries = new AreaSeries { Color = OxyColors.LightGreen, Title = country.Name, RenderInLegend = false }; var points = boundary.Points; if (points.Count > PolygonReducer.MaxPolygonPoints) { points = PolygonReducer.AdaptativePolygonReduce(points, PolygonReducer.MaxPolygonPoints); } foreach (var point in points) { double ptX = 0; double ptY = 0; point.GetCoordinates(out ptX, out ptY); DataPoint dataPoint = new DataPoint(ptX, ptY); areaSeries.Points.Add(dataPoint); } newPlot.Series.Add(areaSeries); // just do the 10 biggest bits per country (looks to be enough) i++; if (i > 10) { break; } } } }
/// <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); }