Example #1
0
        public Highcharts GuildKillTimers(int bossFightId, int difficultyId)
        {
            const string graphTitle = "Kill times by guild";

            var guildKillTimes = _encounterRepository.GetDateSortedKills(bossFightId, difficultyId);

            #region Build chart series
            // Determine the guild IDs of those we wish to show by default.
            // Default this chart to the 4 guilds with the lowest kill times
            var visibleGuildIds = new List <int>();
            var lowestTimeList  = guildKillTimes.OrderBy(s => s.Duration.TotalSeconds);
            foreach (var guildKill in lowestTimeList.TakeWhile(kill => visibleGuildIds.Count != 4))
            {
                if (!visibleGuildIds.Contains((int)guildKill.GuildId))
                {
                    visibleGuildIds.Add((int)guildKill.GuildId);
                }
            }
            var seriesList = new List <Series>();
            var killGroup  = guildKillTimes.OrderBy(g => g.UploadGuild.Name).GroupBy(e => new { e.GuildId, e.UploadGuild.Name });
            foreach (var guildKillGroup in killGroup)
            {
                var thisSeries = new Series {
                    Name = guildKillGroup.Key.Name.Replace("'", "\\\'")
                };

                thisSeries.PlotOptionsSpline = visibleGuildIds.Contains((int)guildKillGroup.Key.GuildId)
                    ? new PlotOptionsSpline()
                {
                    Visible = true
                }
                    : new PlotOptionsSpline()
                {
                    Visible = false
                };

                thisSeries.Data = new Data(guildKillGroup.Select(guildKill => new object[] { guildKill.Date, guildKill.Duration.TotalSeconds }).ToArray());
                seriesList.Add(thisSeries);
            }

            var seriesArray = seriesList.ToArray();
            #endregion

            var chart =
                new Highcharts(string.Format("bf{0}f{1}gkt", bossFightId, difficultyId))
                .InitChart(new Chart
            {
                DefaultSeriesType = ChartTypes.Spline,
                ZoomType          = ZoomTypes.Xy,
                Height            = 400,
                BackgroundColor   = new BackColorOrGradient(new Gradient
                {
                    LinearGradient = new[] { 0, 0, 0, 400 },
                    Stops          = new object[, ]
                    {
                        { 0, Color.FromArgb(13, 255, 255, 255) },
                        { 1, Color.FromArgb(13, 255, 255, 255) }
                    }
                }),
                Style = ChartColors.WhiteTextStyle
            })
                .SetCredits(ChartDefaults.Credits)
                .SetOptions(new GlobalOptions
            {
                Colors = ChartColors.ColorArray(),
                Global = new Global {
                    UseUTC = false
                }
            })
                .SetTitle(new Title
            {
                Text  = graphTitle,
                Style = ChartColors.WhiteTextStyle
            })
                .SetXAxis(new XAxis
            {
                Type = AxisTypes.Datetime,
                DateTimeLabelFormats = new DateTimeLabel {
                    Month = "%e %b", Year = "%e %b", Day = "%e %b", Week = "%e %b"
                },
                LineColor = Color.White,
                TickColor = Color.White,
                Labels    = new XAxisLabels {
                    Style = ChartColors.WhiteTextStyle
                },
            })
                .SetYAxis(new YAxis
            {
                Title = new YAxisTitle {
                    Text = "Encounter length (seconds)", Style = ChartColors.WhiteTextStyle
                },
                //Min = 0
                TickColor = Color.White,
                LineColor = Color.White,
                Labels    = new YAxisLabels {
                    Style = ChartColors.WhiteTextStyle
                },
            })
                .SetSeries(seriesArray)
                .SetExporting(new Exporting {
                Enabled = false
            })
                .SetLegend(new Legend()
            {
                ItemStyle = ChartColors.WhiteTextStyle, ItemHoverStyle = "color: '#bbb'"
            })
            ;
            return(chart);
        }