Skip to content
Closed
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
90 changes: 88 additions & 2 deletions src/Models/Statistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,27 @@ public class StaticsticsSample(DateTime time, int count)

public class StatisticsReport
{
private const float OPACITY_DIMMED = 0.3f;

public static readonly string[] WEEKDAYS = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];

public int Total { get; set; } = 0;
public List<StaticsticsAuthor> Authors { get; set; } = new List<StaticsticsAuthor>();
public List<ISeries> Series { get; set; } = new List<ISeries>();
public List<Axis> XAxes { get; set; } = new List<Axis>();
public List<Axis> YAxes { get; set; } = new List<Axis>();

private StaticsticsAuthor _selectedAuthor = null;
public StaticsticsAuthor SelectedAuthor
{
get => _selectedAuthor;
set
{
_selectedAuthor = value;

UpdateHighlighting();
}
}

public StatisticsReport(StaticsticsMode mode, DateTime start)
{
Expand Down Expand Up @@ -92,6 +106,18 @@ public void AddCommit(DateTime time, User author)
_mapUsers[author] = vu + 1;
else
_mapUsers.Add(author, 1);

if (!_authorCommitsByDate.TryGetValue(author, out var authorDates))
{
authorDates = new Dictionary<DateTime, int>();

_authorCommitsByDate.Add(author, authorDates);
}

if (authorDates.TryGetValue(normalized, out var authorDateCount))
authorDates[normalized] = authorDateCount + 1;
else
authorDates.Add(normalized, 1);
}

public void Complete()
Expand Down Expand Up @@ -121,13 +147,73 @@ public void Complete()

public void ChangeColor(uint color)
{
if (Series is [ColumnSeries<DateTimePoint> series])
series.Fill = new SolidColorPaint(new SKColor(color));
_currentColor = color;

UpdateHighlighting();
}

private void UpdateHighlighting()
{
if (Series.Count == 0)
return;

var skColor = new SKColor(_currentColor);

if (_selectedAuthor == null)
{
if (Series.Count > 1)
Series.RemoveAt(1);

if (Series is [ColumnSeries<DateTimePoint> series])
series.Fill = new SolidColorPaint(skColor);
}
else
{
var dimmedColor = new SKColor(skColor.Red, skColor.Green, skColor.Blue, (byte)(255 * OPACITY_DIMMED));

if (Series is [ColumnSeries<DateTimePoint> series, ..])
series.Fill = new SolidColorPaint(dimmedColor);

if (_authorCommitsByDate.TryGetValue(_selectedAuthor.User, out var authorData))
{
var highlightSamples = new List<DateTimePoint>();

foreach (var kv in authorData)
highlightSamples.Add(new DateTimePoint(kv.Key, kv.Value));

highlightSamples.Sort((a, b) => a.DateTime.CompareTo(b.DateTime));

if (Series.Count > 1)
{
if (Series[1] is ColumnSeries<DateTimePoint> highlightSeries)
highlightSeries.Values = highlightSamples;
}
else
{
Series.Add(new ColumnSeries<DateTimePoint>
{
Values = highlightSamples,
Stroke = null,
Fill = new SolidColorPaint(skColor),
Padding = 1,
});
}
}
}
}

public void ResetSelection()
{
_selectedAuthor = null;

UpdateHighlighting();
}

private StaticsticsMode _mode = StaticsticsMode.All;
private Dictionary<User, int> _mapUsers = new Dictionary<User, int>();
private Dictionary<DateTime, int> _mapSamples = new Dictionary<DateTime, int>();
private Dictionary<User, Dictionary<DateTime, int>> _authorCommitsByDate = new Dictionary<User, Dictionary<DateTime, int>>();
private uint _currentColor;
}

public class Statistics
Expand Down
18 changes: 18 additions & 0 deletions src/ViewModels/Statistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ public IBrush SampleBrush
get => new SolidColorBrush(SampleColor);
}

public Models.StaticsticsAuthor SelectedAuthor
{
get => _selectedAuthor;
set
{
if (SetProperty(ref _selectedAuthor, value))
{
_selectedReport?.ResetSelection();

_selectedReport.SelectedAuthor = value;
}
}
}

public Statistics(string repo)
{
Task.Run(() =>
Expand All @@ -69,13 +83,16 @@ private void RefreshReport()
if (_data == null)
return;

SetProperty(ref _selectedAuthor, null);

var report = _selectedIndex switch
{
0 => _data.All,
1 => _data.Month,
_ => _data.Week,
};

report.ResetSelection();
report.ChangeColor(SampleColor);
SelectedReport = report;
}
Expand All @@ -84,5 +101,6 @@ private void RefreshReport()
private Models.Statistics _data = null;
private Models.StatisticsReport _selectedReport = null;
private int _selectedIndex = 0;
private Models.StaticsticsAuthor _selectedAuthor = null;
}
}
1 change: 1 addition & 0 deletions src/Views/Statistics.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<!-- Table By Autor -->
<ListBox Grid.Column="0"
ItemsSource="{Binding Authors}"
SelectedItem="{Binding $parent[ContentControl].((vm:Statistics)DataContext).SelectedAuthor, Mode=TwoWay}"
SelectionMode="Single"
BorderThickness="1"
BorderBrush="{DynamicResource Brush.Border2}"
Expand Down