ux: different node in graph (#395)

This commit is contained in:
leo 2024-08-23 10:22:53 +08:00
parent 7389f5d521
commit e6f3ab5e68
No known key found for this signature in database
3 changed files with 62 additions and 25 deletions

View file

@ -97,8 +97,16 @@ namespace SourceGit.Models
public int Color;
}
public enum DotType
{
Default,
Head,
Merge,
}
public class Dot
{
public DotType Type;
public Point Center;
public int Color;
}
@ -134,6 +142,7 @@ namespace SourceGit.Models
double HALF_WIDTH = 6;
double UNIT_HEIGHT = 28;
double HALF_HEIGHT = 14;
double H_MARGIN = 2;
var temp = new CommitGraph();
var unsolved = new List<PathHelper>();
@ -152,7 +161,7 @@ namespace SourceGit.Models
offsetY += UNIT_HEIGHT;
// Find first curves that links to this commit and marks others that links to this commit ended.
double offsetX = -HALF_WIDTH;
double offsetX = H_MARGIN - HALF_WIDTH;
foreach (var l in unsolved)
{
if (l.Next == commit.SHA)
@ -204,16 +213,22 @@ namespace SourceGit.Models
// Calculate link position of this commit.
Point position = new Point(offsetX, offsetY);
int dotColor = 0;
if (major != null)
{
major.IsMerged = isMerged;
position = new Point(major.LastX, offsetY);
temp.Dots.Add(new Dot() { Center = position, Color = major.Path.Color });
dotColor = major.Path.Color;
}
Dot anchor = new Dot() { Center = position, Color = dotColor };
if (commit.IsCurrentHead)
anchor.Type = DotType.Head;
else if (commit.Parents.Count > 1)
anchor.Type = DotType.Merge;
else
{
temp.Dots.Add(new Dot() { Center = position, Color = 0 });
}
anchor.Type = DotType.Default;
temp.Dots.Add(anchor);
// Deal with other parents (the first parent has been processed)
if (!firstParentOnlyEnabled)
@ -258,7 +273,7 @@ namespace SourceGit.Models
// Margins & merge state (used by datagrid).
commit.IsMerged = isMerged;
commit.Margin = new Thickness(Math.Max(offsetX + HALF_WIDTH, oldCount * UNIT_WIDTH), 0, 0, 0);
commit.Margin = new Thickness(Math.Max(offsetX + HALF_WIDTH, oldCount * UNIT_WIDTH + H_MARGIN) + H_MARGIN, 0, 0, 0);
// Clean up
ended.Clear();
@ -274,7 +289,7 @@ namespace SourceGit.Models
if (path.Path.Points.Count == 1 && Math.Abs(path.Path.Points[0].Y - endY) < 0.0001)
continue;
path.Add((i + 0.5) * UNIT_WIDTH, endY + HALF_HEIGHT, HALF_HEIGHT, true);
path.Add((i + 0.5) * UNIT_WIDTH + H_MARGIN, endY + HALF_HEIGHT, HALF_HEIGHT, true);
}
unsolved.Clear();