Skip to content

Commit d6201ce

Browse files
committed
Fixed letter spacing issue
1 parent 3e0d98d commit d6201ce

8 files changed

Lines changed: 113 additions & 26 deletions

File tree

NuGet/Package.Forms.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>Microcharts.Forms</id>
5-
<version>0.9.5.6</version>
5+
<version>0.9.5.7</version>
66
<title>Microcharts for Xamarin.Forms</title>
77
<authors>Aloïs Deniel, Ed Lomonaco</authors>
88
<owners>Aloïs Deniel, Ed Lomonaco</owners>
@@ -14,7 +14,7 @@
1414
<tags>xamarin.forms chart skia</tags>
1515
<dependencies>
1616
<group targetFramework="netstandard2.0">
17-
<dependency id="Microcharts" version="0.9.5.6" />
17+
<dependency id="Microcharts" version="0.9.5.7" />
1818
<dependency id="SkiaSharp" version="2.80.1" />
1919
<dependency id="SkiaSharp.Views.Forms" version="2.80.1" />
2020
<dependency id="System.ValueTuple" version="4.5.0" />

NuGet/Package.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>Microcharts</id>
5-
<version>0.9.5.6</version>
5+
<version>0.9.5.7</version>
66
<title>Microcharts</title>
77
<authors>Aloïs Deniel, Ed Lomonaco</authors>
88
<owners>Aloïs Deniel, Ed Lomonaco</owners>

Sources/Microcharts.Samples.Droid/MainActivity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protected override void OnCreate(Bundle savedInstanceState)
1515
// Set our view from the "main" layout resource
1616
SetContentView(Resource.Layout.Main);
1717

18-
var charts = Data.RightToLeftTest();
18+
var charts = Data.CreateQuickstart();
1919

2020
FindViewById<ChartView>(Resource.Id.chartView1).Chart = charts[0];
2121
FindViewById<ChartView>(Resource.Id.chartView2).Chart = charts[1];

Sources/Microcharts.Samples/Data.cs

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,22 +182,24 @@ public static Chart[] RightToLeftTest()
182182
Label = "שבוע 3",
183183
ValueLabel = "100",
184184
Color = SKColor.Parse("#90D585"),
185-
},
185+
}
186186
};
187187

188188
return new Chart[]
189189
{
190190
new BarChart
191191
{
192192
Entries = entries,
193-
LabelTextSize = 42,
193+
LabelTextSize = 60,
194+
LabelColor = SKColors.Red,
194195
LabelOrientation = Orientation.Horizontal,
195196
TextDirection = TextDirection.RTL
196197
},
197198
new PointChart
198199
{
199200
Entries = entries,
200-
LabelTextSize = 42,
201+
LabelTextSize = 60,
202+
LabelColor = SKColors.Red,
201203
LabelOrientation = Orientation.Horizontal,
202204
TextDirection = TextDirection.RTL
203205
},
@@ -206,29 +208,30 @@ public static Chart[] RightToLeftTest()
206208
Entries = entries,
207209
LineMode = LineMode.Straight,
208210
LineSize = 8,
209-
LabelTextSize = 42,
211+
LabelTextSize = 60,
212+
LabelColor = SKColors.Red,
210213
PointMode = PointMode.Square,
211214
PointSize = 18,
212215
TextDirection = TextDirection.RTL
213216
},
214217
new DonutChart
215218
{
216219
Entries = entries,
217-
LabelTextSize = 42,
220+
LabelTextSize = 60,
218221
GraphPosition = GraphPosition.Center,
219222
LabelMode = LabelMode.RightOnly,
220223
TextDirection = TextDirection.RTL
221224
},
222225
new RadialGaugeChart
223226
{
224227
Entries = entries,
225-
LabelTextSize = 42,
228+
LabelTextSize = 60,
226229
TextDirection = TextDirection.RTL
227230
},
228231
new RadarChart
229232
{
230233
Entries = entries,
231-
LabelTextSize = 42,
234+
LabelTextSize = 60,
232235
TextDirection = TextDirection.RTL
233236
}
234237
};
@@ -240,32 +243,68 @@ public static Chart[] CreateQuickstart()
240243
{
241244
new ChartEntry(200)
242245
{
243-
Label = "January",
246+
Label = "Week 1",
244247
ValueLabel = "200",
245248
Color = SKColor.Parse("#266489"),
246249
},
247250
new ChartEntry(400)
248251
{
249-
Label = "February",
252+
Label = "Week 2",
250253
ValueLabel = "400",
251254
Color = SKColor.Parse("#68B9C0"),
252255
},
253256
new ChartEntry(100)
254257
{
255-
Label = "March",
258+
Label = "Week 3",
256259
ValueLabel = "100",
257260
Color = SKColor.Parse("#90D585"),
258261
},
262+
new ChartEntry(600)
263+
{
264+
Label = "Week 4",
265+
ValueLabel = "600",
266+
Color = SKColor.Parse("#32a852"),
267+
}
259268
};
260269

