Ejemplo n.º 1
0
        /// <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 = "Percentage Books Read by Country With Time Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Percentage Books Read by Country With Time Plot");
            SetupPercentageBooksReadKeyVsTimeAxes(newPlot);

            // get the countries (in order)
            BooksDelta.DeltaTally latestTally = BooksReadProvider.BookDeltas.Last().OverallTally;
            List <string>         countries   = (from item in latestTally.CountryTotals
                                                 orderby item.Item2 descending
                                                 select item.Item1).ToList();

            // create the series for the languages
            List <KeyValuePair <string, LineSeries> > countriesSeries =
                new List <KeyValuePair <string, LineSeries> >();

            for (int i = 0; i < countries.Count; i++)
            {
                LineSeries countrySeries;
                OxyPlotUtilities.CreateLongLineSeries(
                    out countrySeries,
                    ChartAxisKeys.DateKey,
                    ChartAxisKeys.PercentageBooksReadKey,
                    countries[i],
                    i);
                countriesSeries.Add(new KeyValuePair <string, LineSeries>(countries[i], countrySeries));
            }

            // loop through the deltas adding points for each of the items
            foreach (BooksDelta delta in BooksReadProvider.BookDeltas)
            {
                double date = DateTimeAxis.ToDouble(delta.Date);
                foreach (KeyValuePair <string, LineSeries> countryLine in countriesSeries)
                {
                    double percentage = 0.0;
                    foreach (Tuple <string, uint, double, uint, double> countryTotal in delta.OverallTally.CountryTotals)
                    {
                        if (countryTotal.Item1 == countryLine.Key)
                        {
                            percentage = countryTotal.Item3;
                        }
                    }

                    countryLine.Value.Points.Add(new DataPoint(date, percentage));
                }
            }

            // add them to the plot
            foreach (KeyValuePair <string, LineSeries> countryItems in countriesSeries)
            {
                newPlot.Series.Add(countryItems.Value);
            }

            // finally update the model with the new plot
            return(newPlot);
        }
        /// <summary>
        /// Sets up the plot model to be displayed.
        /// </summary>
        /// <returns>The plot model.</returns>
        protected override PlotModel SetupPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Total Books Read by Language With Time Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Total Books Read by Language With Time Plot");
            SetupTotalBooksReadKeyVsTimeAxes(newPlot);

            // get the languages (in order)
            BooksDelta.DeltaTally latestTally = BooksReadProvider.BookDeltas.Last().OverallTally;
            List <string>         countries   = (from item in latestTally.CountryTotals
                                                 orderby item.Item2 descending
                                                 select item.Item1).ToList();

            // create the series for the languages
            List <KeyValuePair <string, LineSeries> > lineSeriesSet =
                new List <KeyValuePair <string, LineSeries> >();

            for (int i = 0; i < countries.Count; i++)
            {
                LineSeries series;
                OxyPlotUtilities.CreateLongLineSeries(out series,
                                                      ChartAxisKeys.DateKey, ChartAxisKeys.TotalBooksReadKey, countries[i], i, 128);
                lineSeriesSet.Add(
                    new KeyValuePair <string, LineSeries>(countries[i], series));
            }

            // loop through the deltas adding points for each of the items to the lines
            foreach (var delta in BooksReadProvider.BookDeltas)
            {
                var date = DateTimeAxis.ToDouble(delta.Date);
                foreach (var line in lineSeriesSet)
                {
                    double ttl = 0.0;
                    foreach (var langTotal in delta.OverallTally.CountryTotals)
                    {
                        if (langTotal.Item1 == line.Key)
                        {
                            ttl = langTotal.Item2;
                        }
                    }
                    line.Value.Points.Add(new DataPoint(date, ttl));
                }
            }

            IList <LineSeries> lineSeries =
                (from item in lineSeriesSet select item.Value).ToList();
            var stackSeries = OxyPlotUtilities.StackLineSeries(lineSeries);

            // add them to the plot
            foreach (var areaSeries in stackSeries)
            {
                newPlot.Series.Add(areaSeries);
            }

            // finally update the model with the new plot
            return(newPlot);
        }
        private PlotModel SetupPercentageBooksReadByLanguagePlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Percentage Books Read by Language With Time Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Percentage Books Read by Language With Time Plot");
            SetupPercentageBooksReadKeyVsTimeAxes(newPlot);

            // get the languages (in order)
            BooksDelta.DeltaTally latestTally = _mainModel.BookDeltas.Last().OverallTally;
            List <string>         languages   = (from item in latestTally.LanguageTotals
                                                 orderby item.Item2 descending
                                                 select item.Item1).ToList();

            // create the series for the languages
            List <KeyValuePair <string, LineSeries> > languagesSeries =
                new List <KeyValuePair <string, LineSeries> >();

            for (int i = 0; i < languages.Count; i++)
            {
                LineSeries languageSeries;
                OxyPlotUtilities.CreateLongLineSeries(out languageSeries,
                                                      ChartAxisKeys.DateKey, ChartAxisKeys.PercentageBooksReadKey, languages[i], i);
                languagesSeries.Add(
                    new KeyValuePair <string, LineSeries>(languages[i], languageSeries));
            }

            // loop through the deltas adding points for each of the items
            foreach (var delta in _mainModel.BookDeltas)
            {
                var date = DateTimeAxis.ToDouble(delta.Date);
                foreach (var languageLine in languagesSeries)
                {
                    double percentage = 0.0;
                    foreach (var langTotal in delta.OverallTally.LanguageTotals)
                    {
                        if (langTotal.Item1 == languageLine.Key)
                        {
                            percentage = langTotal.Item3;
                        }
                    }
                    languageLine.Value.Points.Add(new DataPoint(date, percentage));
                }
            }

            // add them to the plot
            foreach (var languagesItems in languagesSeries)
            {
                newPlot.Series.Add(languagesItems.Value);
            }

            // finally update the model with the new plot
            return(newPlot);
        }
Ejemplo n.º 4
0
        private void SetupPartiesLineSeries(
            string[] partiesNames,
            List <KeyValuePair <string, LineSeries> > partiesLineSeries,
            bool interpolated = false)
        {
            for (int i = 0; i < partiesNames.Length; i++)
            {
                int colorIndex = SetupPartNameAndColor(partiesNames, i);

                LineSeries partyLineSeries;
                if (!interpolated)
                {
                    OxyPlotUtilities.CreateLongLineSeries(
                        out partyLineSeries,
                        ChartAxisKeys.DateKey,
                        ChartAxisKeys.PercentageListVotes,
                        partiesNames[i],
                        colorIndex,
                        175,
                        strokeThickness: 3);
                }
                else
                {
                    OxyPlotUtilities.CreateLongLineSeries(
                        out partyLineSeries,
                        ChartAxisKeys.DateKey,
                        ChartAxisKeys.PercentageListVotes,
                        partiesNames[i],
                        colorIndex,
                        125,
                        strokeThickness: 2,
                        includeInLegend: false);
                }

                partiesLineSeries.Add(
                    new KeyValuePair <string, LineSeries>(partiesNames[i], partyLineSeries));
            }
        }