Skip to content

Commit

Permalink
update tooltip tests to latest api
Browse files Browse the repository at this point in the history
  • Loading branch information
beto-rodriguez committed Dec 13, 2024
1 parent 774d517 commit ad4dc90
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 18 deletions.
21 changes: 19 additions & 2 deletions tests/LiveChartsCore.UnitTesting/SeriesTests/BoxSeriesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand All @@ -122,42 +123,55 @@ 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,
"Tool tip on top failed");

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,
"Tool tip on bottom failed");

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,
"Tool tip on left failed");

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,
"Tool tip on right failed");

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,
"Tool tip on center failed");

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 &&
Expand All @@ -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 &&
Expand All @@ -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 &&
Expand All @@ -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 &&
Expand Down
21 changes: 19 additions & 2 deletions tests/LiveChartsCore.UnitTesting/SeriesTests/ColumnSeriesTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using LiveChartsCore.Drawing;
using LiveChartsCore.Measure;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
Expand Down Expand Up @@ -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
{
Expand All @@ -107,42 +108,55 @@ 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,
"Tool tip on top failed");

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,
"Tool tip on bottom failed");

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,
"Tool tip on left failed");

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,
"Tool tip on right failed");

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,
"Tool tip on center failed");

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 &&
Expand All @@ -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 &&
Expand All @@ -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 &&
Expand All @@ -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 &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using LiveChartsCore.Defaults;
using LiveChartsCore.Drawing;
using LiveChartsCore.Kernel;
using LiveChartsCore.Measure;
using LiveChartsCore.SkiaSharpView;
Expand Down Expand Up @@ -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
{
Expand All @@ -144,42 +145,55 @@ 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,
"Tool tip on top failed");

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,
"Tool tip on bottom failed");

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,
"Tool tip on left failed");

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,
"Tool tip on right failed");

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,
"Tool tip on center failed");

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 &&
Expand All @@ -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 &&
Expand All @@ -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 &&
Expand All @@ -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 &&
Expand Down
20 changes: 18 additions & 2 deletions tests/LiveChartsCore.UnitTesting/SeriesTests/HeatSeriesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void ShouldPlaceToolTips()
},
};

var tooltip = new SKDefaultTooltip();
var tooltip = new SKDefaultTooltip { Easing = null }; ;

var chart = new SKCartesianChart
{
Expand All @@ -173,42 +173,55 @@ 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,
"Tool tip on top failed");

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,
"Tool tip on bottom failed");

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,
"Tool tip on left failed");

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,
"Tool tip on right failed");

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,
"Tool tip on center failed");

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 &&
Expand All @@ -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 &&
Expand All @@ -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 &&
Expand All @@ -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 &&
Expand Down
Loading

0 comments on commit ad4dc90

Please sign in to comment.