From 3852a4f8d9c6a0b42272afc8286ab9b628a85c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Rodr=C3=ADguez?= Date: Mon, 31 May 2021 23:26:32 -0500 Subject: [PATCH] automatic tooltips strategy --- docs/1.overview/1.10.tooltips.md | 14 +++++++++++++ .../{1.10.legends.md => 1.11.legends.md} | 0 .../{1.11.themes.md => 1.12.themes.md} | 0 docs/1.overview/1.12.tooltips.md | 0 src/LiveChartsCore/CartesianChart.cs | 19 ++++++++++++++++- src/LiveChartsCore/ColumnSeries.cs | 4 +++- src/LiveChartsCore/Drawing/MotionCanvas.cs | 2 ++ src/LiveChartsCore/ISeries.cs | 3 ++- .../Kernel/ICartesianChartView.cs | 9 ++++++++ src/LiveChartsCore/Kernel/IChartView.cs | 8 ------- .../Kernel/LiveChartsSettings.cs | 2 +- .../Kernel/RectangleHoverArea.cs | 7 +++++-- src/LiveChartsCore/Kernel/SeriesProperties.cs | 17 ++++++++++++++- src/LiveChartsCore/LineSeries.cs | 4 +++- .../Measure/TooltipFindingStrategy.cs | 7 ++++++- src/LiveChartsCore/PieChart.cs | 4 ++-- src/LiveChartsCore/RowSeries.cs | 10 +++++---- src/LiveChartsCore/ScatterSeries.cs | 2 +- src/LiveChartsCore/Series.cs | 16 ++++++++------ src/LiveChartsCore/StackedColumnSeries.cs | 4 +++- src/LiveChartsCore/StackedRowSeries.cs | 4 +++- .../CartesianChart.axaml.cs | 2 +- .../PieChart.axaml.cs | 14 ------------- .../CartesianChart.cs | 16 ++++++++++++++ .../LiveChartsCore.SkiaSharp.WPF/Chart.cs | 21 ------------------- .../CartesianChart.cs | 4 ++++ .../Chart.cs | 4 ---- .../PieChart.xaml.cs | 18 +--------------- 28 files changed, 126 insertions(+), 89 deletions(-) create mode 100644 docs/1.overview/1.10.tooltips.md rename docs/1.overview/{1.10.legends.md => 1.11.legends.md} (100%) rename docs/1.overview/{1.11.themes.md => 1.12.themes.md} (100%) delete mode 100644 docs/1.overview/1.12.tooltips.md diff --git a/docs/1.overview/1.10.tooltips.md b/docs/1.overview/1.10.tooltips.md new file mode 100644 index 000000000..2cf220d44 --- /dev/null +++ b/docs/1.overview/1.10.tooltips.md @@ -0,0 +1,14 @@ +
+ +
+
+ + +
+ Edit this article +
+
+
+ +# Tooltips + diff --git a/docs/1.overview/1.10.legends.md b/docs/1.overview/1.11.legends.md similarity index 100% rename from docs/1.overview/1.10.legends.md rename to docs/1.overview/1.11.legends.md diff --git a/docs/1.overview/1.11.themes.md b/docs/1.overview/1.12.themes.md similarity index 100% rename from docs/1.overview/1.11.themes.md rename to docs/1.overview/1.12.themes.md diff --git a/docs/1.overview/1.12.tooltips.md b/docs/1.overview/1.12.tooltips.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/LiveChartsCore/CartesianChart.cs b/src/LiveChartsCore/CartesianChart.cs index 675af06c0..b5b13ea77 100644 --- a/src/LiveChartsCore/CartesianChart.cs +++ b/src/LiveChartsCore/CartesianChart.cs @@ -146,7 +146,24 @@ public override void Update(ChartUpdateParams? chartUpdateParams = null) /// public override IEnumerable FindPointsNearTo(PointF pointerPosition) { - return _chartView.Series.SelectMany(series => series.FindPointsNearTo(this, pointerPosition)); + var actualStrategy = TooltipFindingStrategy; + if (TooltipFindingStrategy == TooltipFindingStrategy.Automatic) + { + var areAllX = true; + var areAllY = true; + + foreach (var series in Series) + { + areAllX = areAllX && (series.SeriesProperties & SeriesProperties.PrefersXStrategyTooltips) != 0; + areAllY = areAllY && (series.SeriesProperties & SeriesProperties.PrefersYStrategyTooltips) != 0; + } + + actualStrategy = areAllX + ? TooltipFindingStrategy.CompareOnlyX + : (areAllY ? TooltipFindingStrategy.CompareOnlyY : TooltipFindingStrategy.CompareAll); + } + + return _chartView.Series.SelectMany(series => series.FindPointsNearTo(this, pointerPosition, actualStrategy)); } /// diff --git a/src/LiveChartsCore/ColumnSeries.cs b/src/LiveChartsCore/ColumnSeries.cs index b367c94c0..be64d9d3e 100644 --- a/src/LiveChartsCore/ColumnSeries.cs +++ b/src/LiveChartsCore/ColumnSeries.cs @@ -45,7 +45,9 @@ public abstract class ColumnSeries : B /// Initializes a new instance of the class. /// public ColumnSeries() - : base(SeriesProperties.Bar | SeriesProperties.PrimaryAxisVerticalOrientation | SeriesProperties.Solid) + : base( + SeriesProperties.Bar | SeriesProperties.PrimaryAxisVerticalOrientation | + SeriesProperties.Solid | SeriesProperties.PrefersXStrategyTooltips) { DataPadding = new PointF(0, 1); } diff --git a/src/LiveChartsCore/Drawing/MotionCanvas.cs b/src/LiveChartsCore/Drawing/MotionCanvas.cs index d21ae9581..fd8663649 100644 --- a/src/LiveChartsCore/Drawing/MotionCanvas.cs +++ b/src/LiveChartsCore/Drawing/MotionCanvas.cs @@ -94,6 +94,8 @@ public void DrawFrame(TDrawingContext context) foreach (var geometry in task.GetGeometries(this)) { + if (geometry == null) continue; + geometry.IsValid = true; geometry.CurrentTime = frameTime; if (!task.IsPaused) geometry.Draw(context); diff --git a/src/LiveChartsCore/ISeries.cs b/src/LiveChartsCore/ISeries.cs index 5a6feb565..4bd992fb8 100644 --- a/src/LiveChartsCore/ISeries.cs +++ b/src/LiveChartsCore/ISeries.cs @@ -156,8 +156,9 @@ public interface ISeries : IDisposable /// /// the chart /// the pointer position + /// the already resolved strategy when strategy is set to automatic. /// - IEnumerable FindPointsNearTo(IChart chart, PointF pointerPosition); + IEnumerable FindPointsNearTo(IChart chart, PointF pointerPosition, TooltipFindingStrategy automaticStategy); /// /// Marks a given point as a given state. diff --git a/src/LiveChartsCore/Kernel/ICartesianChartView.cs b/src/LiveChartsCore/Kernel/ICartesianChartView.cs index f78381fee..fefc6f68e 100644 --- a/src/LiveChartsCore/Kernel/ICartesianChartView.cs +++ b/src/LiveChartsCore/Kernel/ICartesianChartView.cs @@ -75,6 +75,15 @@ public interface ICartesianChartView : IChartView ZoomAndPanMode ZoomMode { get; set; } + + /// + /// Gets or sets the tool tip finding strategy. + /// + /// + /// The tool tip finding strategy. + /// + TooltipFindingStrategy TooltipFindingStrategy { get; set; } + /// /// Gets or sets the zooming speed from 0 to 1, where 0 is the fastest and 1 the slowest. /// diff --git a/src/LiveChartsCore/Kernel/IChartView.cs b/src/LiveChartsCore/Kernel/IChartView.cs index d5d2e555b..407edff11 100644 --- a/src/LiveChartsCore/Kernel/IChartView.cs +++ b/src/LiveChartsCore/Kernel/IChartView.cs @@ -113,14 +113,6 @@ public interface IChartView /// The tooltip position. /// TooltipPosition TooltipPosition { get; set; } - - /// - /// Gets or sets the tooltip finding strategy. - /// - /// - /// The tooltip finding strategy. - /// - TooltipFindingStrategy TooltipFindingStrategy { get; set; } } /// diff --git a/src/LiveChartsCore/Kernel/LiveChartsSettings.cs b/src/LiveChartsCore/Kernel/LiveChartsSettings.cs index 42a3ffdb0..eb46e3c61 100644 --- a/src/LiveChartsCore/Kernel/LiveChartsSettings.cs +++ b/src/LiveChartsCore/Kernel/LiveChartsSettings.cs @@ -100,7 +100,7 @@ public class LiveChartsSettings /// /// The default tooltip finding strategy. /// - public TooltipFindingStrategy DefaultTooltipFindingStrategy { get; set; } = TooltipFindingStrategy.CompareOnlyX; + public TooltipFindingStrategy DefaultTooltipFindingStrategy { get; set; } = TooltipFindingStrategy.Automatic; /// /// Gets the theme identifier. diff --git a/src/LiveChartsCore/Kernel/RectangleHoverArea.cs b/src/LiveChartsCore/Kernel/RectangleHoverArea.cs index ca1d018b9..bea471837 100644 --- a/src/LiveChartsCore/Kernel/RectangleHoverArea.cs +++ b/src/LiveChartsCore/Kernel/RectangleHoverArea.cs @@ -22,6 +22,7 @@ using LiveChartsCore.Measure; using System; +using System.Diagnostics; using System.Drawing; namespace LiveChartsCore.Kernel @@ -88,12 +89,14 @@ public override float GetDistanceToPoint(PointF point, TooltipFindingStrategy st var dx = point.X - (X + Width * 0.5f); var dy = point.Y - (Y + Height * 0.5f); + //Trace.WriteLine($"{Y:N2} {point.Y:N2}"); + return strategy switch { - TooltipFindingStrategy.CompareAll => (float)Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dx, 2)), + TooltipFindingStrategy.CompareAll => (float)Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2)), TooltipFindingStrategy.CompareOnlyX => Math.Abs(dx), TooltipFindingStrategy.CompareOnlyY => Math.Abs(dy), - _ => throw new Exception($"The strategy {strategy} is not supported."), + TooltipFindingStrategy.Automatic or _ => throw new Exception($"The strategy {strategy} is not supported.") }; } diff --git a/src/LiveChartsCore/Kernel/SeriesProperties.cs b/src/LiveChartsCore/Kernel/SeriesProperties.cs index b35cbfb10..527f7f017 100644 --- a/src/LiveChartsCore/Kernel/SeriesProperties.cs +++ b/src/LiveChartsCore/Kernel/SeriesProperties.cs @@ -90,6 +90,21 @@ public enum SeriesProperties /// /// The solid /// - Solid = 1 << 13 + Solid = 1 << 13, + + /// + /// The prefers x tool tips + /// + PrefersXStrategyTooltips = 1 << 14, + + /// + /// The prefers y tool tips + /// + PrefersYStrategyTooltips = 1 << 15, + + /// + /// The prefers xy tool tips + /// + PrefersXYStrategyTooltips = 1 << 16 } } diff --git a/src/LiveChartsCore/LineSeries.cs b/src/LiveChartsCore/LineSeries.cs index 8a7c84dcf..8270aff62 100644 --- a/src/LiveChartsCore/LineSeries.cs +++ b/src/LiveChartsCore/LineSeries.cs @@ -56,7 +56,9 @@ public class LineSeries /// if set to true [is stacked]. public LineSeries(bool isStacked = false) - : base(SeriesProperties.Line | SeriesProperties.PrimaryAxisVerticalOrientation | (isStacked ? SeriesProperties.Stacked : 0) | SeriesProperties.Sketch) + : base( + SeriesProperties.Line | SeriesProperties.PrimaryAxisVerticalOrientation | + (isStacked ? SeriesProperties.Stacked : 0) | SeriesProperties.Sketch | SeriesProperties.PrefersXStrategyTooltips) { DataPadding = new PointF(0.5f, 1f); HoverState = LiveCharts.LineSeriesHoverKey; diff --git a/src/LiveChartsCore/Measure/TooltipFindingStrategy.cs b/src/LiveChartsCore/Measure/TooltipFindingStrategy.cs index 6ed078ec3..fec1741fa 100644 --- a/src/LiveChartsCore/Measure/TooltipFindingStrategy.cs +++ b/src/LiveChartsCore/Measure/TooltipFindingStrategy.cs @@ -23,10 +23,15 @@ namespace LiveChartsCore.Measure { /// - /// Defines the tooltip finding strategy. + /// Defines the tool tip finding strategy. /// public enum TooltipFindingStrategy { + /// + /// The automatic mode, it will be calculated based on the series in the chart. + /// + Automatic, + /// /// Compares X and Y coordinates. /// diff --git a/src/LiveChartsCore/PieChart.cs b/src/LiveChartsCore/PieChart.cs index afff34944..717147ad5 100644 --- a/src/LiveChartsCore/PieChart.cs +++ b/src/LiveChartsCore/PieChart.cs @@ -127,7 +127,8 @@ public PieChart( /// public override IEnumerable FindPointsNearTo(PointF pointerPosition) { - return _chartView.Series.SelectMany(series => series.FindPointsNearTo(this, pointerPosition)); + return _chartView.Series.SelectMany( + series => series.FindPointsNearTo(this, pointerPosition, TooltipFindingStrategy.CompareAll)); } /// @@ -175,7 +176,6 @@ protected override void Measure() legend = _chartView.Legend; tooltipPosition = _chartView.TooltipPosition; - tooltipFindingStrategy = _chartView.TooltipFindingStrategy; tooltip = _chartView.Tooltip; animationsSpeed = _chartView.AnimationsSpeed; diff --git a/src/LiveChartsCore/RowSeries.cs b/src/LiveChartsCore/RowSeries.cs index 98bbca704..87513b0a2 100644 --- a/src/LiveChartsCore/RowSeries.cs +++ b/src/LiveChartsCore/RowSeries.cs @@ -46,7 +46,9 @@ public class RowSeries : BarSeries class. /// public RowSeries() - : base(SeriesProperties.Bar | SeriesProperties.PrimaryAxisHorizontalOrientation | SeriesProperties.Solid) { } + : base( + SeriesProperties.Bar | SeriesProperties.PrimaryAxisHorizontalOrientation + | SeriesProperties.Solid | SeriesProperties.PrefersYStrategyTooltips) { } /// public override void Measure( @@ -59,7 +61,7 @@ public override void Measure( primaryAxis.PreviousDataBounds == null ? null : new Scaler(drawLocation, drawMarginSize, primaryAxis); var primaryScale = new Scaler(drawLocation, drawMarginSize, secondaryAxis); - var uw = secondaryScale.ToPixels((float)primaryAxis.UnitWidth) - secondaryScale.ToPixels(0f); + var uw = secondaryScale.ToPixels(0f) - secondaryScale.ToPixels((float)primaryAxis.UnitWidth); var uwm = 0.5f * uw; uw -= (float)GroupPadding; @@ -81,7 +83,7 @@ public override void Measure( if (uw > MaxBarWidth) { - uw = (float)MaxBarWidth * -1; + uw = (float)MaxBarWidth; uwm = uw / 2f; } @@ -171,7 +173,7 @@ public override void Measure( sizedGeometry.Ry = ry; sizedGeometry.RemoveOnCompleted = false; - point.Context.HoverArea = new RectangleHoverArea().SetDimensions(primary, secondary - uwm + cp, b, uw); + point.Context.HoverArea = new RectangleHoverArea().SetDimensions(cx, y, b, uw); OnPointMeasured(point); _ = toDeletePoints.Remove(point); diff --git a/src/LiveChartsCore/ScatterSeries.cs b/src/LiveChartsCore/ScatterSeries.cs index d57b87b0b..61abc2cae 100644 --- a/src/LiveChartsCore/ScatterSeries.cs +++ b/src/LiveChartsCore/ScatterSeries.cs @@ -49,7 +49,7 @@ public class ScatterSeries : Cartesian /// Initializes a new instance of the class. /// public ScatterSeries() - : base(SeriesProperties.Scatter | SeriesProperties.Solid) + : base(SeriesProperties.Scatter | SeriesProperties.Solid | SeriesProperties.PrefersXYStrategyTooltips) { DataPadding = new PointF(1, 1); diff --git a/src/LiveChartsCore/Series.cs b/src/LiveChartsCore/Series.cs index 03af3d2b6..542fccb59 100644 --- a/src/LiveChartsCore/Series.cs +++ b/src/LiveChartsCore/Series.cs @@ -30,6 +30,7 @@ using System.ComponentModel; using System.Runtime.CompilerServices; using System.Linq; +using System.Diagnostics; namespace LiveChartsCore { @@ -223,9 +224,9 @@ IEnumerable ISeries.Fetch(IChart chart) return Fetch(chart); } - IEnumerable ISeries.FindPointsNearTo(IChart chart, PointF pointerPosition) + IEnumerable ISeries.FindPointsNearTo(IChart chart, PointF pointerPosition, TooltipFindingStrategy automaticStategy) { - return FilterTooltipPoints(Fetch(chart), chart, pointerPosition); + return FilterTooltipPoints(Fetch(chart), chart, pointerPosition, automaticStategy); } /// @@ -383,7 +384,7 @@ protected void OnPropertyChanged([CallerMemberName] string? propertyName = null) } private IEnumerable FilterTooltipPoints( - IEnumerable? points, IChart chart, PointF pointerPosition) + IEnumerable? points, IChart chart, PointF pointerPosition, TooltipFindingStrategy automaticStategy) { if (points == null) return Enumerable.Empty(); var tolerance = float.MaxValue; @@ -406,11 +407,12 @@ private IEnumerable FilterTooltipPoints( tolerance = (float)Math.Sqrt(Math.Pow(uwx, 2) + Math.Pow(uwy, 2)); break; case TooltipFindingStrategy.CompareOnlyX: - tolerance = uwx; + tolerance = Math.Abs(uwx); break; case TooltipFindingStrategy.CompareOnlyY: - tolerance = uwy; + tolerance = Math.Abs(uwy); break; + case TooltipFindingStrategy.Automatic: default: break; } @@ -421,7 +423,7 @@ private IEnumerable FilterTooltipPoints( foreach (var point in points) { if (point == null || point.Context.HoverArea == null) continue; - var d = point.Context.HoverArea.GetDistanceToPoint(pointerPosition, chart.TooltipFindingStrategy); + var d = point.Context.HoverArea.GetDistanceToPoint(pointerPosition, automaticStategy); //chart.TooltipFindingStrategy if (d > tolerance || d > minD.Item1) continue; if (minD.Item1 == d) @@ -434,6 +436,8 @@ private IEnumerable FilterTooltipPoints( minD = new Tuple>(d, new List { new TooltipPoint(this, point) }); } + Trace.WriteLine(minD.Item2.Count); + return minD.Item2; } diff --git a/src/LiveChartsCore/StackedColumnSeries.cs b/src/LiveChartsCore/StackedColumnSeries.cs index 331140dc2..2bebe161c 100644 --- a/src/LiveChartsCore/StackedColumnSeries.cs +++ b/src/LiveChartsCore/StackedColumnSeries.cs @@ -46,7 +46,9 @@ public class StackedColumnSeries : Sta /// Initializes a new instance of the class. /// public StackedColumnSeries() - : base(SeriesProperties.Bar | SeriesProperties.PrimaryAxisVerticalOrientation | SeriesProperties.Stacked | SeriesProperties.Solid) + : base( + SeriesProperties.Bar | SeriesProperties.PrimaryAxisVerticalOrientation | SeriesProperties.Stacked | + SeriesProperties.Solid | SeriesProperties.PrefersXStrategyTooltips) { DataPadding = new PointF(0, 1); } diff --git a/src/LiveChartsCore/StackedRowSeries.cs b/src/LiveChartsCore/StackedRowSeries.cs index b4a79003b..b2c315a24 100644 --- a/src/LiveChartsCore/StackedRowSeries.cs +++ b/src/LiveChartsCore/StackedRowSeries.cs @@ -46,7 +46,9 @@ public class StackedRowSeries : Stacke /// Initializes a new instance of the class. /// public StackedRowSeries() - : base(SeriesProperties.Bar | SeriesProperties.PrimaryAxisHorizontalOrientation | SeriesProperties.Stacked | SeriesProperties.Solid) + : base( + SeriesProperties.Bar | SeriesProperties.PrimaryAxisHorizontalOrientation | SeriesProperties.Stacked | + SeriesProperties.Solid | SeriesProperties.PrefersXStrategyTooltips) { } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/CartesianChart.axaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/CartesianChart.axaml.cs index 1fcef3c36..9ea1f992f 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/CartesianChart.axaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/CartesianChart.axaml.cs @@ -398,7 +398,7 @@ public TooltipPosition TooltipPosition set => SetValue(TooltipPositionProperty, value); } - /// + /// public TooltipFindingStrategy TooltipFindingStrategy { get => (TooltipFindingStrategy)GetValue(TooltipFindingStrategyProperty); diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/PieChart.axaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/PieChart.axaml.cs index dad1507eb..b40161645 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/PieChart.axaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/PieChart.axaml.cs @@ -168,13 +168,6 @@ public PieChart() AvaloniaProperty.Register( nameof(TooltipPosition), LiveCharts.CurrentSettings.DefaultTooltipPosition, inherits: true); - /// - /// The tool tip finding strategy property - /// - public static readonly AvaloniaProperty TooltipFindingStrategyProperty = - AvaloniaProperty.Register( - nameof(LegendPosition), LiveCharts.CurrentSettings.DefaultTooltipFindingStrategy, inherits: true); - /// /// The tool tip font family property /// @@ -375,13 +368,6 @@ public TooltipPosition TooltipPosition set => SetValue(TooltipPositionProperty, value); } - /// - public TooltipFindingStrategy TooltipFindingStrategy - { - get => (TooltipFindingStrategy)GetValue(TooltipFindingStrategyProperty); - set => SetValue(TooltipFindingStrategyProperty, value); - } - /// /// Gets or sets the tool data tip template. /// diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/CartesianChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/CartesianChart.cs index bed5afa26..7264feab4 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/CartesianChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/CartesianChart.cs @@ -152,6 +152,14 @@ public CartesianChart() nameof(ZoomingSpeed), typeof(double), typeof(CartesianChart), new PropertyMetadata(LiveCharts.CurrentSettings.DefaultZoomSpeed)); + /// + /// The tool tip finding strategy property + /// + public static readonly DependencyProperty TooltipFindingStrategyProperty = + DependencyProperty.Register( + nameof(TooltipFindingStrategy), typeof(TooltipFindingStrategy), typeof(Chart), + new PropertyMetadata(LiveCharts.CurrentSettings.DefaultTooltipFindingStrategy, OnDependencyPropertyChanged)); + #endregion #region properties @@ -206,6 +214,14 @@ double ICartesianChartView.ZoomingSpeed set => SetValueOrCurrentValue(ZoomingSpeedProperty, value); } + + /// + public TooltipFindingStrategy TooltipFindingStrategy + { + get => (TooltipFindingStrategy)GetValue(TooltipFindingStrategyProperty); + set => SetValue(TooltipFindingStrategyProperty, value); + } + #endregion /// diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/Chart.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/Chart.cs index 786be3d51..cbf2d4e82 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/Chart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/Chart.cs @@ -136,14 +136,6 @@ public Chart() nameof(TooltipPosition), typeof(TooltipPosition), typeof(Chart), new PropertyMetadata(LiveCharts.CurrentSettings.DefaultTooltipPosition, OnDependencyPropertyChanged)); - /// - /// The tool tip finding strategy property - /// - public static readonly DependencyProperty TooltipFindingStrategyProperty = - DependencyProperty.Register( - nameof(TooltipFindingStrategy), typeof(TooltipFindingStrategy), typeof(Chart), - new PropertyMetadata(LiveCharts.CurrentSettings.DefaultTooltipFindingStrategy, OnDependencyPropertyChanged)); - /// /// The tool tip background property /// @@ -373,19 +365,6 @@ TooltipPosition IChartView.TooltipPosition set => SetValueOrCurrentValue(TooltipPositionProperty, value); } - /// - public TooltipFindingStrategy TooltipFindingStrategy - { - get => (TooltipFindingStrategy)GetValue(TooltipFindingStrategyProperty); - set => SetValue(TooltipFindingStrategyProperty, value); - } - - TooltipFindingStrategy IChartView.TooltipFindingStrategy - { - get => TooltipFindingStrategy; - set => SetValueOrCurrentValue(TooltipFindingStrategyProperty, value); - } - /// /// Gets or sets the tool tip template. /// diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/CartesianChart.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/CartesianChart.cs index e447be921..8bfa64ce6 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/CartesianChart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/CartesianChart.cs @@ -46,6 +46,7 @@ public class CartesianChart : Chart, ICartesianChartView _series = new List(); private IEnumerable _xAxes = new List { new Axis() }; private IEnumerable _yAxes = new List { new Axis() }; + private TooltipFindingStrategy _tooltipFindingStrategy = LiveCharts.CurrentSettings.DefaultTooltipFindingStrategy; /// /// Initializes a new instance of the class. @@ -126,6 +127,9 @@ public IEnumerable YAxes [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public double ZoomingSpeed { get; set; } = LiveCharts.CurrentSettings.DefaultZoomSpeed; + /// + public TooltipFindingStrategy TooltipFindingStrategy { get => _tooltipFindingStrategy; set { _tooltipFindingStrategy = value; OnPropertyChanged(); } } + /// /// Initializes the core. /// diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/Chart.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/Chart.cs index 607f3e7c0..ea1db9ac1 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/Chart.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/Chart.cs @@ -60,7 +60,6 @@ public abstract class Chart : UserControl, IChartView private LegendOrientation _legendOrientation = LiveCharts.CurrentSettings.DefaultLegendOrientation; private Margin? _drawMargin = null; private TooltipPosition _tooltipPosition = LiveCharts.CurrentSettings.DefaultTooltipPosition; - private TooltipFindingStrategy _tooltipFindingStrategy = LiveCharts.CurrentSettings.DefaultTooltipFindingStrategy; private Font _tooltipFont = new(new FontFamily("Trebuchet MS"), 11, FontStyle.Regular); private Color _tooltipBackColor = Color.FromArgb(255, 250, 250, 250); private Font _legendFont = new(new FontFamily("Trebuchet MS"), 11, FontStyle.Regular); @@ -187,9 +186,6 @@ Color IChartView.BackColor /// public TooltipPosition TooltipPosition { get => _tooltipPosition; set { _tooltipPosition = value; OnPropertyChanged(); } } - /// - public TooltipFindingStrategy TooltipFindingStrategy { get => _tooltipFindingStrategy; set { _tooltipFindingStrategy = value; OnPropertyChanged(); } } - /// /// Gets or sets the default tool tip font. /// diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/PieChart.xaml.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/PieChart.xaml.cs index b4831348b..7a1592d80 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/PieChart.xaml.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/PieChart.xaml.cs @@ -1,5 +1,4 @@ -\ -// The MIT License(MIT) +// The MIT License(MIT) // // Copyright(c) 2021 Alberto Rodriguez Orozco & LiveCharts Contributors // @@ -224,14 +223,6 @@ public PieChart() nameof(TooltipPosition), typeof(TooltipPosition), typeof(CartesianChart), LiveCharts.CurrentSettings.DefaultTooltipPosition, propertyChanged: OnBindablePropertyChanged); - /// - /// The tool tip finding strategy property - /// - public static readonly BindableProperty TooltipFindingStrategyProperty = - BindableProperty.Create( - nameof(TooltipFindingStrategy), typeof(TooltipFindingStrategy), typeof(CartesianChart), - LiveCharts.CurrentSettings.DefaultTooltipFindingStrategy); - /// /// The tool tip template property /// @@ -469,13 +460,6 @@ public TooltipPosition TooltipPosition set => SetValue(TooltipPositionProperty, value); } - /// - public TooltipFindingStrategy TooltipFindingStrategy - { - get => (TooltipFindingStrategy)GetValue(TooltipFindingStrategyProperty); - set => SetValue(TooltipFindingStrategyProperty, value); - } - /// /// Gets or sets the tool tip template. ///