Skip to content

Commit

Permalink
update tests to new api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
beto-rodriguez committed Nov 30, 2024
1 parent 834f80a commit 96682c9
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 83 deletions.
1 change: 1 addition & 0 deletions src/LiveChartsCore/CorePolarAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ public override void Invalidate(Chart chart)
textGeometry.X = l.X;
textGeometry.Y = l.Y;
textGeometry.Opacity = 0;
textGeometry.Paint = LabelsPaint;
textGeometry.CompleteTransition(null);
}

Expand Down
1 change: 1 addition & 0 deletions src/LiveChartsCore/VisualElements/AngularTicksVisual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ protected internal override void OnInvalidated(Chart chart)
visual.Label.X = cx + (float)Math.Cos(beta) * labelsRadius;
visual.Label.Y = cy + (float)Math.Sin(beta) * labelsRadius;
visual.Label.TextSize = labelsSize;
visual.Label.Paint = LabelsPaint;

if (i + tick <= max)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,6 @@ public override void Draw(IDrawable drawable, float opacity)
{
_ = Canvas.Save();

if (drawable is CoreLabelGeometry label)
{
var a = label.Text;
var b = 1;
var m1 = element.Measure();
}

var m = element.Measure();
var o = element.TransformOrigin;
var p = new SKPoint(element.X, element.Y);
Expand Down
13 changes: 9 additions & 4 deletions tests/LiveChartsCore.UnitTesting/LayoutTests/TableLayoutTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,15 @@ public void UnevenColumns()
var g10g = (LabelGeometry)g10.GetDrawnGeometries()[0];
var g11g = (LabelGeometry)g11.GetDrawnGeometries()[0];

var g00m = g00g.Measure(g00.Paint);
var g01m = g01g.Measure(g01.Paint);
var g10m = g10g.Measure(g10.Paint);
var g11m = g11g.Measure(g11.Paint);
g00g.Paint = g00.Paint;
g01g.Paint = g01.Paint;
g10g.Paint = g10.Paint;
g11g.Paint = g11.Paint;

var g00m = g00g.Measure();
var g01m = g01g.Measure();
var g10m = g10g.Measure();
var g11m = g11g.Measure();

var wc0 = g00m.Width > g01m.Width ? g00m.Width : g10m.Width;
var wc1 = g10m.Width > g11m.Width ? g01m.Width : g11m.Width;
Expand Down
10 changes: 7 additions & 3 deletions tests/LiveChartsCore.UnitTesting/OtherTests/LabelsMeasureTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public void MaxWidth()
l++;
}

var size = label.Measure(paint);
label.Paint = paint;
var size = label.Measure();
Assert.IsTrue(size.Width <= maxWidth);
Assert.IsTrue(l == label._lines);

Expand All @@ -154,7 +155,9 @@ public void MaxWidth()
TextSize = 15,
MaxWidth = 100
};
var size2 = label2.Measure(paint);

label2.Paint = paint;
var size2 = label2.Measure();

Assert.IsTrue(label2._lines == 5);
Assert.IsTrue(size2.Width > label2.MaxWidth); // the text is too long, this is allowed.
Expand All @@ -165,7 +168,8 @@ public void MaxWidth()
TextSize = 15,
MaxWidth = 100
};
var size3 = label3.Measure(paint);
label3.Paint = paint;
var size3 = label3.Measure();
var lines3 = label3.GetLines(paint._skiaPaint).ToArray();

Assert.IsTrue(label3._lines == 6);
Expand Down
22 changes: 15 additions & 7 deletions tests/LiveChartsCore.UnitTesting/SeriesTests/BoxSeriesTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Runtime.InteropServices;
using LiveChartsCore.Defaults;
using LiveChartsCore.Measure;
using LiveChartsCore.SkiaSharpView;
Expand Down Expand Up @@ -245,7 +246,8 @@ public void ShouldPlaceDataLabel()
var v = p.Visual;
var l = p.Label;

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X + v.Width * 0.5f - l.X) < 0.01 && // x is centered
Expand All @@ -267,7 +269,8 @@ public void ShouldPlaceDataLabel()
var l = p.Label;
var h = Math.Abs(p.Visual.Y - p.Visual.Min);

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X + v.Width * 0.5f - l.X) < 0.01 && // x is centered
Expand All @@ -289,7 +292,8 @@ public void ShouldPlaceDataLabel()
var l = p.Label;
var h = Math.Abs(p.Visual.Y - p.Visual.Min);

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X + v.Width - (l.X - ls.Width * 0.5)) < 0.01 && // x is right
Expand All @@ -311,7 +315,8 @@ public void ShouldPlaceDataLabel()
var l = p.Label;
var h = Math.Abs(p.Visual.Y - p.Visual.Min);

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X - (l.X + ls.Width * 0.5f)) < 0.01 && // x is left
Expand All @@ -333,7 +338,8 @@ public void ShouldPlaceDataLabel()
var l = p.Label;
var h = Math.Abs(p.Visual.Y - p.Visual.Min);

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X + v.Width * 0.5f - l.X) < 0.01 && // x is centered
Expand All @@ -355,7 +361,8 @@ public void ShouldPlaceDataLabel()
var l = p.Label;
var h = Math.Abs(p.Visual.Y - p.Visual.Min);

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

