mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2025-01-11 23:57:21 -08:00
enhance: graph color allocation
This commit is contained in:
parent
0391ec99b4
commit
7a217336dc
1 changed files with 28 additions and 6 deletions
|
@ -71,7 +71,7 @@ namespace SourceGit.Models
|
||||||
var unsolved = new List<PathHelper>();
|
var unsolved = new List<PathHelper>();
|
||||||
var ended = new List<PathHelper>();
|
var ended = new List<PathHelper>();
|
||||||
var offsetY = -halfHeight;
|
var offsetY = -halfHeight;
|
||||||
var colorIdx = 0;
|
var colorPicker = new ColorPicker();
|
||||||
|
|
||||||
foreach (var commit in commits)
|
foreach (var commit in commits)
|
||||||
{
|
{
|
||||||
|
@ -121,7 +121,10 @@ namespace SourceGit.Models
|
||||||
|
|
||||||
// Remove ended curves from unsolved
|
// Remove ended curves from unsolved
|
||||||
foreach (var l in ended)
|
foreach (var l in ended)
|
||||||
|
{
|
||||||
|
colorPicker.Recycle(l.Path.Color);
|
||||||
unsolved.Remove(l);
|
unsolved.Remove(l);
|
||||||
|
}
|
||||||
ended.Clear();
|
ended.Clear();
|
||||||
|
|
||||||
// If no path found, create new curve for branch head
|
// If no path found, create new curve for branch head
|
||||||
|
@ -132,12 +135,10 @@ namespace SourceGit.Models
|
||||||
|
|
||||||
if (commit.Parents.Count > 0)
|
if (commit.Parents.Count > 0)
|
||||||
{
|
{
|
||||||
major = new PathHelper(commit.Parents[0], isMerged, colorIdx, new Point(offsetX, offsetY));
|
major = new PathHelper(commit.Parents[0], isMerged, colorPicker.Next(), new Point(offsetX, offsetY));
|
||||||
unsolved.Add(major);
|
unsolved.Add(major);
|
||||||
temp.Paths.Add(major.Path);
|
temp.Paths.Add(major.Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
colorIdx = (colorIdx + 1) % s_penCount;
|
|
||||||
}
|
}
|
||||||
else if (isMerged && !major.IsMerged && commit.Parents.Count > 0)
|
else if (isMerged && !major.IsMerged && commit.Parents.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -187,10 +188,9 @@ namespace SourceGit.Models
|
||||||
offsetX += unitWidth;
|
offsetX += unitWidth;
|
||||||
|
|
||||||
// Create new curve for parent commit that not includes before
|
// Create new curve for parent commit that not includes before
|
||||||
var l = new PathHelper(parentHash, isMerged, colorIdx, position, new Point(offsetX, position.Y + halfHeight));
|
var l = new PathHelper(parentHash, isMerged, colorPicker.Next(), position, new Point(offsetX, position.Y + halfHeight));
|
||||||
unsolved.Add(l);
|
unsolved.Add(l);
|
||||||
temp.Paths.Add(l.Path);
|
temp.Paths.Add(l.Path);
|
||||||
colorIdx = (colorIdx + 1) % s_penCount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,6 +217,28 @@ namespace SourceGit.Models
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class ColorPicker
|
||||||
|
{
|
||||||
|
public int Next()
|
||||||
|
{
|
||||||
|
if (_colorsQueue.Count == 0)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < s_penCount; i++)
|
||||||
|
_colorsQueue.Enqueue(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _colorsQueue.Dequeue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Recycle(int idx)
|
||||||
|
{
|
||||||
|
if (!_colorsQueue.Contains(idx))
|
||||||
|
_colorsQueue.Enqueue(idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Queue<int> _colorsQueue = new Queue<int>();
|
||||||
|
}
|
||||||
|
|
||||||
private class PathHelper
|
private class PathHelper
|
||||||
{
|
{
|
||||||
public Path Path { get; private set; }
|
public Path Path { get; private set; }
|
||||||
|
|
Loading…
Reference in a new issue