Beispiel #1
0
        public static Color FromRGB(byte r, byte g, byte b, byte a)
        {
#if (__IOS__ || __TVOS__) && !SKIASHARP
            return(Color.FromRGB(r / 255f, g / 255f, b / 255f, a / 255f));
#else
            return(new Color(r, g, b, a));
#endif
        }
Beispiel #2
0
 public static void Draw(this SkiaSharp.SKPicture skPicture, SkiaSharp.SKColor background, float scaleX, float scaleY, SkiaSharp.SKCanvas skCanvas)
 {
     skCanvas.DrawColor(background);
     skCanvas.Save();
     skCanvas.Scale(scaleX, scaleY);
     skCanvas.DrawPicture(skPicture);
     skCanvas.Restore();
 }
Beispiel #3
0
        public ChartEntry ToChartEntry()
        {
            var color = new SkiaSharp.SKColor((byte)rng.Next(256), (byte)rng.Next(256), (byte)rng.Next(256), byte.MaxValue);

            return(new ChartEntry((float)Value)
            {
                Label = Name,
                Color = color,
                TextColor = color,
                ValueLabelColor = color,
            });
        }
 /// <param name="label">The legend entry text.A `null` label will start a group.</param>
 /// <param name="form">The form to draw for this entry.</param>
 /// <param name="formSize">Set to NaN to use the legend's default.</param>
 /// <param name="formLineWidth">Set to NaN to use the legend's default.</param>
 /// <param name="formLineDashEffect">Set to nil to use the legend's default.</param>
 /// <param name="formColor">The color for drawing the form.</param>
 public LegendEntry(string label,
                    Form form,
                    float formSize,
                    float formLineWidth,
                    DashPathEffect formLineDashEffect,
                    Color formColor)
 {
     Label              = label;
     Form               = form;
     FormSize           = formSize;
     FormLineWidth      = formLineWidth;
     FormLineDashEffect = formLineDashEffect;
     FormColor          = formColor;
 }
Beispiel #5
0
        private void Canvas_PaintSurface(object sender, SkiaSharp.Views.UWP.SKPaintSurfaceEventArgs e)
        {
            e.Surface.Canvas.Clear();

            // Handle the text color
            byte r = 0, g = 0, b = 0, a = 255;

            if (Foreground is SolidColorBrush)
            {
                var fore = (Foreground as SolidColorBrush).Color;
                r = fore.R;
                g = fore.G;
                b = fore.B;
                a = fore.A;
            }
            SkiaSharp.SKColor textColor = new SkiaSharp.SKColor(r, g, b, a);

            // Handle the background color
            r = 255; g = 255; b = 255; a = 255;
            if (Background is SolidColorBrush)
            {
                var back = (Background as SolidColorBrush).Color;
                r = back.R;
                g = back.G;
                b = back.B;
                a = back.A;
            }
            SkiaSharp.SKColor backColor = new SkiaSharp.SKColor(r, g, b, a);
            e.Surface.Canvas.DrawColor(backColor);

            var painter = new CSharpMath.SkiaSharp.MathPainter
            {
                LaTeX     = LaTeXString,
                FontSize  = (float)FontSize,
                TextColor = textColor,
            };

            painter.Draw(e.Surface.Canvas);
        }
Beispiel #6
0
        private async void GetPoolResults()
        {
            Func <Task> results = new Func <Task>(
                async() =>
            {
                var query = await PoolsResults.GetAvailablePools();
                if (query.Count() > 0)
                {
                    Polls.ForEach(poll => poll.Results = new ObservableCollection <Microcharts.Entry>());

                    foreach (PoolsResults poolResult in query)
                    {
                        var proxy        = Polls.Where(p => p.Definition.Category == poolResult.Category).FirstOrDefault();
                        var entry        = new Microcharts.Entry(poolResult.Votes);
                        entry.Label      = poolResult.Option;
                        var newColor     = new SkiaSharp.SKColor((byte)rnd.Next(256), (byte)rnd.Next(256), (byte)rnd.Next(256));
                        entry.Color      = newColor;
                        entry.ValueLabel = poolResult.Votes.ToString();
                        proxy.Results.Add(entry);
                    }
                    foreach (var poll in Polls)
                    {
                        if (poll.Answer != null)
                        {
                            poll.CurrentChart = new PieChart()
                            {
                                Entries       = poll.Results,
                                LabelTextSize = 50
                            };
                        }
                    }
                }
            }
                );

            await ExecuteSafeOperation(results);
        }
Beispiel #7
0
 public static Color FromNative(this SKColor color) => new Color(color.Red, color.Green, color.Blue, color.Alpha);
