public void LoadEntries(bool refresh = false)
 {
     if (Entries.Count() == 0 || refresh)
     {
         this.LoadEntries(ContentFul.Client.Instance);
     }
 }
Ejemplo n.º 2
0
        public override void DrawContent(SKCanvas canvas, int width, int height)
        {
            if (Entries != null)
            {
                var sumValue    = Entries.Where(x => x.Value.HasValue).Sum(x => Math.Abs(x.Value.Value));
                var radius      = (Math.Min(width, height) - (2 * Margin)) / 2;
                var cx          = width / 2;
                var cy          = height / 2;
                var lineWidth   = (LineSize < 0) ? (radius / ((Entries.Count() + 1) * 2)) : LineSize;
                var radiusSpace = lineWidth * 2;

                for (int i = 0; i < Entries.Count(); i++)
                {
                    var entry = Entries.ElementAt(i);

                    //Skip the ring if it has a null value
                    if (!entry.Value.HasValue)
                    {
                        continue;
                    }

                    var entryRadius = (i + 1) * radiusSpace;
                    DrawGaugeArea(canvas, entry, entryRadius, cx, cy, lineWidth);
                    DrawGauge(canvas, entry.Color, entry.Value.Value, entryRadius, cx, cy, lineWidth);
                }

                //Make sure captions draw on top of chart
                DrawCaption(canvas, width, height);
            }
        }
Ejemplo n.º 3
0
 public ListViewModel(IEnumerable <T> entries, int totalCount = -1, int page = 1, int entriesPerPage = 10)
 {
     Entries        = entries ?? new List <T>();
     TotalCount     = totalCount == -1 ? Entries.Count() : totalCount;
     Page           = page;
     EntriesPerPage = entriesPerPage;
 }
