@@ -71,7 +71,7 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
71
71
var unsolved = new List < PathHelper > ( ) ;
72
72
var ended = new List < PathHelper > ( ) ;
73
73
var offsetY = - halfHeight ;
74
- var colorIdx = 0 ;
74
+ var colorPicker = new ColorPicker ( ) ;
75
75
76
76
foreach ( var commit in commits )
77
77
{
@@ -121,7 +121,10 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
121
121
122
122
// Remove ended curves from unsolved
123
123
foreach ( var l in ended )
124
+ {
125
+ colorPicker . Recycle ( l . Path . Color ) ;
124
126
unsolved . Remove ( l ) ;
127
+ }
125
128
ended . Clear ( ) ;
126
129
127
130
// If no path found, create new curve for branch head
@@ -132,12 +135,10 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
132
135
133
136
if ( commit . Parents . Count > 0 )
134
137
{
135
- major = new PathHelper ( commit . Parents [ 0 ] , isMerged , colorIdx , new Point ( offsetX , offsetY ) ) ;
138
+ major = new PathHelper ( commit . Parents [ 0 ] , isMerged , colorPicker . Next ( ) , new Point ( offsetX , offsetY ) ) ;
136
139
unsolved . Add ( major ) ;
137
140
temp . Paths . Add ( major . Path ) ;
138
141
}
139
-
140
- colorIdx = ( colorIdx + 1 ) % s_penCount ;
141
142
}
142
143
else if ( isMerged && ! major . IsMerged && commit . Parents . Count > 0 )
143
144
{
@@ -187,10 +188,9 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
187
188
offsetX += unitWidth ;
188
189
189
190
// Create new curve for parent commit that not includes before
190
- var l = new PathHelper ( parentHash , isMerged , colorIdx , position , new Point ( offsetX , position . Y + halfHeight ) ) ;
191
+ var l = new PathHelper ( parentHash , isMerged , colorPicker . Next ( ) , position , new Point ( offsetX , position . Y + halfHeight ) ) ;
191
192
unsolved . Add ( l ) ;
192
193
temp . Paths . Add ( l . Path ) ;
193
- colorIdx = ( colorIdx + 1 ) % s_penCount ;
194
194
}
195
195
}
196
196
}
@@ -217,6 +217,28 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
217
217
return temp ;
218
218
}
219
219
220
+ private class ColorPicker
221
+ {
222
+ public int Next ( )
223
+ {
224
+ if ( _colorsQueue . Count == 0 )
225
+ {
226
+ for ( var i = 0 ; i < s_penCount ; i ++ )
227
+ _colorsQueue . Enqueue ( i ) ;
228
+ }
229
+
230
+ return _colorsQueue . Dequeue ( ) ;
231
+ }
232
+
233
+ public void Recycle ( int idx )
234
+ {
235
+ if ( ! _colorsQueue . Contains ( idx ) )
236
+ _colorsQueue . Enqueue ( idx ) ;
237
+ }
238
+
239
+ private Queue < int > _colorsQueue = new Queue < int > ( ) ;
240
+ }
241
+
220
242
private class PathHelper
221
243
{
222
244
public Path Path { get ; private set ; }
0 commit comments