Skip to content

Commit

Permalink
changes made
Browse files Browse the repository at this point in the history
  • Loading branch information
subash-sf committed Oct 29, 2024
1 parent 5c912ce commit 591f90f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 41 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,4 @@ public partial class MainWindow : Window
### Path too long exception
If you are facing a path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project.

For more details, refer to the KB on [How to add multiple trackballs in a WPF SfChart?](https://support.syncfusion.com/agent/kb/17741/edit).



For more details, refer to the KB on [How to add multiple trackballs in a WPF SfChart?]().
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,11 @@ async Task ShowTrackball()
}
}

public class Model
{
public string Day { get; set; }
public double CPULoad { get; set; }
}

public class ViewModel
{
public List<Model> Data { get; set; }

public ViewModel()
{
Data = new List<Model>
{
new Model { Day = "Monday", CPULoad = 35 },
new Model { Day = "Tuesday", CPULoad = 42 },
new Model { Day = "Wednesday", CPULoad = 18 },
new Model { Day = "Thursday", CPULoad = 30 },
new Model { Day = "Friday", CPULoad = 64 },
new Model { Day = "Saturday", CPULoad = 22 },
new Model { Day = "Sunday", CPULoad = 10 }
};
}
}

public class ChartTrackBallBehaviorExt : ChartTrackBallBehavior
{
private bool isTrackballActive = false;

public SfChart SfChart { get; set; }
public SfChart? SfChart { get; set; }

public double X { get; set; }
public double Y { get; set; }
Expand Down Expand Up @@ -121,24 +96,27 @@ protected override void OnMouseLeave(MouseEventArgs e)
isTrackballActive = false;
}

private ChartTrackBallBehavior FindNearestTrackball(Point touchPoint)
private ChartTrackBallBehavior? FindNearestTrackball(Point touchPoint)
{
ChartTrackBallBehavior nearestTrackball = null;
ChartTrackBallBehavior? nearestTrackball = null;
double minDistance = double.MaxValue;

// Iterate through all trackball behaviors to find the nearest one
foreach (var trackballBehaviour in SfChart.Behaviors)
if (SfChart != null)
{
if (trackballBehaviour is ChartTrackBallBehaviorExt trackball)
foreach (var trackballBehaviour in SfChart.Behaviors)
{
// Calculate the distance between the trackball and the touch point
double distance = Math.Sqrt(Math.Pow(trackball.X - touchPoint.X, 2) + Math.Pow(trackball.Y - touchPoint.Y, 2));

// Update the nearest trackball if the current one is closer
if (distance < minDistance)
if (trackballBehaviour is ChartTrackBallBehaviorExt trackball)
{
minDistance = distance;
nearestTrackball = trackball;
// Calculate the distance between the trackball and the touch point
double distance = Math.Sqrt(Math.Pow(trackball.X - touchPoint.X, 2) + Math.Pow(trackball.Y - touchPoint.Y, 2));

// Update the nearest trackball if the current one is closer
if (distance < minDistance)
{
minDistance = distance;
nearestTrackball = trackball;
}
}
}
}
Expand Down

0 comments on commit 591f90f

Please sign in to comment.