From ad4dc90aeb9d56866b931c4e3abb68885dc79157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Rodr=C3=ADguez?= Date: Thu, 12 Dec 2024 20:37:57 -0600 Subject: [PATCH] update tooltip tests to latest api --- .../SeriesTests/BoxSeriesTests.cs | 21 +++++++++++++++++-- .../SeriesTests/ColumnSeriesTest.cs | 21 +++++++++++++++++-- .../SeriesTests/FinancialSeriesTest.cs | 21 +++++++++++++++++-- .../SeriesTests/HeatSeriesTest.cs | 20 ++++++++++++++++-- .../SeriesTests/LineSeriesTest.cs | 20 ++++++++++++++++-- .../SeriesTests/PieSeriesTest.cs | 16 ++++++++++++-- .../SeriesTests/PolarLineSeriesTest.cs | 16 ++++++++++++-- .../SeriesTests/ScatterSeriesTest.cs | 21 +++++++++++++++++-- .../SeriesTests/StepLineSeriesTest.cs | 20 ++++++++++++++++-- 9 files changed, 158 insertions(+), 18 deletions(-) diff --git a/tests/LiveChartsCore.UnitTesting/SeriesTests/BoxSeriesTests.cs b/tests/LiveChartsCore.UnitTesting/SeriesTests/BoxSeriesTests.cs index 4754e044e..06c7542dc 100644 --- a/tests/LiveChartsCore.UnitTesting/SeriesTests/BoxSeriesTests.cs +++ b/tests/LiveChartsCore.UnitTesting/SeriesTests/BoxSeriesTests.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Runtime.InteropServices; using LiveChartsCore.Defaults; +using LiveChartsCore.Drawing; using LiveChartsCore.Measure; using LiveChartsCore.SkiaSharpView; using LiveChartsCore.SkiaSharpView.Drawing.Geometries; @@ -103,7 +104,7 @@ public void ShouldPlaceToolTips() DataPadding = new Drawing.LvcPoint(0, 0) }; - var tooltip = new SKDefaultTooltip(); + var tooltip = new SKDefaultTooltip { Easing = null }; var chart = new SKCartesianChart { @@ -122,7 +123,15 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Top; _ = chart.GetImage(); - var tp = tooltip._container.Geometry; + + LvcRectangle tp; + void UpdateTooltipRect() + { + var g = tooltip._container; + tp = new LvcRectangle(new(g.X, g.Y), tooltip._container.Measure()); + } + + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 - tp.Height - 1 / 5d * 300 * 0.5d)) < 0.1, @@ -130,6 +139,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Bottom; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 + 1 / 5d * 300 * 0.5d)) < 0.1, @@ -137,6 +147,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Left; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - (150 - tp.Width - 1 / 5d * 300 * 0.5d)) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -144,6 +155,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Right; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - 150 - 1 / 5d * 300 * 0.5d) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -151,6 +163,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Center; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -158,6 +171,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Auto; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 - tp.Height - 1 / 5d * 300 * 0.5d)) < 0.1 && @@ -166,6 +180,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(300 * 4 / 5d - 10, 300 * 1 / 5d + 10); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 1 / 5d * 300 - 150) < 0.1 && Math.Abs(tp.Y - 300 * 1 / 5d) < 0.1 && @@ -174,6 +189,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(299, 150); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - (300 - 300 * (1 / 5d) * 0.5 - tp.Width)) < 0.0001 && //Math.Abs(tp.Y - -tp.Height * 0.5f) < 0.1 && @@ -182,6 +198,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(1, 150); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - 300 * (1 / 5d) * 0.5) < 0.0001 && //Math.Abs(tp.Y - (300 - tp.Height * 0.5f - 300 * (1 / 5d))) < 0.1 && diff --git a/tests/LiveChartsCore.UnitTesting/SeriesTests/ColumnSeriesTest.cs b/tests/LiveChartsCore.UnitTesting/SeriesTests/ColumnSeriesTest.cs index 65f7a6ba0..838fb9d64 100644 --- a/tests/LiveChartsCore.UnitTesting/SeriesTests/ColumnSeriesTest.cs +++ b/tests/LiveChartsCore.UnitTesting/SeriesTests/ColumnSeriesTest.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using LiveChartsCore.Drawing; using LiveChartsCore.Measure; using LiveChartsCore.SkiaSharpView; using LiveChartsCore.SkiaSharpView.Drawing.Geometries; @@ -88,7 +89,7 @@ public void ShouldPlaceToolTips() DataPadding = new Drawing.LvcPoint(0, 0) }; - var tooltip = new SKDefaultTooltip(); + var tooltip = new SKDefaultTooltip { Easing = null }; var chart = new SKCartesianChart { @@ -107,7 +108,15 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Top; _ = chart.GetImage(); - var tp = tooltip._container.Geometry; + + LvcRectangle tp; + void UpdateTooltipRect() + { + var g = tooltip._container; + tp = new LvcRectangle(new(g.X, g.Y), tooltip._container.Measure()); + } + + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 - tp.Height)) < 0.1, @@ -115,6 +124,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Bottom; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - 150) < 0.1, @@ -122,6 +132,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Left; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - (150 - tp.Width)) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -129,6 +140,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Right; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - 150) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -136,6 +148,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Center; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -143,6 +156,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Auto; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 - tp.Height)) < 0.1 && @@ -151,6 +165,7 @@ public void ShouldPlaceToolTips() sutSeries.Values = new double[] { -1, -2, -3, -4, -5 }; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - 150) < 0.1 && @@ -160,6 +175,7 @@ public void ShouldPlaceToolTips() sutSeries.Values = new double[] { 1, 2, 3, 4, 5 }; chart.Core._pointerPosition = new(299, 150); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - (300 - 300 * (1 / 5d) * 0.5 - tp.Width)) < 0.0001 && //Math.Abs(tp.Y - -tp.Height * 0.5f) < 0.1 && @@ -168,6 +184,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(1, 150); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - 300 * (1 / 5d) * 0.5) < 0.0001 && //Math.Abs(tp.Y - (300 - tp.Height * 0.5f)) < 0.1 && diff --git a/tests/LiveChartsCore.UnitTesting/SeriesTests/FinancialSeriesTest.cs b/tests/LiveChartsCore.UnitTesting/SeriesTests/FinancialSeriesTest.cs index d2acf54c1..569439e2d 100644 --- a/tests/LiveChartsCore.UnitTesting/SeriesTests/FinancialSeriesTest.cs +++ b/tests/LiveChartsCore.UnitTesting/SeriesTests/FinancialSeriesTest.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using LiveChartsCore.Defaults; +using LiveChartsCore.Drawing; using LiveChartsCore.Kernel; using LiveChartsCore.Measure; using LiveChartsCore.SkiaSharpView; @@ -125,7 +126,7 @@ public void ShouldPlaceToolTips() DataPadding = new Drawing.LvcPoint(0, 0) }; - var tooltip = new SKDefaultTooltip(); + var tooltip = new SKDefaultTooltip { Easing = null }; var chart = new SKCartesianChart { @@ -144,7 +145,15 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Top; _ = chart.GetImage(); - var tp = tooltip._container.Geometry; + + LvcRectangle tp; + void UpdateTooltipRect() + { + var g = tooltip._container; + tp = new LvcRectangle(new(g.X, g.Y), tooltip._container.Measure()); + } + + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 - tp.Height - 1 / 5d * 300 * 0.5d)) < 0.1, @@ -152,6 +161,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Bottom; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 + 1 / 5d * 300 * 0.5d)) < 0.1, @@ -159,6 +169,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Left; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - (150 - tp.Width - 1 / 5d * 300 * 0.5d)) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -166,6 +177,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Right; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - 150 - 1 / 5d * 300 * 0.5d) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -173,6 +185,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Center; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -180,6 +193,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Auto; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 - tp.Height - 1 / 5d * 300 * 0.5d)) < 0.1 && @@ -188,6 +202,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(300 * 4 / 5d - 10, 300 * 1 / 5d + 10); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 1 / 5d * 300 - 150) < 0.1 && Math.Abs(tp.Y - 300 * 1 / 5d) < 0.1 && @@ -196,6 +211,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(299, 150); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - (300 - 300 * (1 / 5d) * 0.5 - tp.Width)) < 0.0001 && //Math.Abs(tp.Y - -tp.Height * 0.5f) < 0.1 && @@ -204,6 +220,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(1, 150); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - 300 * (1 / 5d) * 0.5) < 0.0001 && //Math.Abs(tp.Y - (300 - tp.Height * 0.5f - 300 * (1 / 5d))) < 0.1 && diff --git a/tests/LiveChartsCore.UnitTesting/SeriesTests/HeatSeriesTest.cs b/tests/LiveChartsCore.UnitTesting/SeriesTests/HeatSeriesTest.cs index 1a1aba730..b3f314368 100644 --- a/tests/LiveChartsCore.UnitTesting/SeriesTests/HeatSeriesTest.cs +++ b/tests/LiveChartsCore.UnitTesting/SeriesTests/HeatSeriesTest.cs @@ -154,7 +154,7 @@ public void ShouldPlaceToolTips() }, }; - var tooltip = new SKDefaultTooltip(); + var tooltip = new SKDefaultTooltip { Easing = null }; ; var chart = new SKCartesianChart { @@ -173,7 +173,15 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Top; _ = chart.GetImage(); - var tp = tooltip._container.Geometry; + + LvcRectangle tp; + void UpdateTooltipRect() + { + var g = tooltip._container; + tp = new LvcRectangle(new(g.X, g.Y), tooltip._container.Measure()); + } + + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 - tp.Height)) < 0.1, @@ -181,6 +189,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Bottom; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - 150) < 0.1, @@ -188,6 +197,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Left; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - (150 - tp.Width)) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -195,6 +205,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Right; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - 150) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -202,6 +213,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Center; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -209,6 +221,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Auto; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 - tp.Height)) < 0.1 && @@ -217,6 +230,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(150, 10); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - (150 - tp.Width * 0.5f)) < 0.1 && Math.Abs(tp.Y - 300 * 1 / 5d * 0.5f) < 0.1 && @@ -225,6 +239,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(295, 5); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - (300 - 300 * 1 / 5d * 0.5 - tp.Width)) < 0.1 && Math.Abs(tp.Y - -(tp.Height * 0.5f - 300 * 1 / 5d * 0.5)) < 0.1 && @@ -233,6 +248,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(5, 295); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - 300 * 1 / 5d * 0.5) < 0.1 && Math.Abs(tp.Y - (300 - tp.Height * 0.5f - 300 * 1 / 5d * 0.5)) < 0.1 && diff --git a/tests/LiveChartsCore.UnitTesting/SeriesTests/LineSeriesTest.cs b/tests/LiveChartsCore.UnitTesting/SeriesTests/LineSeriesTest.cs index 76a3be558..24ea7aca5 100644 --- a/tests/LiveChartsCore.UnitTesting/SeriesTests/LineSeriesTest.cs +++ b/tests/LiveChartsCore.UnitTesting/SeriesTests/LineSeriesTest.cs @@ -94,7 +94,7 @@ public void ShouldPlaceToolTips() DataPadding = new LvcPoint(0, 0) }; - var tooltip = new SKDefaultTooltip(); + var tooltip = new SKDefaultTooltip { Easing = null }; var chart = new SKCartesianChart { @@ -113,7 +113,15 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Top; _ = chart.GetImage(); - var tp = tooltip._container.Geometry; + + LvcRectangle tp; + void UpdateTooltipRect() + { + var g = tooltip._container; + tp = new LvcRectangle(new(g.X, g.Y), tooltip._container.Measure()); + } + + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 - tp.Height)) < 0.1, @@ -121,6 +129,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Bottom; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - 150) < 0.1, @@ -128,6 +137,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Left; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - (150 - tp.Width)) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -135,6 +145,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Right; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - 150) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -142,6 +153,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Center; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -149,6 +161,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Auto; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 - tp.Height)) < 0.1 && @@ -157,6 +170,7 @@ public void ShouldPlaceToolTips() sutSeries.Values = [-1, -2, -3, -4, -5]; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - 150) < 0.1 && @@ -166,6 +180,7 @@ public void ShouldPlaceToolTips() sutSeries.Values = [1, 2, 3, 4, 5]; chart.Core._pointerPosition = new(299, 150); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( // that 2... it seems that the lineseries.DataPadding takes more space than expected Math.Abs(tp.X - (300 - tp.Width)) < 2 && @@ -175,6 +190,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(1, 150); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X) < 2 && //Math.Abs(tp.Y - (300 - tp.Height * 0.5f)) < 2 && diff --git a/tests/LiveChartsCore.UnitTesting/SeriesTests/PieSeriesTest.cs b/tests/LiveChartsCore.UnitTesting/SeriesTests/PieSeriesTest.cs index b9a344b92..e1cb086d4 100644 --- a/tests/LiveChartsCore.UnitTesting/SeriesTests/PieSeriesTest.cs +++ b/tests/LiveChartsCore.UnitTesting/SeriesTests/PieSeriesTest.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using LiveChartsCore.Drawing; using LiveChartsCore.Measure; using LiveChartsCore.SkiaSharpView; using LiveChartsCore.SkiaSharpView.Drawing.Geometries; @@ -72,7 +73,7 @@ public void ShouldScale() [TestMethod] public void ShouldPlaceToolTips() { - var tooltip = new SKDefaultTooltip(); + var tooltip = new SKDefaultTooltip { Easing = null }; var chart = new SKPieChart { @@ -88,7 +89,15 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(150 + 10, 150 + 10); _ = chart.GetImage(); - var tp = tooltip._container. Geometry; + + LvcRectangle tp; + void UpdateTooltipRect() + { + var g = tooltip._container; + tp = new LvcRectangle(new(g.X, g.Y), tooltip._container.Measure()); + } + + UpdateTooltipRect(); Assert.IsTrue( tp.X - 150 > 0 && tp.Y + tp.Height - 150 > 0, @@ -96,6 +105,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(150 - 10, 150 + 10); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( tp.X - 150 < 0 && tp.Y + tp.Height - 150 > 0, @@ -103,6 +113,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(150 - 10, 150 - 10); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( tp.X - 150 < 0 && tp.Y + tp.Height - 150 < 0, @@ -110,6 +121,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(150 + 10, 150 - 10); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( tp.X - 150 > 0 && tp.Y + tp.Height - 150 < 0, diff --git a/tests/LiveChartsCore.UnitTesting/SeriesTests/PolarLineSeriesTest.cs b/tests/LiveChartsCore.UnitTesting/SeriesTests/PolarLineSeriesTest.cs index e4b41aaea..a30a12140 100644 --- a/tests/LiveChartsCore.UnitTesting/SeriesTests/PolarLineSeriesTest.cs +++ b/tests/LiveChartsCore.UnitTesting/SeriesTests/PolarLineSeriesTest.cs @@ -75,7 +75,7 @@ public void ShouldPlaceToolTipsCorrectly() DataPadding = new LvcPoint(0, 0) }; - var tooltip = new SKDefaultTooltip(); + var tooltip = new SKDefaultTooltip { Easing = null }; var chart = new SKPolarChart { @@ -94,7 +94,15 @@ public void ShouldPlaceToolTipsCorrectly() chart.TooltipPosition = TooltipPosition.Top; _ = chart.GetImage(); - var tp = tooltip._container.Geometry; + + LvcRectangle tp; + void UpdateTooltipRect() + { + var g = tooltip._container; + tp = new LvcRectangle(new(g.X, g.Y), tooltip._container.Measure()); + } + + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 - tp.Height)) < 0.1, @@ -102,6 +110,7 @@ public void ShouldPlaceToolTipsCorrectly() chart.TooltipPosition = TooltipPosition.Bottom; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - 150) < 0.1, @@ -109,6 +118,7 @@ public void ShouldPlaceToolTipsCorrectly() chart.TooltipPosition = TooltipPosition.Left; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - (150 - tp.Width)) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -116,6 +126,7 @@ public void ShouldPlaceToolTipsCorrectly() chart.TooltipPosition = TooltipPosition.Right; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - 150) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -123,6 +134,7 @@ public void ShouldPlaceToolTipsCorrectly() chart.TooltipPosition = TooltipPosition.Center; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, diff --git a/tests/LiveChartsCore.UnitTesting/SeriesTests/ScatterSeriesTest.cs b/tests/LiveChartsCore.UnitTesting/SeriesTests/ScatterSeriesTest.cs index 7514380d3..321c9c002 100644 --- a/tests/LiveChartsCore.UnitTesting/SeriesTests/ScatterSeriesTest.cs +++ b/tests/LiveChartsCore.UnitTesting/SeriesTests/ScatterSeriesTest.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using LiveChartsCore.Defaults; +using LiveChartsCore.Drawing; using LiveChartsCore.Measure; using LiveChartsCore.SkiaSharpView; using LiveChartsCore.SkiaSharpView.Drawing.Geometries; @@ -112,7 +113,7 @@ public void ShouldPlaceToolTips() $"{Environment.NewLine}{x.Coordinate.PrimaryValue}", }; - var tooltip = new SKDefaultTooltip(); + var tooltip = new SKDefaultTooltip { Easing = null }; var chart = new SKCartesianChart { @@ -131,7 +132,15 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Top; _ = chart.GetImage(); - var tp = tooltip._container.Geometry; + + LvcRectangle tp; + void UpdateTooltipRect() + { + var g = tooltip._container; + tp = new LvcRectangle(new(g.X, g.Y), tooltip._container.Measure()); + } + + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 - tp.Height)) < 0.1, @@ -139,6 +148,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Bottom; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - 150) < 0.1, @@ -146,6 +156,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Left; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - (150 - tp.Width)) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -153,6 +164,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Right; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - 150) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -160,6 +172,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Center; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -167,6 +180,7 @@ public void ShouldPlaceToolTips() chart.TooltipPosition = TooltipPosition.Auto; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 - tp.Height)) < 0.1 && @@ -175,6 +189,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(300 * 3 / 4d, 300 * 1 / 4d); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - (300 * 3 / 4d - tp.Width * 0.5f)) < 0.1 && Math.Abs(tp.Y - 300 * 1 / 4d) < 0.1 && @@ -183,6 +198,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(295, 5); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - (300 - tp.Width)) < 0.1 && //Math.Abs(tp.Y - -tp.Height * 0.5f) < 0.1 && @@ -191,6 +207,7 @@ public void ShouldPlaceToolTips() chart.Core._pointerPosition = new(5, 295); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X) < 0.1 && //Math.Abs(tp.Y - (300 - tp.Height * 0.5f)) < 0.1 && diff --git a/tests/LiveChartsCore.UnitTesting/SeriesTests/StepLineSeriesTest.cs b/tests/LiveChartsCore.UnitTesting/SeriesTests/StepLineSeriesTest.cs index 4627994b4..5a46077a8 100644 --- a/tests/LiveChartsCore.UnitTesting/SeriesTests/StepLineSeriesTest.cs +++ b/tests/LiveChartsCore.UnitTesting/SeriesTests/StepLineSeriesTest.cs @@ -93,7 +93,7 @@ public void ShouldPlaceToolTipsCorrectly() DataPadding = new LvcPoint(0, 0) }; - var tooltip = new SKDefaultTooltip(); + var tooltip = new SKDefaultTooltip { Easing = null }; var chart = new SKCartesianChart { @@ -112,7 +112,15 @@ public void ShouldPlaceToolTipsCorrectly() chart.TooltipPosition = TooltipPosition.Top; _ = chart.GetImage(); - var tp = tooltip._container.Geometry; + + LvcRectangle tp; + void UpdateTooltipRect() + { + var g = tooltip._container; + tp = new LvcRectangle(new(g.X, g.Y), tooltip._container.Measure()); + } + + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 - tp.Height)) < 0.1, @@ -120,6 +128,7 @@ public void ShouldPlaceToolTipsCorrectly() chart.TooltipPosition = TooltipPosition.Bottom; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - 150) < 0.1, @@ -127,6 +136,7 @@ public void ShouldPlaceToolTipsCorrectly() chart.TooltipPosition = TooltipPosition.Left; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - (150 - tp.Width)) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -134,6 +144,7 @@ public void ShouldPlaceToolTipsCorrectly() chart.TooltipPosition = TooltipPosition.Right; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X - 150) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -141,6 +152,7 @@ public void ShouldPlaceToolTipsCorrectly() chart.TooltipPosition = TooltipPosition.Center; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y + tp.Height * 0.5f - 150) < 0.1, @@ -148,6 +160,7 @@ public void ShouldPlaceToolTipsCorrectly() chart.TooltipPosition = TooltipPosition.Auto; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - (150 - tp.Height)) < 0.1 && @@ -156,6 +169,7 @@ public void ShouldPlaceToolTipsCorrectly() sutSeries.Values = new double[] { -1, -2, -3, -4, -5 }; _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X + tp.Width * 0.5f - 150) < 0.1 && Math.Abs(tp.Y - 150) < 0.1 && @@ -165,6 +179,7 @@ public void ShouldPlaceToolTipsCorrectly() sutSeries.Values = new double[] { 1, 2, 3, 4, 5 }; chart.Core._pointerPosition = new(299, 150); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( // that 2... it seems that the lineseries.DataPadding takes more space than expected Math.Abs(tp.X - (300 - tp.Width)) < 2 && @@ -174,6 +189,7 @@ public void ShouldPlaceToolTipsCorrectly() chart.Core._pointerPosition = new(1, 150); _ = chart.GetImage(); + UpdateTooltipRect(); Assert.IsTrue( Math.Abs(tp.X) < 2 && //Math.Abs(tp.Y - (300 - tp.Height * 0.5f)) < 2 &&