Ejemplo n.º 4
0
        private void DrawCaptionLeftAndRight(SKCanvas canvas, int width, int height, bool isGraphCentered)
        {
            var sumValue    = Entries.Sum(x => Math.Abs(x.Value));
            var rightValues = new List <ChartEntry>();
            var leftValues  = new List <ChartEntry>();
            int i           = 0;
            var current     = 0.0f;

            while (i < Entries.Count() && (current < sumValue / 2))
            {
                var entry = Entries.ElementAt(i);
                rightValues.Add(entry);
                current += Math.Abs(entry.Value);
                i++;
            }

            while (i < Entries.Count())
            {
                var entry = Entries.ElementAt(i);
                leftValues.Add(entry);
                i++;
            }

            leftValues.Reverse();

            DrawCaptionElements(canvas, width, height, rightValues, false, isGraphCentered);
            DrawCaptionElements(canvas, width, height, leftValues, true, isGraphCentered);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Draws the value bars.
        /// </summary>
        /// <param name="canvas">The canvas.</param>
        /// <param name="points">The points.</param>
        /// <param name="itemSize">The item size.</param>
        /// <param name="origin">The origin.</param>
        /// <param name="headerHeight">The Header height.</param>
        protected void DrawBars(SKCanvas canvas, SKPoint[] points, SKSize itemSize, float origin, float headerHeight)
        {
            if (points.Length > 0)
            {
                for (int i = 0; i < Entries.Count(); i++)
                {
                    var entry = Entries.ElementAt(i);
                    var point = points[i];

                    using (var paint = new SKPaint
                    {
                        Style = SKPaintStyle.Fill,
                        Color = entry.Color,
                    })
                    {
                        var x      = point.X - (itemSize.Width / 2);
                        var y      = Math.Min(origin, point.Y);
                        var height = Math.Max(MinBarHeight, Math.Abs(origin - point.Y));
                        if (height < MinBarHeight)
                        {
                            height = MinBarHeight;
                            if (y + height > Margin + itemSize.Height)
                            {
                                y = headerHeight + itemSize.Height - height;
                            }
                        }

                        var rect = SKRect.Create(x, y, itemSize.Width, height);
                        canvas.DrawRect(rect, paint);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Рисуем лэйблы
        /// </summary>
        protected void DrawLabels(SKCanvas canvas, SKPoint[] points, SKSize itemSize, int height, float footerHeight)
        {
            // Проходим по записям диаграммы
            for (var i = 0; i < Entries.Count(); i++)
            {
                // Получаем запись
                var entry = Entries.ElementAt(i);
                var point = points[i];

                // Если лейбл не пустой
                if (!string.IsNullOrEmpty(entry.Label))
                {
                    using (var paint = new SKPaint())
                    {
                        // Настраиваем свойства рисования
                        paint.TextSize    = GreenChartLabelTextSize;
                        paint.IsAntialias = true;
                        paint.Color       = entry.TextColor;
                        paint.IsStroke    = false;

                        // Отступы
                        var bounds = new SKRect();
                        // Текст
                        var text = entry.Label;
                        // Измеряем текст
                        paint.MeasureText(text, ref bounds);

                        // Рисуем текст
                        canvas.DrawText(text, point.X - (bounds.Width / 2), height - Margin + (GreenChartLabelTextSize / 2), paint);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        protected void DrawLabels(SKCanvas canvas, SKPoint[] points, SKSize itemSize, int height, float footerHeight)
        {
            for (int i = 0; i < Entries.Count(); i++)
            {
                var entry = Entries.ElementAt(i);
                var point = points[i];

                if (!string.IsNullOrEmpty(entry.Label))
                {
                    using (var paint = new SKPaint())
                    {
                        paint.TextSize    = GreenChartLabelTextSize;
                        paint.IsAntialias = true;
                        paint.Color       = entry.TextColor;
                        paint.IsStroke    = false;

                        var bounds = new SKRect();
                        var text   = entry.Label;
                        paint.MeasureText(text, ref bounds);

                        canvas.DrawText(text, point.X - (bounds.Width / 2), height - Margin + (GreenChartLabelTextSize / 2), paint);
                    }
                }
            }
        }
        void DrawCaption(SKCanvas canvas, int width, int height)
        {
            var sumValue    = Entries.Sum(x => Math.Abs(x.Value));
            var rightValues = new List <Entry>();
            var leftValues  = new List <Entry>();

            var i       = 0;
            var current = 0.0f;

            while (i < Entries.Count() && (current < sumValue / 2))
            {
                var entry = Entries.ElementAt(i);
                rightValues.Add(entry);
                current += Math.Abs(entry.Value);
                i++;
            }

            while (i < Entries.Count())
            {
                var entry = Entries.ElementAt(i);
                leftValues.Add(entry);
                i++;
            }

            leftValues.Reverse();

            DrawCaptionElements(canvas, width, height, rightValues, false);
            DrawCaptionElements(canvas, width, height, leftValues, true);
        }
        public override void DrawContent(SKCanvas canvas, int width, int height)
        {
            DrawCaption(canvas, width, height);
            using (new SKAutoCanvasRestore(canvas))
            {
                canvas.Translate(width / 2, height / 2);
                var sumValue = Entries.Sum(x => Math.Abs(x.Value));
                var radius   = (Math.Min(width, height) - (2 * Margin)) / 2;

                var start = 0.0f;
                for (var i = 0; i < Entries.Count(); i++)
                {
                    var entry = Entries.ElementAt(i);
                    var end   = start + (Math.Abs(entry.Value) / sumValue);

                    var path = RadialHelpers.CreateSectorPath(start, end, radius, radius - HoleRadius);
                    using (var paint = new SKPaint
                    {
                        Style = SKPaintStyle.Fill,
                        Color = entry.Color,
                        IsAntialias = true,
                    })
                    {
                        canvas.DrawPath(path, paint);
                    }

                    start = end;
                }
            }
        }
Ejemplo n.º 10
0
        protected SKSize CalculateItemSize(int width, int height, float footerHeight, float headerHeight)
        {
            var total = Entries.Count();
            var w     = (width - ((total + 1) * Margin)) / total;
            var h     = height - Margin - footerHeight - headerHeight;

            return(new SKSize(w, h));
        }
        public ChessBoardHistoryEntry Next()
        {
            if (Plies == Entries.Count() - 1)
            {
                return(null);
            }

            return(Entries[Plies + 1]);
        }
Ejemplo n.º 12
0
        private void DrawCaption(SKCanvas canvas, int width, int height)
        {
            var rightValues = Entries.Take(Entries.Count() / 2).ToList();
            var leftValues  = Entries.Skip(rightValues.Count()).ToList();

            leftValues.Reverse();

            DrawCaptionElements(canvas, width, height, rightValues, false, false);
            DrawCaptionElements(canvas, width, height, leftValues, true, false);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Посчитать размер элемента
        /// </summary>
        protected SKSize CalculateItemSize(int width, int height, float footerHeight, float headerHeight)
        {
            // Всего
            var total = Entries.Count();
            // Ширина
            var w = (width - (total + 1) * Margin) / total;
            // Высота
            var h = height - Margin - footerHeight - headerHeight;

            return(new SKSize(w, h));
        }
Ejemplo n.º 14
0
        public override void DrawContent(SKCanvas canvas, int width, int height)
        {
            if (Entries != null)
            {
                DrawCaption(canvas, width, height);
                using (new SKAutoCanvasRestore(canvas))
                {
                    if (DrawDebugRectangles)
                    {
                        using (var paint = new SKPaint
                        {
                            Color = SKColors.Red,
                            IsStroke = true,
                        })
                        {
                            canvas.DrawRect(DrawableChartArea, paint);
                        }
                    }

                    canvas.Translate(DrawableChartArea.Left + DrawableChartArea.Width / 2, height / 2);

                    var sumValue = Entries.Where(x => x.Value.HasValue).Sum(x => Math.Abs(x.Value.Value));
                    var radius   = (Math.Min(DrawableChartArea.Width, DrawableChartArea.Height) - (2 * Margin)) / 2;
                    var start    = 0.0f;

                    for (int i = 0; i < Entries.Count(); i++)
                    {
                        var entry = Entries.ElementAt(i);
                        if (!entry.Value.HasValue)
                        {
                            continue;
                        }

                        var end = start + ((Math.Abs(entry.Value.Value) / sumValue) * AnimationProgress);

                        // Sector
                        var path = RadialHelpers.CreateSectorPath(start, end, radius, radius * HoleRadius);
                        using (var paint = new SKPaint
                        {
                            Style = SKPaintStyle.Fill,
                            Color = entry.Color,
                            IsAntialias = true,
                        })
                        {
                            canvas.DrawPath(path, paint);
                        }

                        start = end;
                    }
                }
            }
        }
        public bool UndoMove()
        {
            TruncateToCurrentPly();

            if (Entries.Count() > 1)
            {
                Entries.RemoveAt(Entries.Count() - 1);
                --Plies;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 16
0
        public override void DrawContent(SKCanvas canvas, int width, int height)
        {
            var sumValue    = Entries.Sum(x => Math.Abs(x.Value));
            var radius      = (Math.Min(width, height) - (2 * Margin)) / 2;
            var cx          = width / 2;
            var cy          = Convert.ToInt32(height / 1.25);
            var lineWidth   = (LineSize < 0) ? (radius / ((Entries.Count() + 1) * 2)) : LineSize;
            var radiusSpace = lineWidth * 4;

            foreach (var entry in Entries.OrderByDescending(e => e.Value))
            {
                DrawChart(canvas, entry, radiusSpace, cx, cy, lineWidth);
            }

            DrawCaption(canvas, cx, cy, radiusSpace);
        }
Ejemplo n.º 17
0
        protected SKPoint[] CalculatePoints(SKSize itemSize, float origin, float headerHeight)
        {
            var result = new List <SKPoint>();

            for (int i = 0; i < Entries.Count(); i++)
            {
                var entry = Entries.ElementAt(i);

                var x     = Margin + (itemSize.Width / 2) + (i * (itemSize.Width + Margin));
                var y     = headerHeight + (((MaxValue - entry.Value) / ValueRange) * itemSize.Height);
                var point = new SKPoint(x, y);
                result.Add(point);
            }

            return(result.ToArray());
        }
Ejemplo n.º 18
0
        // Write all Pokedex entires to console with paging
        public void GetPokedex()
        {
            int    perPage        = 1;
            int    numberPages    = Entries.Count() / perPage;
            var    currentPage    = 0;
            var    currentEntries = Entries.Skip(currentPage).Take(perPage);
            string input;

            foreach (var entry in currentEntries)
            {
                Console.WriteLine("-~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~-\n");
                entry.Value.PokedexEntry();
            }

            do
            {
                Console.WriteLine("[ Current Page: " + (currentPage + 1) + "/" + (numberPages + 1) + " ] [ Z: Backward ] [ Enter: Forward ] [ Q: Exit ]");
                Console.Write("Enter Selection or Page Number >>> ");
                input = Console.ReadLine();
                Console.Clear();
                if (input == "")
                {
                    currentPage++;
                    currentEntries = Entries.Skip(currentPage * perPage).Take(perPage);
                }
                if (input.ToLower() == "z")
                {
                    currentPage    = currentPage <= 0 ? 0 : currentPage - 1;
                    currentEntries = Entries.Skip(currentPage * perPage).Take(perPage);
                }
                if (int.TryParse(input, out int result))
                {
                    currentPage    = result - 1;
                    currentEntries = Entries.Skip(currentPage * perPage).Take(perPage);
                }
                foreach (var entry in currentEntries)
                {
                    Console.WriteLine("-~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~-\n");
                    entry.Value.PokedexEntry();
                }
            }while (input != "q");

            PokedexMenu.Run();
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Посчитать точки
        /// </summary>
        protected SKPoint[] CalculatePoints(SKSize itemSize, float origin, float headerHeight)
        {
            // Результат
            var result = new List <SKPoint>();

            // Проходим по записям диаграммы
            for (var i = 0; i < Entries.Count(); i++)
            {
                // Получаем запись
                var entry = Entries.ElementAt(i);

                // Подсчитываем x, y
                var x = Margin + (itemSize.Width / 2) + (i * (itemSize.Width + Margin));
                var y = headerHeight + (((MaxValue - entry.Value) / ValueRange) * itemSize.Height);

                var point = new SKPoint(x, y);
                result.Add(point);
            }

            return(result.ToArray());
        }
Ejemplo n.º 20
0
        public override void DrawContent(SKCanvas canvas, int width, int height)
        {
            if (Entries != null)
            {
                DrawCaption(canvas, width, height);

                var sumValue    = Entries.Sum(x => Math.Abs(x.Value));
                var radius      = (Math.Min(width, height) - (2 * Margin)) / 2;
                var cx          = width / 2;
                var cy          = height / 2;
                var lineWidth   = (LineSize < 0) ? (radius / ((Entries.Count() + 1) * 2)) : LineSize;
                var radiusSpace = lineWidth * 2;

                for (int i = 0; i < Entries.Count(); i++)
                {
                    var entry       = Entries.ElementAt(i);
                    var entryRadius = (i + 1) * radiusSpace;
                    DrawGaugeArea(canvas, entry, entryRadius, cx, cy, lineWidth);
                    DrawGauge(canvas, entry, entryRadius, cx, cy, lineWidth);
                }
            }
        }
Ejemplo n.º 21
0
        public override void BuildContent(ICanvas canvas, int width, int height)
        {
            var total = Entries?.Count() ?? 0;

            if (total > 0)
            {
                var captionHeight = Entries.Max(x =>
                {
                    var result = 0.0;

                    var hasLabel      = !string.IsNullOrEmpty(x.Label);
                    var hasValueLabel = !string.IsNullOrEmpty(x.ValueLabel);
                    if (hasLabel || hasValueLabel)
                    {
                        var hasOffset     = hasLabel && hasValueLabel;
                        var captionMargin = LabelTextSize * 0.60f;
                        var space         = hasOffset ? captionMargin : 0;

                        if (hasLabel)
                        {
                            result += LabelTextSize;
                        }

                        if (hasValueLabel)
                        {
                            result += LabelTextSize;
                        }
                    }

                    return(result);
                });

                var center     = new Point(width / 2, height / 2);
                var radius     = ((Math.Min(width, height) - (2 * Margin)) / 2) - captionHeight;
                var rangeAngle = (float)((Math.PI * 2) / total);
                var startAngle = (float)Math.PI;

                var nextEntry = Entries.First();
                var nextAngle = startAngle;
                var nextPoint = GetPoint(nextEntry.Value * AnimationProgress, center, nextAngle, radius);

                DrawBorder(canvas, center, radius);
#if LATER
                clip.AddCircle(center.X, center.Y, radius);
#endif

                for (int i = 0; i < total; i++)
                {
                    var angle = nextAngle;
                    var entry = nextEntry;
                    var point = nextPoint;

                    var nextIndex = (i + 1) % total;
                    nextAngle = startAngle + (rangeAngle * nextIndex);
                    nextEntry = Entries.ElementAt(nextIndex);
                    nextPoint = GetPoint(nextEntry.Value * AnimationProgress, center, nextAngle, radius);

#if LATER
                    canvas.Save();
                    canvas.ClipPath(clip);
#endif

                    // Border center bars
                    var borderPoint = GetPoint(MaxValue, center, angle, radius);
                    var line        = Line().X1(point.X).Y1(point.Y).X2(borderPoint.X).Y2(borderPoint.Y).Stroke(SolidColorBrush().Color(BorderLineColor)).StrokeThickness(BorderLineSize);
                    canvas.Add(0, 0, line);

                    // Values points and lines
                    //PathEffect = SKPathEffect.CreateDash(new[] { BorderLineSize, BorderLineSize * 2 }, 0),

                    var amount      = Math.Abs(entry.Value - AbsoluteMinimum) / ValueRange;
                    var diameter    = radius * amount * 2;
                    var circleColor = entry.Color.WithA((byte)(entry.Color.A * 0.75f * AnimationProgress));
                    var circle      = Ellipse().Width(diameter).Height(diameter).Stroke(SolidColorBrush().Color(circleColor)).StrokeThickness(BorderLineSize);
                    canvas.Add(center.X - diameter / 2, center.Y - diameter / 2, circle);

                    canvas.DrawGradientLine(center, entry.Color.WithA(0), point, entry.Color.WithA((byte)(entry.Color.A * 0.75f)), LineSize);
                    canvas.DrawGradientLine(point, entry.Color, nextPoint, nextEntry.Color, LineSize);
                    canvas.DrawPoint(point, entry.Color, (float)PointSize, PointMode);
                }

#if LATER
                canvas.Restore();
#endif

#if LATER
                // Labels
                var labelPoint = new Point(0, radius + LabelTextSize + (PointSize / 2));
                var rotation   = SKMatrix.MakeRotation(angle);
                labelPoint = center + rotation.MapPoint(labelPoint);
                var alignment = SKTextAlign.Left;

                if ((Math.Abs(angle - (startAngle + Math.PI)) < Epsilon) || (Math.Abs(angle - Math.PI) < Epsilon))
                {
                    alignment = SKTextAlign.Center;
                }
                else if (angle > (float)(startAngle + Math.PI))
                {
                    alignment = SKTextAlign.Right;
                }

                canvas.DrawCaptionLabels(entry.Label, entry.TextColor, UnicodeMode, UnicodeLanguage, entry.ValueLabel, entry.Color.WithA((byte)(255 * AnimationProgress)), LabelTextSize, labelPoint, alignment, base.Typeface, out var _);
#endif
            }
        }
Ejemplo n.º 22
0
 public override string ToString()
 {
     return(string.Format("{0}: {2}, load @0x{4:X}, {5} entries", Name, NameIndex, Type, RawFlags, LoadAddress, Entries.Count()));
 }
Ejemplo n.º 23
0
 public void ReadWriteAll()
 {
     if (Connection != null)
     {
         //IList<Kanjidict> verbres = new List<Kanjidict>();
         Connection.CreateTable <Kanjidict>();
         for (int i = 0; i < Entries.Count(); i++)
         {
             var    entry = GetEntry(i);
             string on    = "";
             foreach (var ir in entry.Descendants("reading_meaning").Descendants("rmgroup").Descendants("reading").Where(f => f.FirstAttribute.Value == "ja_on"))
             {
                 on += ir.Value + ", ";
             }
             if (!string.IsNullOrWhiteSpace(on))
             {
                 on = on.Substring(0, on.Length - 2);
             }
             else
             {
                 on = "-";
             }
             string kun = "";
             foreach (var ik in entry.Descendants("reading_meaning").Descendants("rmgroup").Descendants("reading").Where(f => f.FirstAttribute.Value == "ja_kun"))
             {
                 kun += ik.Value + ", ";
             }
             if (!string.IsNullOrWhiteSpace(kun))
             {
                 kun = kun.Substring(0, kun.Length - 2);
             }
             else
             {
                 kun = "-";
             }
             var    grades  = entry.Descendants("misc").Descendants("grade");
             string grade   = "";
             var    jlpts   = entry.Descendants("misc").Descendants("jlpt");
             string jlpt    = "";
             var    freqs   = entry.Descendants("misc").Descendants("freq");
             string freq    = "";
             var    kanjis  = entry.Descendants("literal");
             string kanji   = "";
             var    strokes = entry.Descendants("misc").Descendants("stroke_count");
             string stroke  = "";
             if (grades.Count() != 0)
             {
                 grade = grades.First().Value;
             }
             else
             {
                 grade = "-";
             }
             if (jlpts.Count() != 0)
             {
                 jlpt = jlpts.First().Value;
             }
             else
             {
                 jlpt = "-";
             }
             if (freqs.Count() != 0)
             {
                 freq = freqs.First().Value;
             }
             else
             {
                 freq = "-";
             }
             if (kanjis.Count() != 0)
             {
                 kanji = kanjis.First().Value;
             }
             else
             {
                 kanji = "-";
             }
             if (strokes.Count() != 0)
             {
                 stroke = strokes.First().Value;
             }
             else
             {
                 stroke = "-";
             }
             var kanjidict = new Kanjidict()
             {
                 Grade = grade, Jlpt = jlpt, Frequency = freq, Kanji = kanji, Strokes = stroke, KunReading = kun, OnReading = on
             };
             Connection.Insert(kanjidict);
         }
     }
 }
Ejemplo n.º 24
0
        public override void DrawContent(SKCanvas canvas, int width, int height)
        {
            var total = Entries?.Count() ?? 0;

            if (total > 0)
            {
                var captionHeight = Entries.Max(x =>
                {
                    var result = 0.0f;

                    var hasLabel      = !string.IsNullOrEmpty(x.Label);
                    var hasValueLabel = !string.IsNullOrEmpty(x.ValueLabel);

                    if (hasLabel || hasValueLabel)
                    {
                        var hasOffset     = hasLabel && hasValueLabel;
                        var captionMargin = LabelTextSize * 0.60f;
                        var space         = hasOffset ? captionMargin : 0;

                        if (hasLabel)
                        {
                            result += LabelTextSize;
                        }

                        if (hasValueLabel)
                        {
                            result += LabelTextSize;
                        }
                    }

                    return(result);
                });

                var center     = new SKPoint(width / 2, height / 2);
                var radius     = ((Math.Min(width, height) - (2 * Margin)) / 2) - captionHeight;
                var rangeAngle = (float)((Math.PI * 2) / total);
                var startAngle = (float)Math.PI;

                DrawBorder(canvas, center, radius);

                using (var clip = new SKPath())
                {
                    clip.AddCircle(center.X, center.Y, radius);


                    for (int i = 0; i < total; i++)
                    {
                        var angle = startAngle + (rangeAngle * i);
                        var entry = Entries.ElementAt(i);


                        int nextIndex = (i + 1) % total;
                        var nextAngle = startAngle + (rangeAngle * nextIndex);
                        var nextEntry = Entries.ElementAt(nextIndex);
                        while (!nextEntry.Value.HasValue)
                        {
                            nextIndex = (nextIndex + 1) % total;
                            nextAngle = startAngle + (rangeAngle * nextIndex);
                            nextEntry = Entries.ElementAt(nextIndex);
                        }

                        canvas.Save();
                        if (entry.Value.HasValue)
                        {
                            var point     = GetPoint(entry.Value.Value * AnimationProgress, center, angle, radius);
                            var nextPoint = GetPoint(nextEntry.Value.Value * AnimationProgress, center, nextAngle, radius);

                            canvas.ClipPath(clip);

                            // Border center bars
                            using (var paint = new SKPaint()
                            {
                                Style = SKPaintStyle.Stroke,
                                StrokeWidth = BorderLineSize,
                                Color = BorderLineColor,
                                IsAntialias = true,
                            })
                            {
                                var borderPoint = GetPoint(MaxValue, center, angle, radius);
                                canvas.DrawLine(point.X, point.Y, borderPoint.X, borderPoint.Y, paint);
                            }

                            // Values points and lines
                            using (var paint = new SKPaint()
                            {
                                Style = SKPaintStyle.Stroke,
                                StrokeWidth = BorderLineSize,
                                Color = entry.Color.WithAlpha((byte)(entry.Color.Alpha * 0.75f * AnimationProgress)),
                                PathEffect = SKPathEffect.CreateDash(new[] { BorderLineSize, BorderLineSize * 2 }, 0),
                                IsAntialias = true,
                            })
                            {
                                var amount = Math.Abs(entry.Value.Value - AbsoluteMinimum) / ValueRange;
                                canvas.DrawCircle(center.X, center.Y, radius * amount, paint);
                            }

                            canvas.DrawGradientLine(center, entry.Color.WithAlpha(0), point, entry.Color.WithAlpha((byte)(entry.Color.Alpha * 0.75f)), LineSize);
                            canvas.DrawGradientLine(point, entry.Color, nextPoint, nextEntry.Color, LineSize);
                            canvas.DrawPoint(point, entry.Color, PointSize, PointMode);
                        }
                        canvas.Restore();

                        // Labels
                        var labelPoint = new SKPoint(0, radius + LabelTextSize + (PointSize / 2));
                        var rotation   = SKMatrix.CreateRotation(angle);
                        labelPoint = center + rotation.MapPoint(labelPoint);
                        var alignment = SKTextAlign.Left;

                        if ((Math.Abs(angle - (startAngle + Math.PI)) < Epsilon) || (Math.Abs(angle - Math.PI) < Epsilon))
                        {
                            alignment = SKTextAlign.Center;
                        }
                        else if (angle > (float)(startAngle + Math.PI))
                        {
                            alignment = SKTextAlign.Right;
                        }

                        canvas.DrawCaptionLabels(entry.Label, entry.TextColor, entry.ValueLabel, entry.Color.WithAlpha((byte)(255 * AnimationProgress)), LabelTextSize, labelPoint, alignment, base.Typeface, out var _);
                    }
                }
            }
        }
Ejemplo n.º 25
0
        public void InternalRegenerateCloud()
        {
            _source = new WriteableBitmap((int)_layoutRoot.ActualWidth, (int)_layoutRoot.ActualHeight);
            int arraySize = (int)((_layoutRoot.ActualWidth / 4) + 2) * (int)((_layoutRoot.ActualHeight / 4) + 2);

            _mapping = new int[arraySize];
            for (int i = 0; i < arraySize; i++)
            {
                _mapping[i] = -1;
            }

            if (Entries.Count() < 2)
            {
                _image.Source = _source;
                _image.InvalidateArrange();
                return;
            }

            _random = new Random(10202);

            double minSize = Entries.OrderByDescending(e => e.SizeValue).Take(MaxWords).Min(e => e.SizeValue);

            if (!double.IsNaN(MinimumValue))
            {
                minSize = Math.Min(MinimumValue, minSize);
            }
            double maxSize  = Math.Max(Entries.Max(e => e.SizeValue), MinimumLargestValue);
            double range    = Math.Max(0.00001, maxSize - minSize);
            double minColor = Entries.OrderByDescending(e => e.SizeValue).Take(MaxWords).Min(e => e.ColorValue);
            double maxColor = Entries.OrderByDescending(e => e.SizeValue).Take(MaxWords).Max(e => e.ColorValue);
            double maxAngle = Entries.OrderByDescending(e => e.SizeValue).Take(MaxWords).Max(e => e.Angle);

            if (!double.IsNaN(MinimumLargestAngleValue))
            {
                maxAngle = Math.Max(MinimumLargestAngleValue, maxAngle);
            }
            double minAngle = Entries.OrderByDescending(e => e.SizeValue).Take(MaxWords).Min(e => e.Angle);

            if (!double.IsNaN(MaximumLowestAngleValue))
            {
                minAngle = Math.Min(MaximumLowestAngleValue, minAngle);
            }


            double colorRange = Math.Max(0, maxColor - minColor);

            double angleRange = Math.Max(0, maxAngle - minAngle);

            //If there's a centre value then specify the range
            if (!double.IsNaN(AngleCenterValue))
            {
                var lr = AngleCenterValue - minAngle;
                var ur = maxAngle - AngleCenterValue;
                angleRange = Math.Max(ur, lr);
            }


            var txt = new TextBlock
            {
                FontFamily = FontFamily,
                FontSize   = 100,
                Text       = "x"
            };


            double areaPerLetter = ((txt.ActualWidth)) / (range);

            double         targetWidth    = _layoutRoot.ActualWidth * LargestSizeWidthProportion;
            WordCloudEntry od             = Entries.OrderByDescending(e => (e.SizeValue - minSize) * e.Word.Length).First();
            double         maxFontSize    = Math.Max(MinFontSize * 2.7, 100 / (((od.SizeValue - minSize) * od.Word.Length * areaPerLetter) / targetWidth));
            double         fontMultiplier = Math.Min((maxFontSize - MinFontSize) / range, 200);

            var points = new[]
            {
                new Point((int)(_layoutRoot.ActualWidth / 2), (int)(_layoutRoot.ActualHeight / 2)),
                new Point((int)(_layoutRoot.ActualWidth / 4), (int)(_layoutRoot.ActualHeight / 4)),
                new Point((int)(_layoutRoot.ActualWidth / 4), (int)(3 * _layoutRoot.ActualHeight / 2)),
                new Point((int)(3 * _layoutRoot.ActualWidth / 4), (int)(_layoutRoot.ActualHeight / 2)),
                new Point((int)(3 * _layoutRoot.ActualWidth / 4), (int)(3 * _layoutRoot.ActualHeight / 4))
            };


            int currentPoint = 0;

            foreach (WordCloudEntry e in Entries.OrderByDescending(e => e.SizeValue).Take(MaxWords))
            {
again:
                double position = 0.0;
                Point centre = points[currentPoint];

                double angle = 0.0;
                if (double.IsNaN(AngleCenterValue))
                {
                    angle = angleRange >= 0.01 ? -90 + (((e.Angle - minAngle) / angleRange) * 90) : 0;
                }
                else
                {
                    angle = angleRange >= 0.01 ? 90 * ((e.Angle - AngleCenterValue) / angleRange) : 0;
                }
                WriteableBitmap bm = CreateImage(e.Word,
                                                 ((e.SizeValue - minSize) * fontMultiplier) + MinFontSize,
                                                 SelectedItems.Contains(Entries.IndexOf(e)) ? -1 : (colorRange >= 0.01 ? (e.ColorValue - minColor) / colorRange : 1), e.Color,
                                                 angle);
                Dictionary <Point, List <Point> > lst = CreateCollisionList(bm);
                bool collided = true;
                do
                {
                    Point spiralPoint = GetSpiralPoint(position);
                    int   offsetX     = (bm.PixelWidth / 2);
                    int   offsetY     = (bm.PixelHeight / 2);
                    var   testPoint   = new Point((int)(spiralPoint.X + centre.X - offsetX), (int)(spiralPoint.Y + centre.Y - offsetY));
                    if (position > (2 * Math.PI) * 580)
                    {
                        if (++currentPoint >= points.Length)
                        {
                            goto done;
                        }
                        goto again;
                    }
                    int cols = CountCollisions(testPoint, lst);
                    if (cols == 0)
                    {
tryagain:
                        double oldY = testPoint.Y;
                        if (Math.Abs(testPoint.X + offsetX - centre.X) > 10)
                        {
                            if (testPoint.X + offsetX < centre.X)
                            {
                                do
                                {
                                    testPoint.X += 2;
                                } while (testPoint.X + offsetX < centre.X && CountCollisions(testPoint, lst) == 0);
                                testPoint.X -= 2;
                            }
                            else
                            {
                                do
                                {
                                    testPoint.X -= 2;
                                } while (testPoint.X + offsetX > centre.X && CountCollisions(testPoint, lst) == 0);
                                testPoint.X += 2;
                            }
                        }
                        if (Math.Abs(testPoint.Y + offsetY - centre.Y) > 10)
                        {
                            if (testPoint.Y + offsetY < centre.Y)
                            {
                                do
                                {
                                    testPoint.Y += 2;
                                } while (testPoint.Y + offsetY < centre.Y && CountCollisions(testPoint, lst) == 0);
                                testPoint.Y -= 2;
                            }
                            else
                            {
                                do
                                {
                                    testPoint.Y -= 2;
                                } while (testPoint.Y + offsetY > centre.Y && CountCollisions(testPoint, lst) == 0);
                                testPoint.Y += 2;
                            }
                            if (testPoint.Y != oldY)
                            {
                                goto tryagain;
                            }
                        }


                        collided = false;
                        CopyBits(testPoint, bm, lst, Entries.IndexOf(e));
                    }
                    else
                    {
                        if (cols <= 2)
                        {
                            position += (2 * Math.PI) / 100;
                        }
                        else
                        {
                            position += (2 * Math.PI) / 40;
                        }
                    }
                } while (collided);
            }
done:
            _image.Source = _source;
            _image.InvalidateArrange();
        }
Ejemplo n.º 26
0
 public static void MarkAllRead()
 {
     readCount = Entries.Count();
 }