1111
1212namespace SourceGit . Models
1313{
14- public enum StaticsticsMode
14+ public enum StatisticsMode
1515 {
1616 All ,
1717 ThisMonth ,
1818 ThisWeek ,
1919 }
2020
21- public class StaticsticsAuthor ( User user , int count )
21+ public class StatisticsAuthor ( User user , int count )
2222 {
2323 public User User { get ; set ; } = user ;
2424 public int Count { get ; set ; } = count ;
2525 }
2626
27- public class StaticsticsSample ( DateTime time , int count )
28- {
29- public DateTime Time { get ; set ; } = time ;
30- public int Count { get ; set ; } = count ;
31- }
32-
3327 public class StatisticsReport
3428 {
3529 public static readonly string [ ] WEEKDAYS = [ "SUN" , "MON" , "TUE" , "WED" , "THU" , "FRI" , "SAT" ] ;
3630
3731 public int Total { get ; set ; } = 0 ;
38- public List < StaticsticsAuthor > Authors { get ; set ; } = new List < StaticsticsAuthor > ( ) ;
32+ public List < StatisticsAuthor > Authors { get ; set ; } = new List < StatisticsAuthor > ( ) ;
3933 public List < ISeries > Series { get ; set ; } = new List < ISeries > ( ) ;
4034 public List < Axis > XAxes { get ; set ; } = new List < Axis > ( ) ;
4135 public List < Axis > YAxes { get ; set ; } = new List < Axis > ( ) ;
36+ public StatisticsAuthor SelectedAuthor { get => _selectedAuthor ; set => ChangeAuthor ( value ) ; }
4237
43- public StatisticsReport ( StaticsticsMode mode , DateTime start )
38+ public StatisticsReport ( StatisticsMode mode , DateTime start )
4439 {
4540 _mode = mode ;
4641
@@ -51,14 +46,14 @@ public StatisticsReport(StaticsticsMode mode, DateTime start)
5146 SeparatorsPaint = new SolidColorPaint ( new SKColor ( 0x40808080 ) ) { StrokeThickness = 1 }
5247 } ] ;
5348
54- if ( mode == StaticsticsMode . ThisWeek )
49+ if ( mode == StatisticsMode . ThisWeek )
5550 {
5651 for ( int i = 0 ; i < 7 ; i ++ )
5752 _mapSamples . Add ( start . AddDays ( i ) , 0 ) ;
5853
5954 XAxes . Add ( new DateTimeAxis ( TimeSpan . FromDays ( 1 ) , v => WEEKDAYS [ ( int ) v . DayOfWeek ] ) { TextSize = 10 } ) ;
6055 }
61- else if ( mode == StaticsticsMode . ThisMonth )
56+ else if ( mode == StatisticsMode . ThisMonth )
6257 {
6358 var now = DateTime . Now ;
6459 var maxDays = DateTime . DaysInMonth ( now . Year , now . Month ) ;
@@ -78,7 +73,7 @@ public void AddCommit(DateTime time, User author)
7873 Total ++ ;
7974
8075 var normalized = DateTime . MinValue ;
81- if ( _mode == StaticsticsMode . ThisWeek || _mode == StaticsticsMode . ThisMonth )
76+ if ( _mode == StatisticsMode . ThisWeek || _mode == StatisticsMode . ThisMonth )
8277 normalized = time . Date ;
8378 else
8479 normalized = new DateTime ( time . Year , time . Month , 1 ) . ToLocalTime ( ) ;
@@ -92,10 +87,30 @@ public void AddCommit(DateTime time, User author)
9287 _mapUsers [ author ] = vu + 1 ;
9388 else
9489 _mapUsers . Add ( author , 1 ) ;
90+
91+ if ( _mapUserSamples . TryGetValue ( author , out var vus ) )
92+ {
93+ if ( vus . TryGetValue ( normalized , out var n ) )
94+ vus [ normalized ] = n + 1 ;
95+ else
96+ vus . Add ( normalized , 1 ) ;
97+ }
98+ else
99+ {
100+ _mapUserSamples . Add ( author , new Dictionary < DateTime , int >
101+ {
102+ { normalized , 1 }
103+ } ) ;
104+ }
95105 }
96106
97107 public void Complete ( )
98108 {
109+ foreach ( var kv in _mapUsers )
110+ Authors . Add ( new StatisticsAuthor ( kv . Key , kv . Value ) ) ;
111+
112+ Authors . Sort ( ( l , r ) => r . Count - l . Count ) ;
113+
99114 var samples = new List < DateTimePoint > ( ) ;
100115 foreach ( var kv in _mapSamples )
101116 samples . Add ( new DateTimePoint ( kv . Key , kv . Value ) ) ;
@@ -110,24 +125,59 @@ public void Complete()
110125 }
111126 ) ;
112127
113- foreach ( var kv in _mapUsers )
114- Authors . Add ( new StaticsticsAuthor ( kv . Key , kv . Value ) ) ;
115-
116- Authors . Sort ( ( l , r ) => r . Count - l . Count ) ;
117-
118128 _mapUsers . Clear ( ) ;
119129 _mapSamples . Clear ( ) ;
120130 }
121131
122132 public void ChangeColor ( uint color )
123133 {
124- if ( Series is [ ColumnSeries < DateTimePoint > series ] )
125- series . Fill = new SolidColorPaint ( new SKColor ( color ) ) ;
134+ _fillColor = color ;
135+
136+ var fill = new SKColor ( color ) ;
137+
138+ if ( Series . Count > 0 && Series [ 0 ] is ColumnSeries < DateTimePoint > total )
139+ total . Fill = new SolidColorPaint ( _selectedAuthor == null ? fill : fill . WithAlpha ( 51 ) ) ;
140+
141+ if ( Series . Count > 1 && Series [ 1 ] is ColumnSeries < DateTimePoint > user )
142+ user . Fill = new SolidColorPaint ( fill ) ;
143+ }
144+
145+ public void ChangeAuthor ( StatisticsAuthor author )
146+ {
147+ if ( author == _selectedAuthor )
148+ return ;
149+
150+ _selectedAuthor = author ;
151+ Series . RemoveRange ( 1 , Series . Count - 1 ) ;
152+ if ( author == null || ! _mapUserSamples . TryGetValue ( author . User , out var userSamples ) )
153+ {
154+ ChangeColor ( _fillColor ) ;
155+ return ;
156+ }
157+
158+ var samples = new List < DateTimePoint > ( ) ;
159+ foreach ( var kv in userSamples )
160+ samples . Add ( new DateTimePoint ( kv . Key , kv . Value ) ) ;
161+
162+ Series . Add (
163+ new ColumnSeries < DateTimePoint > ( )
164+ {
165+ Values = samples ,
166+ Stroke = null ,
167+ Fill = null ,
168+ Padding = 1 ,
169+ }
170+ ) ;
171+
172+ ChangeColor ( _fillColor ) ;
126173 }
127174
128- private StaticsticsMode _mode = StaticsticsMode . All ;
175+ private StatisticsMode _mode = StatisticsMode . All ;
129176 private Dictionary < User , int > _mapUsers = new Dictionary < User , int > ( ) ;
130177 private Dictionary < DateTime , int > _mapSamples = new Dictionary < DateTime , int > ( ) ;
178+ private Dictionary < User , Dictionary < DateTime , int > > _mapUserSamples = new Dictionary < User , Dictionary < DateTime , int > > ( ) ;
179+ private StatisticsAuthor _selectedAuthor = null ;
180+ private uint _fillColor = 255 ;
131181 }
132182
133183 public class Statistics
@@ -143,9 +193,9 @@ public Statistics()
143193 _thisWeekStart = _today . AddDays ( - weekOffset ) ;
144194 _thisMonthStart = _today . AddDays ( 1 - _today . Day ) ;
145195
146- All = new StatisticsReport ( StaticsticsMode . All , DateTime . MinValue ) ;
147- Month = new StatisticsReport ( StaticsticsMode . ThisMonth , _thisMonthStart ) ;
148- Week = new StatisticsReport ( StaticsticsMode . ThisWeek , _thisWeekStart ) ;
196+ All = new StatisticsReport ( StatisticsMode . All , DateTime . MinValue ) ;
197+ Month = new StatisticsReport ( StatisticsMode . ThisMonth , _thisMonthStart ) ;
198+ Week = new StatisticsReport ( StatisticsMode . ThisWeek , _thisWeekStart ) ;
149199 }
150200
151201 public void AddCommit ( string author , double timestamp )
0 commit comments