Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/Views/PieChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public override void Render(DrawingContext context)
base.Render(context);

_arcs.Clear();
_lastHoverred = null;
_lastHovered = null;

var w = Bounds.Width;
var h = Bounds.Height;
Expand Down Expand Up @@ -125,10 +125,10 @@ public override void Render(DrawingContext context)
foreach (var author in _report.Authors)
{
var percent = (double)author.Count / total;
var brush = s_brushes[brushIndex];
if (percent > 0.01)
{
var sweepAngle = percent * 2 * Math.PI;
var brush = s_brushes[brushIndex];
DrawArc(context, startAngle, sweepAngle, brush);

var arc = new Arc(startAngle, sweepAngle, author.User.Name, author.Count, percent, brush, author);
Expand All @@ -146,10 +146,11 @@ public override void Render(DrawingContext context)
else
{
var sweepAngle = remaining;
var othersBrush = secondaryForeground;
var count = total - renderedCount;
DrawArc(context, startAngle, sweepAngle, brush);
DrawArc(context, startAngle, sweepAngle, othersBrush);

var arc = new Arc(startAngle, sweepAngle, "Others", count, (double)count / total, brush, null);
var arc = new Arc(startAngle, sweepAngle, "Others", count, (double)count / total, othersBrush, null);
_arcs.Add(arc);
if (arc.IsLeftSide)
leftArcs.Add(arc);
Expand Down Expand Up @@ -248,7 +249,7 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang

if (change.Property == ReportProperty)
{
_lastHoverred = null;
_lastHovered = null;
HoveringTip = null;
}

Expand All @@ -265,7 +266,7 @@ protected override void OnPointerMoved(PointerEventArgs e)

if (_report == null || _report.Authors.Count == 0)
{
_lastHoverred = null;
_lastHovered = null;
HoveringTip = null;
return;
}
Expand All @@ -274,7 +275,7 @@ protected override void OnPointerMoved(PointerEventArgs e)
var distance = Math.Sqrt(Math.Pow(pos.X - _center.X, 2) + Math.Pow(pos.Y - _center.Y, 2));
if (distance > _radius)
{
_lastHoverred = null;
_lastHovered = null;
HoveringTip = null;
return;
}
Expand All @@ -287,32 +288,32 @@ protected override void OnPointerMoved(PointerEventArgs e)
{
if (angle >= arc.StartAngle && angle < arc.EndAngle)
{
if (_lastHoverred == arc)
if (_lastHovered == arc)
return;

_lastHoverred = arc;
_lastHovered = arc;
HoveringTip = arc.Tip;
return;
}
}

_lastHoverred = null;
_lastHovered = null;
HoveringTip = null;
}

protected override void OnPointerPressed(PointerPressedEventArgs e)
{
base.OnPointerPressed(e);

if (_lastHoverred != null)
if (_lastHovered != null)
{
var statisticsView = this.FindAncestorOfType<Statistics>();
if (statisticsView is { DataContext: ViewModels.Statistics vm })
{
if (_lastHoverred.Author == null || _lastHoverred.Author == vm.SelectedAuthor)
if (_lastHovered.Author == null || _lastHovered.Author == vm.SelectedAuthor)
vm.ChangeAuthor(null);
else
vm.ChangeAuthor(_lastHoverred.Author);
vm.ChangeAuthor(_lastHovered.Author);
}
}
}
Expand Down Expand Up @@ -370,7 +371,7 @@ public Arc(double startAngle, double sweepAngle, string title, int count, double
private Point _center = new Point(0, 0);
private double _radius = 0;
private List<Arc> _arcs = new List<Arc>();
private Arc _lastHoverred = null;
private Arc _lastHovered = null;
private PieChartToolTip _hoveringTip = null;
}
}
Loading