diff --git a/NuGet/Package.Forms.nuspec b/NuGet/Package.Forms.nuspec index 27db6fc7..fc7fd3ba 100644 --- a/NuGet/Package.Forms.nuspec +++ b/NuGet/Package.Forms.nuspec @@ -2,7 +2,7 @@ Microcharts.Forms - 0.9.5.6 + 0.9.5.7 Microcharts for Xamarin.Forms Aloïs Deniel, Ed Lomonaco Aloïs Deniel, Ed Lomonaco @@ -14,7 +14,7 @@ xamarin.forms chart skia - + diff --git a/NuGet/Package.nuspec b/NuGet/Package.nuspec index c558ee43..00342a2b 100644 --- a/NuGet/Package.nuspec +++ b/NuGet/Package.nuspec @@ -2,7 +2,7 @@ Microcharts - 0.9.5.6 + 0.9.5.7 Microcharts Aloïs Deniel, Ed Lomonaco Aloïs Deniel, Ed Lomonaco diff --git a/Sources/Microcharts.Samples.Droid/MainActivity.cs b/Sources/Microcharts.Samples.Droid/MainActivity.cs index 674b93f3..c29f61ce 100644 --- a/Sources/Microcharts.Samples.Droid/MainActivity.cs +++ b/Sources/Microcharts.Samples.Droid/MainActivity.cs @@ -15,7 +15,7 @@ protected override void OnCreate(Bundle savedInstanceState) // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); - var charts = Data.RightToLeftTest(); + var charts = Data.CreateQuickstart(); FindViewById(Resource.Id.chartView1).Chart = charts[0]; FindViewById(Resource.Id.chartView2).Chart = charts[1]; diff --git a/Sources/Microcharts.Samples/Data.cs b/Sources/Microcharts.Samples/Data.cs index e3c396a4..39b0cc7c 100644 --- a/Sources/Microcharts.Samples/Data.cs +++ b/Sources/Microcharts.Samples/Data.cs @@ -182,7 +182,7 @@ public static Chart[] RightToLeftTest() Label = "שבוע 3", ValueLabel = "100", Color = SKColor.Parse("#90D585"), - }, + } }; return new Chart[] @@ -190,14 +190,16 @@ public static Chart[] RightToLeftTest() new BarChart { Entries = entries, - LabelTextSize = 42, + LabelTextSize = 60, + LabelColor = SKColors.Red, LabelOrientation = Orientation.Horizontal, TextDirection = TextDirection.RTL }, new PointChart { Entries = entries, - LabelTextSize = 42, + LabelTextSize = 60, + LabelColor = SKColors.Red, LabelOrientation = Orientation.Horizontal, TextDirection = TextDirection.RTL }, @@ -206,7 +208,8 @@ public static Chart[] RightToLeftTest() Entries = entries, LineMode = LineMode.Straight, LineSize = 8, - LabelTextSize = 42, + LabelTextSize = 60, + LabelColor = SKColors.Red, PointMode = PointMode.Square, PointSize = 18, TextDirection = TextDirection.RTL @@ -214,7 +217,7 @@ public static Chart[] RightToLeftTest() new DonutChart { Entries = entries, - LabelTextSize = 42, + LabelTextSize = 60, GraphPosition = GraphPosition.Center, LabelMode = LabelMode.RightOnly, TextDirection = TextDirection.RTL @@ -222,13 +225,13 @@ public static Chart[] RightToLeftTest() new RadialGaugeChart { Entries = entries, - LabelTextSize = 42, + LabelTextSize = 60, TextDirection = TextDirection.RTL }, new RadarChart { Entries = entries, - LabelTextSize = 42, + LabelTextSize = 60, TextDirection = TextDirection.RTL } }; @@ -240,32 +243,68 @@ public static Chart[] CreateQuickstart() { new ChartEntry(200) { - Label = "January", + Label = "Week 1", ValueLabel = "200", Color = SKColor.Parse("#266489"), }, new ChartEntry(400) { - Label = "February", + Label = "Week 2", ValueLabel = "400", Color = SKColor.Parse("#68B9C0"), }, new ChartEntry(100) { - Label = "March", + Label = "Week 3", ValueLabel = "100", Color = SKColor.Parse("#90D585"), }, + new ChartEntry(600) + { + Label = "Week 4", + ValueLabel = "600", + Color = SKColor.Parse("#32a852"), + } }; return new Chart[] { - new BarChart() { Entries = entries, LabelTextSize = 60, LabelOrientation = Orientation.Horizontal }, - new PointChart() { Entries = entries, LabelTextSize = 60, LabelOrientation = Orientation.Horizontal }, - new LineChart() { Entries = entries, LabelTextSize = 60, LabelOrientation = Orientation.Horizontal }, - new DonutChart() { Entries = entries, LabelTextSize = 60 }, - new RadialGaugeChart() { Entries = entries, LabelTextSize = 60 }, - new RadarChart() { Entries = entries, LabelTextSize = 60 }, + new BarChart + { + Entries = entries, + LabelTextSize = 55, + LabelOrientation = Orientation.Horizontal, + Margin = 10 + }, + new PointChart + { + Entries = entries, + LabelTextSize = 55, + LabelOrientation = Orientation.Horizontal, + Margin = 10 + }, + new LineChart + { + Entries = entries, + LabelTextSize = 55, + LabelOrientation = Orientation.Horizontal, + Margin = 10 + }, + new DonutChart + { + Entries = entries, + LabelTextSize = 60 + }, + new RadialGaugeChart + { + Entries = entries, + LabelTextSize = 60 + }, + new RadarChart + { + Entries = entries, + LabelTextSize = 60 + } }; } diff --git a/Sources/Microcharts/Charts/Chart.cs b/Sources/Microcharts/Charts/Chart.cs index 135a62a8..452aee75 100644 --- a/Sources/Microcharts/Charts/Chart.cs +++ b/Sources/Microcharts/Charts/Chart.cs @@ -74,7 +74,12 @@ public Chart() /// /// Get or set the direction the text should be facing. /// - public TextDirection TextDirection { get; set; } = TextDirection.LTR; + public TextDirection TextDirection { get; set; } = TextDirection.Auto; + + /// + /// Get or set label text spacing. + /// + public float LabelTextSpacing { get; set; } = 4.0f; /// /// Gets or sets a value indicating whether this is animated when entries change. @@ -149,6 +154,9 @@ public float LabelTextSize set => Set(ref labelTextSize, value); } + /// + /// Typeface for labels + /// public SKTypeface Typeface { get => typeface; @@ -359,7 +367,7 @@ protected void DrawCaptionElements(SKCanvas canvas, int width, int height, List< captionX -= captionMargin; } - canvas.DrawCaptionLabels(entry.Label, lblColor, TextDirection, entry.ValueLabel, valueColor, LabelTextSize, new SKPoint(captionX, y + (LabelTextSize / 2)), isLeft ? SKTextAlign.Left : SKTextAlign.Right, Typeface, out var labelBounds); + canvas.DrawCaptionLabels(entry.Label, lblColor, TextDirection, LabelTextSpacing, entry.ValueLabel, valueColor, LabelTextSize, new SKPoint(captionX, y + (LabelTextSize / 2)), isLeft ? SKTextAlign.Left : SKTextAlign.Right, Typeface, out var labelBounds); labelBounds.Union(rect); if (DrawDebugRectangles) diff --git a/Sources/Microcharts/Charts/PointChart.cs b/Sources/Microcharts/Charts/PointChart.cs index a9977633..76fa34d1 100644 --- a/Sources/Microcharts/Charts/PointChart.cs +++ b/Sources/Microcharts/Charts/PointChart.cs @@ -280,7 +280,27 @@ protected void DrawLabels(SKCanvas canvas, string[] texts, SKPoint[] points, SKR canvas.Translate(point.X - (bounds.Width / 2), y); } - var rs = new RichString().Add(text, fontSize: LabelTextSize, textColor: colors[i], textDirection: TextDirection); + RichString rs; + + if (Typeface != null) + { + rs = new RichString() + .FontFamily(Typeface.FamilyName) + .FontSize(LabelTextSize) + .LetterSpacing(LabelTextSpacing) + .TextColor(colors[i]) + .TextDirection(TextDirection) + .Add(text); + } + else + { + rs = new RichString() + .FontSize(LabelTextSize) + .LetterSpacing(LabelTextSpacing) + .TextColor(colors[i]) + .TextDirection(TextDirection) + .Add(text); + } rs.Paint(canvas, new TextPaintOptions { diff --git a/Sources/Microcharts/Charts/RadarChart.cs b/Sources/Microcharts/Charts/RadarChart.cs index de1759ef..c0f630c4 100644 --- a/Sources/Microcharts/Charts/RadarChart.cs +++ b/Sources/Microcharts/Charts/RadarChart.cs @@ -172,7 +172,7 @@ public override void DrawContent(SKCanvas canvas, int width, int height) alignment = SKTextAlign.Right; } - canvas.DrawCaptionLabels(entry.Label, entry.TextColor, TextDirection, entry.ValueLabel, entry.Color.WithAlpha((byte)(255 * AnimationProgress)), LabelTextSize, labelPoint, alignment, base.Typeface, out var _); + canvas.DrawCaptionLabels(entry.Label, entry.TextColor, TextDirection, LabelTextSpacing, entry.ValueLabel, entry.Color.WithAlpha((byte)(255 * AnimationProgress)), LabelTextSize, labelPoint, alignment, base.Typeface, out var _); } } } diff --git a/Sources/Microcharts/Extensions/CanvasExtensions.cs b/Sources/Microcharts/Extensions/CanvasExtensions.cs index 7266c64e..323ebfc0 100644 --- a/Sources/Microcharts/Extensions/CanvasExtensions.cs +++ b/Sources/Microcharts/Extensions/CanvasExtensions.cs @@ -8,7 +8,7 @@ namespace Microcharts { internal static class CanvasExtensions { - public static void DrawCaptionLabels(this SKCanvas canvas, string label, SKColor labelColor, TextDirection textDirection, string value, SKColor valueColor, float textSize, SKPoint point, SKTextAlign horizontalAlignment, SKTypeface typeface, out SKRect totalBounds) + public static void DrawCaptionLabels(this SKCanvas canvas, string label, SKColor labelColor, TextDirection textDirection, float labelTextSpacing, string value, SKColor valueColor, float textSize, SKPoint point, SKTextAlign horizontalAlignment, SKTypeface typeface, out SKRect totalBounds) { var hasLabel = !string.IsNullOrEmpty(label); var hasValueLabel = !string.IsNullOrEmpty(value); @@ -39,7 +39,27 @@ public static void DrawCaptionLabels(this SKCanvas canvas, string label, SKColor var y = point.Y - ((bounds.Top + bounds.Bottom) / 2) - space; - var rs = new RichString().Add(text, fontSize: textSize, textColor: labelColor, textDirection: textDirection); + RichString rs; + + if (typeface != null) + { + rs = new RichString() + .FontFamily(typeface.FamilyName) + .FontSize(textSize) + .LetterSpacing(labelTextSpacing) + .TextColor(labelColor) + .TextDirection(textDirection) + .Add(text); + } + else + { + rs = new RichString() + .FontSize(textSize) + .LetterSpacing(labelTextSpacing) + .TextColor(labelColor) + .TextDirection(textDirection) + .Add(text); + } rs.Paint(canvas, new SKPoint(point.X, y), new TextPaintOptions {