Skip to content

Commit b9b5ee6

Browse files
committed
refactor: Optimize ancestor lookups and dot search logic
1 parent bb112a9 commit b9b5ee6

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/Views/Histories.axaml.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -535,16 +535,15 @@ public override void Render(DrawingContext context)
535535
if (graph == null)
536536
return;
537537

538-
var histories = this.FindAncestorOfType<Histories>();
539-
if (histories == null)
540-
return;
538+
_repoView = this.FindAncestorOfType<Repository>();
539+
_histories = this.FindAncestorOfType<Histories>();
541540

542-
var list = histories.CommitListContainer;
541+
var list = _histories?.CommitListContainer;
543542
if (list == null)
544543
return;
545544

546545
// Calculate drawing area.
547-
double width = Bounds.Width - 273 - histories.AuthorNameColumnWidth.Value;
546+
double width = Bounds.Width - 273 - _histories.AuthorNameColumnWidth.Value;
548547
double height = Bounds.Height;
549548
double startY = list.Scroll?.Offset.Y ?? 0;
550549
double endY = startY + height + 28;
@@ -717,8 +716,7 @@ private void OnPointerPressed(object sender, PointerPressedEventArgs e)
717716
{
718717
var point = e.GetPosition(this);
719718
var dot = FindDotAtPosition(point);
720-
var repoView = this.FindAncestorOfType<Repository>();
721-
var repoPath = (repoView?.DataContext as ViewModels.Repository)?.FullPath;
719+
var repoPath = (_repoView?.DataContext as ViewModels.Repository)?.FullPath;
722720
if (dot == null || string.IsNullOrEmpty(repoPath))
723721
return;
724722

@@ -746,22 +744,32 @@ private Models.CommitGraph.Dot FindDotAtPosition(Point point)
746744
return null;
747745

748746
// get scroll offset
749-
var histories = this.FindAncestorOfType<Histories>();
750-
var scrollOffset = histories?.CommitListContainer.Scroll?.Offset.Y ?? 0;
747+
var scrollOffset = _histories?.CommitListContainer.Scroll?.Offset.Y ?? 0;
751748

752749
// adjust point
753750
var adjustedPoint = new Point(point.X, point.Y + scrollOffset);
751+
var searchRadius = 9.0;
754752

755753
foreach (var dot in graph.Dots)
756754
{
755+
if (!(Math.Abs(dot.Center.X - adjustedPoint.X) <= searchRadius) ||
756+
!(Math.Abs(dot.Center.Y - adjustedPoint.Y) <= searchRadius))
757+
{
758+
continue;
759+
}
760+
757761
var distance = Math.Sqrt(Math.Pow(dot.Center.X - adjustedPoint.X, 2) + Math.Pow(dot.Center.Y - adjustedPoint.Y, 2));
758-
if (distance <= 6)
762+
if (distance <= searchRadius)
759763
{
760764
return dot;
761765
}
762766
}
767+
763768
return null;
764769
}
770+
771+
private Histories _histories;
772+
private Repository _repoView;
765773
}
766774

767775
public partial class Histories : UserControl

0 commit comments

Comments
 (0)