Skip to content
Open
Show file tree
Hide file tree
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
41 changes: 27 additions & 14 deletions src/Views/PieChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,21 @@ public IBrush SecondaryForeground
set => SetValue(SecondaryForegroundProperty, value);
}

public static readonly StyledProperty<IBrush> BorderBrushProperty =
AvaloniaProperty.Register<PieChart, IBrush>(nameof(BorderBrush), Brushes.White);

public IBrush BorderBrush
{
get => GetValue(BorderBrushProperty);
set => SetValue(BorderBrushProperty, value);
}

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 +134,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 +155,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 All @@ -159,6 +169,8 @@ public override void Render(DrawingContext context)
}
}

context.DrawLine(new Pen(BorderBrush, 1), _center, new Point(_center.X, _center.Y - _radius));

if (leftArcs.Count > 0)
{
for (var i = leftArcs.Count - 1; i >= 0; i--)
Expand Down Expand Up @@ -248,13 +260,14 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang

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

if (change.Property == ReportProperty ||
change.Property == FontFamilyProperty ||
change.Property == ForegroundProperty ||
change.Property == BorderBrushProperty ||
change.Property == SecondaryForegroundProperty)
InvalidateVisual();
}
Expand All @@ -265,7 +278,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 +287,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 +300,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 +383,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;
}
}
1 change: 1 addition & 0 deletions src/Views/Statistics.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@
FontFamily="{DynamicResource Fonts.Default}"
SecondaryFontFamily="{DynamicResource Fonts.Monospace}"
Foreground="{DynamicResource Brush.FG1}"
BorderBrush="{DynamicResource Brush.Window}"
SecondaryForeground="{DynamicResource Brush.FG2}"/>

<ContentControl Grid.Row="1"
Expand Down
Loading