if (p.Model.Max <= 0)
{
Expand Down Expand Up @@ -388,7 +395,8 @@ public void ShouldPlaceDataLabel()
var l = p.Label;
var h = Math.Abs(p.Visual.Y - p.Visual.Min);

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

if (p.Model.Max <= 0)
{
Expand Down
21 changes: 14 additions & 7 deletions tests/LiveChartsCore.UnitTesting/SeriesTests/ColumnSeriesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ public void ShouldPlaceDataLabel()
var v = p.Visual;
var l = p.Label;

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X + v.Width * 0.5f - l.X) < 0.01 && // x is centered
Expand All @@ -248,7 +249,8 @@ public void ShouldPlaceDataLabel()
var v = p.Visual;
var l = p.Label;

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X + v.Width * 0.5f - l.X) < 0.01 && // x is centered
Expand All @@ -269,7 +271,8 @@ public void ShouldPlaceDataLabel()
var v = p.Visual;
var l = p.Label;

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X + v.Width - (l.X - ls.Width * 0.5)) < 0.01 && // x is right
Expand All @@ -290,7 +293,8 @@ public void ShouldPlaceDataLabel()
var v = p.Visual;
var l = p.Label;

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X - (l.X + ls.Width * 0.5f)) < 0.01 && // x is left
Expand All @@ -311,7 +315,8 @@ public void ShouldPlaceDataLabel()
var v = p.Visual;
var l = p.Label;

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X + v.Width * 0.5f - l.X) < 0.01 && // x is centered
Expand All @@ -332,7 +337,8 @@ public void ShouldPlaceDataLabel()
var v = p.Visual;
var l = p.Label;

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

if (p.Model <= 0)
{
Expand Down Expand Up @@ -364,7 +370,8 @@ public void ShouldPlaceDataLabel()
var v = p.Visual;
var l = p.Label;

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

if (p.Model <= 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ public void ShouldPlaceDataLabel()
var v = p.Visual;
var l = p.Label;

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X + v.Width * 0.5f - l.X) < 0.01 && // x is centered
Expand All @@ -290,7 +291,8 @@ public void ShouldPlaceDataLabel()
var l = p.Label;
var h = Math.Abs(p.Visual.Y - p.Visual.Low);

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X + v.Width * 0.5f - l.X) < 0.01 && // x is centered
Expand All @@ -312,7 +314,8 @@ public void ShouldPlaceDataLabel()
var l = p.Label;
var h = Math.Abs(p.Visual.Y - p.Visual.Low);

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X + v.Width - (l.X - ls.Width * 0.5)) < 0.01 && // x is right
Expand All @@ -334,7 +337,8 @@ public void ShouldPlaceDataLabel()
var l = p.Label;
var h = Math.Abs(p.Visual.Y - p.Visual.Low);

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X - (l.X + ls.Width * 0.5f)) < 0.01 && // x is left
Expand All @@ -356,7 +360,8 @@ public void ShouldPlaceDataLabel()
var l = p.Label;
var h = Math.Abs(p.Visual.Y - p.Visual.Low);

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X + v.Width * 0.5f - l.X) < 0.01 && // x is centered
Expand All @@ -378,7 +383,8 @@ public void ShouldPlaceDataLabel()
var l = p.Label;
var h = Math.Abs(p.Visual.Y - p.Visual.Low);

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

if (p.Model.High <= 0)
{
Expand Down Expand Up @@ -411,7 +417,8 @@ public void ShouldPlaceDataLabel()
var l = p.Label;
var h = Math.Abs(p.Visual.Y - p.Visual.Low);

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

if (p.Model.High <= 0)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using LiveChartsCore.Defaults;
using LiveChartsCore.Drawing;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Extensions;
Expand Down
15 changes: 10 additions & 5 deletions tests/LiveChartsCore.UnitTesting/SeriesTests/HeatSeriesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ public void ShouldPlaceDataLabel()
var v = p.Visual;
var l = p.Label;

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X + v.Width * 0.5f - l.X) < 0.01 && // x is centered
Expand All @@ -318,7 +319,8 @@ public void ShouldPlaceDataLabel()
var v = p.Visual;
var l = p.Label;

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X + v.Width * 0.5f - l.X) < 0.01 && // x is centered
Expand All @@ -339,7 +341,8 @@ public void ShouldPlaceDataLabel()
var v = p.Visual;
var l = p.Label;

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X + v.Width - (l.X - ls.Width * 0.5)) < 0.01 && // x is right
Expand All @@ -360,7 +363,8 @@ public void ShouldPlaceDataLabel()
var v = p.Visual;
var l = p.Label;

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X - (l.X + ls.Width * 0.5f)) < 0.01 && // x is left
Expand All @@ -382,7 +386,8 @@ public void ShouldPlaceDataLabel()
var v = p.Visual;
var l = p.Label;

var ls = l.Measure(sutSeries.DataLabelsPaint);
l.Paint = sutSeries.DataLabelsPaint;
var ls = l.Measure();

Assert.IsTrue(
Math.Abs(v.X + v.Width * 0.5f - l.X) < 0.01 && // x is centered
Expand Down
Loading

0 comments on commit 96682c9

Please sign in to comment.