261270
return new Chart[]
262271
{
263-
new BarChart() { Entries = entries, LabelTextSize = 60, LabelOrientation = Orientation.Horizontal },
264-
new PointChart() { Entries = entries, LabelTextSize = 60, LabelOrientation = Orientation.Horizontal },
265-
new LineChart() { Entries = entries, LabelTextSize = 60, LabelOrientation = Orientation.Horizontal },
266-
new DonutChart() { Entries = entries, LabelTextSize = 60 },
267-
new RadialGaugeChart() { Entries = entries, LabelTextSize = 60 },
268-
new RadarChart() { Entries = entries, LabelTextSize = 60 },
272+
new BarChart
273+
{
274+
Entries = entries,
275+
LabelTextSize = 55,
276+
LabelOrientation = Orientation.Horizontal,
277+
Margin = 10
278+
},
279+
new PointChart
280+
{
281+
Entries = entries,
282+
LabelTextSize = 55,
283+
LabelOrientation = Orientation.Horizontal,
284+
Margin = 10
285+
},
286+
new LineChart
287+
{
288+
Entries = entries,
289+
LabelTextSize = 55,
290+
LabelOrientation = Orientation.Horizontal,
291+
Margin = 10
292+
},
293+
new DonutChart
294+
{
295+
Entries = entries,
296+
LabelTextSize = 60
297+
},
298+
new RadialGaugeChart
299+
{
300+
Entries = entries,
301+
LabelTextSize = 60
302+
},
303+
new RadarChart
304+
{
305+
Entries = entries,
306+
LabelTextSize = 60
307+
}
269308
};
270309
}
271310

Sources/Microcharts/Charts/Chart.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ public Chart()
7474
/// <summary>
7575
/// Get or set the direction the text should be facing.
7676
/// </summary>
77-
public TextDirection TextDirection { get; set; } = TextDirection.LTR;
77+
public TextDirection TextDirection { get; set; } = TextDirection.Auto;
78+
79+
/// <summary>
80+
/// Get or set label text spacing.
81+
/// </summary>
82+
public float LabelTextSpacing { get; set; } = 4.0f;
7883

7984
/// <summary>
8085
/// Gets or sets a value indicating whether this <see cref="T:Microcharts.Chart"/> is animated when entries change.
@@ -149,6 +154,9 @@ public float LabelTextSize
149154
set => Set(ref labelTextSize, value);
150155
}
151156

157+
/// <summary>
158+
/// Typeface for labels
159+
/// </summary>
152160
public SKTypeface Typeface
153161
{
154162
get => typeface;
@@ -359,7 +367,7 @@ protected void DrawCaptionElements(SKCanvas canvas, int width, int height, List<
359367
captionX -= captionMargin;
360368
}
361369

362-
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);
370+
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);
363371
labelBounds.Union(rect);
364372

365373
if (DrawDebugRectangles)

Sources/Microcharts/Charts/PointChart.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,27 @@ protected void DrawLabels(SKCanvas canvas, string[] texts, SKPoint[] points, SKR
280280
canvas.Translate(point.X - (bounds.Width / 2), y);
281281
}
282282

283-
var rs = new RichString().Add(text, fontSize: LabelTextSize, textColor: colors[i], textDirection: TextDirection);
283+
RichString rs;
284+
285+
if (Typeface != null)
286+
{
287+
rs = new RichString()
288+
.FontFamily(Typeface.FamilyName)
289+
.FontSize(LabelTextSize)
290+
.LetterSpacing(LabelTextSpacing)
291+
.TextColor(colors[i])
292+
.TextDirection(TextDirection)
293+
.Add(text);
294+
}
295+
else
296+
{
297+
rs = new RichString()
298+
.FontSize(LabelTextSize)
299+
.LetterSpacing(LabelTextSpacing)
300+
.TextColor(colors[i])
301+
.TextDirection(TextDirection)
302+
.Add(text);
303+
}
284304

285305
rs.Paint(canvas, new TextPaintOptions
286306
{

Sources/Microcharts/Charts/RadarChart.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public override void DrawContent(SKCanvas canvas, int width, int height)
172172
alignment = SKTextAlign.Right;
173173
}
174174

175-
canvas.DrawCaptionLabels(entry.Label, entry.TextColor, TextDirection, entry.ValueLabel, entry.Color.WithAlpha((byte)(255 * AnimationProgress)), LabelTextSize, labelPoint, alignment, base.Typeface, out var _);
175+
canvas.DrawCaptionLabels(entry.Label, entry.TextColor, TextDirection, LabelTextSpacing, entry.ValueLabel, entry.Color.WithAlpha((byte)(255 * AnimationProgress)), LabelTextSize, labelPoint, alignment, base.Typeface, out var _);
176176
}
177177
}
178178
}

Sources/Microcharts/Extensions/CanvasExtensions.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microcharts
88
{
99
internal static class CanvasExtensions
1010
{
11-
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)
11+
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)
1212
{
1313
var hasLabel = !string.IsNullOrEmpty(label);
1414
var hasValueLabel = !string.IsNullOrEmpty(value);
@@ -39,7 +39,27 @@ public static void DrawCaptionLabels(this SKCanvas canvas, string label, SKColor
3939

4040
var y = point.Y - ((bounds.Top + bounds.Bottom) / 2) - space;
4141

42-
var rs = new RichString().Add(text, fontSize: textSize, textColor: labelColor, textDirection: textDirection);
42+
RichString rs;
43+
44+
if (typeface != null)
45+
{
46+
rs = new RichString()
47+
.FontFamily(typeface.FamilyName)
48+
.FontSize(textSize)
49+
.LetterSpacing(labelTextSpacing)
50+
.TextColor(labelColor)
51+
.TextDirection(textDirection)
52+
.Add(text);
53+
}
54+
else
55+
{
56+
rs = new RichString()
57+
.FontSize(textSize)
58+
.LetterSpacing(labelTextSpacing)
59+
.TextColor(labelColor)
60+
.TextDirection(textDirection)
61+
.Add(text);
62+
}
4363

4464
rs.Paint(canvas, new SKPoint(point.X, y), new TextPaintOptions
4565
{

0 commit comments

Comments
 (0)