Beispiel #8
0
 public static bool ToImage(this SkiaSharp.SKPicture skPicture, Stream stream, SkiaSharp.SKColor background, SkiaSharp.SKEncodedImageFormat format, int quality, float scaleX, float scaleY, SkiaSharp.SKColorType skColorType, SkiaSharp.SKAlphaType skAlphaType, SkiaSharp.SKColorSpace skColorSpace)
 {
     using var skBitmap = skPicture.ToBitmap(background, scaleX, scaleY, skColorType, skAlphaType, skColorSpace);
     if (skBitmap is null)
     {
         return(false);
     }
     using var skImage = SkiaSharp.SKImage.FromBitmap(skBitmap);
     using var skData  = skImage.Encode(format, quality);
     if (skData is { })
Beispiel #9
0
        public static SkiaSharp.SKBitmap?ToBitmap(this SkiaSharp.SKPicture skPicture, SkiaSharp.SKColor background, float scaleX, float scaleY, SkiaSharp.SKColorType skColorType, SkiaSharp.SKAlphaType skAlphaType, SkiaSharp.SKColorSpace skColorSpace)
        {
            var width  = skPicture.CullRect.Width * scaleX;
            var height = skPicture.CullRect.Height * scaleY;

            if (!(width > 0) || !(height > 0))
            {
                return(null);
            }
            var skImageInfo = new SkiaSharp.SKImageInfo((int)width, (int)height, skColorType, skAlphaType, skColorSpace);
            var skBitmap    = new SkiaSharp.SKBitmap(skImageInfo);

            using var skCanvas = new SkiaSharp.SKCanvas(skBitmap);
            Draw(skPicture, background, scaleX, scaleY, skCanvas);
            return(skBitmap);
        }
Beispiel #10
0
        public async Task <List <CovidItemList> > CovidRefreshDataAsync()
        {
            CovidItemList UsList    = new CovidItemList();
            CovidItemList StateList = new CovidItemList();

            for (int x = 0; x < 2; x++)
            {
                string BaseUrl = "";
                string DateUrl = "";
                if (x == 0)
                {
                    BaseUrl = Constants.CovidUsUrl;
                    DateUrl = Constants.CovidUsByDateUrl;
                }
                else
                {
                    BaseUrl = Constants.CovidStateUrl;
                    DateUrl = Constants.CovidStateByDateUrl;
                }
                for (int i = 0; i < 4; i++)
                {
                    CovidItem covidItem              = new CovidItem();
                    DateTime  currentDate            = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0));
                    List <Microcharts.Entry> entries = new List <Microcharts.Entry>();

                    try
                    {
                        var uri      = new Uri(string.Format(BaseUrl, string.Empty));
                        var response = await _client.GetAsync(uri);

                        //Debug.WriteLine("XX52: " + response.ToString());
                        if (response.IsSuccessStatusCode)
                        {
                            var content = await response.Content.ReadAsStringAsync();

                            Debug.WriteLine(content.ToString() + "58");

                            var newArry = content.Split(',');
                            Debug.WriteLine(newArry[0] + "61");
                            switch (i)
                            {
                            case 0:
                            {
                                if (x == 0)
                                {
                                    covidItem.Valve = newArry[0].Split(':')[1];
                                }
                                else
                                {
                                    covidItem.Valve = newArry[1].Split(':')[1];
                                }
                                covidItem.Text = "Positive Cases: ";
                                break;
                            }

                            case 1:
                            {
                                if (x == 0)
                                {
                                    covidItem.Valve = newArry[1].Split(':')[1];
                                }
                                else
                                {
                                    covidItem.Valve = newArry[11].Split(':')[1];
                                }
                                covidItem.Text = "Negative Cases: ";
                                break;
                            }

                            case 2:
                            {
                                if (x == 0)
                                {
                                    covidItem.Valve = newArry[9].Split(':')[1];
                                }
                                else
                                {
                                    covidItem.Valve = newArry[19].Split(':')[1];
                                }
                                covidItem.Text = "Recovered Cases: ";
                                break;
                            }

                            case 3:
                            {
                                if (x == 0)
                                {
                                    covidItem.Valve = newArry[12].Split(':')[1];
                                }
                                else
                                {
                                    covidItem.Valve = newArry[22].Split(':')[1];
                                }
                                covidItem.Text = "Total Deaths: ";
                                break;
                            }

                            default:
                            {
                                break;
                            }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(@"\tERROR line 53{0}" + "x:" + x + "i:" + i, ex.Message);
                    }
                    try
                    {
                        for (int y = 10; y > 0; y--)
                        {
                            DateTime tempDate = currentDate.Subtract(new TimeSpan((7 * y), 0, 0, 0));
                            string   urlDate  = tempDate.Year.ToString();

                            if (tempDate.Month < 10)
                            {
                                urlDate = urlDate + "0" + tempDate.Month.ToString();
                            }
                            else
                            {
                                urlDate = urlDate + tempDate.Month.ToString();
                            }

                            if (tempDate.Day < 10)
                            {
                                urlDate = urlDate + "0" + tempDate.Day.ToString();
                            }
                            else
                            {
                                urlDate = urlDate + tempDate.Day.ToString();
                            }

                            //Debug.WriteLine(urlDate);
                            try
                            {
                                var test     = string.Format((DateUrl + urlDate + ".json"), string.Empty);
                                var uriDate  = new Uri(string.Format((DateUrl + urlDate + ".json"), string.Empty));
                                var response = await _client.GetAsync(uriDate);

                                //Debug.WriteLine("X116: " + response.ToString());
                                //Debug.WriteLine(test);
                                if (response.IsSuccessStatusCode)
                                {
                                    var content = await response.Content.ReadAsStringAsync();

                                    //Debug.WriteLine(content.ToString());

                                    var    newArry = content.Split(',');
                                    string tempVal;
                                    string tempLabel;

                                    switch (i)
                                    {
                                    case 0:
                                    {
                                        if (x == 0)
                                        {
                                            tempVal = newArry[2].Split(':')[1];
                                        }
                                        else
                                        {
                                            tempVal = newArry[2].Split(':')[1];
                                        }
                                        //Debug.WriteLine(tempVal);
                                        if (tempVal == "null")
                                        {
                                            tempVal = "0";
                                        }
                                        break;
                                    }

                                    case 1:
                                    {
                                        if (x == 0)
                                        {
                                            tempVal = newArry[3].Split(':')[1];
                                        }
                                        else
                                        {
                                            tempVal = newArry[11].Split(':')[1];
                                        }
                                        //Debug.WriteLine(tempVal);
                                        if (tempVal == "null")
                                        {
                                            tempVal = "0";
                                        }
                                        break;
                                    }

                                    case 2:
                                    {
                                        if (x == 0)
                                        {
                                            tempVal = newArry[11].Split(':')[1];
                                        }
                                        else
                                        {
                                            tempVal = newArry[19].Split(':')[1];
                                        }
                                        //Debug.WriteLine(tempVal);
                                        if (tempVal == "null")
                                        {
                                            tempVal = "0";
                                        }
                                        break;
                                    }

                                    case 3:
                                    {
                                        if (x == 0)
                                        {
                                            tempVal = newArry[15].Split(':')[1];
                                        }
                                        else
                                        {
                                            tempVal = newArry[22].Split(':')[1];
                                        }
                                        //Debug.WriteLine(tempVal);
                                        if (tempVal == "null")
                                        {
                                            tempVal = "0";
                                        }
                                        break;
                                    }

                                    default:
                                    {
                                        tempVal = "0";
                                        break;
                                    }
                                    }

                                    SkiaSharp.SKColor tempColor = new SkiaSharp.SKColor();

                                    switch (y)
                                    {
                                    case 0:
                                    {
                                        tempColor = new SkiaSharp.SKColor(71, 230, 113);
                                        break;
                                    }

                                    case 1:
                                    {
                                        tempColor = new SkiaSharp.SKColor(71, 230, 206);
                                        break;
                                    }

                                    case 2:
                                    {
                                        tempColor = new SkiaSharp.SKColor(71, 137, 230);
                                        break;
                                    }

                                    case 3:
                                    {
                                        tempColor = new SkiaSharp.SKColor(71, 105, 230);
                                        break;
                                    }

                                    default:
                                    {
                                        tempColor = new SkiaSharp.SKColor(230, 71, 71);
                                        break;
                                    }
                                    }

                                    tempLabel = newArry[0].Split(':')[1].Substring(0, 4);
                                    tempLabel = newArry[0].Split(':')[1].Substring(6, 2) + ", " + tempLabel;
                                    tempLabel = newArry[0].Split(':')[1].Substring(4, 2) + "/" + tempLabel;

                                    Debug.WriteLine(tempLabel);

                                    Microcharts.Entry entry = new Microcharts.Entry(float.Parse(tempVal));
                                    entry.Color      = tempColor;
                                    entry.Label      = tempLabel;
                                    entry.ValueLabel = tempVal;

                                    entries.Add(entry);
                                }
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(@"\tERROR line 135 {0}" + "y:" + y + "x:" + x + "i:" + i, ex.Message);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(@"\tERROR line 141 {0}" + "x:" + x + "i:" + i, ex.Message);
                    }

                    covidItem.Chart = new LineChart()
                    {
                        Entries = entries, LabelTextSize = 40
                    };

                    Debug.WriteLine(covidItem.Text);
                    Debug.WriteLine(covidItem.Valve);
                    Debug.WriteLine(covidItem.Chart.Entries.Count());

                    covidItem.Text = covidItem.Text + " " + covidItem.Valve;

                    if (x == 0)
                    {
                        UsList.CovidItems.Add(covidItem);
                    }
                    else
                    {
                        StateList.CovidItems.Add(covidItem);
                    }
                }
            }
            List <CovidItemList> list = new List <CovidItemList>();

            list.Add(UsList);
            list.Add(StateList);
            return(list);
        }
Beispiel #11
0
 /// <summary>
 /// Displays the <see cref="SkiaSharp.SKColor"/> in the style of <see cref="Color.ToString()"/>.
 /// </summary>
 public static string ToColorString(this SkiaSharp.SKColor color)
 {
     return($"Color [A={color.Alpha}, R={color.Red}, G={color.Green}, B={color.Blue}]");
 }
Beispiel #12
0
 public ChartColor(SkiaSharp.SKColor value)
 {
     Value = value;
 }