mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
rename<CommitGraph>: rename CommitGraph.Line to CommitGraph.Path, CommitGraph.LineHelper to CommitGraph.PathHelper
This commit is contained in:
parent
3d7325f376
commit
2bad75ab4a
1 changed files with 35 additions and 34 deletions
|
@ -25,62 +25,63 @@ namespace SourceGit.Views.Controls {
|
||||||
public static readonly double UNIT_HEIGHT = 24;
|
public static readonly double UNIT_HEIGHT = 24;
|
||||||
public static readonly double HALF_HEIGHT = 12;
|
public static readonly double HALF_HEIGHT = 12;
|
||||||
|
|
||||||
public class Line {
|
public class Path {
|
||||||
public List<Point> Points = new List<Point>();
|
public List<Point> Points = new List<Point>();
|
||||||
public int Color = 0;
|
public int Color = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LineHelper {
|
public class PathHelper {
|
||||||
public string Next;
|
public string Next;
|
||||||
public bool IsMerged;
|
public bool IsMerged;
|
||||||
public double LastX;
|
public double LastX;
|
||||||
public double LastY;
|
public double LastY;
|
||||||
public double EndY;
|
public double EndY;
|
||||||
public Line Line;
|
public Path Path;
|
||||||
|
|
||||||
public LineHelper(string next, bool isMerged, int color, Point start) {
|
public PathHelper(string next, bool isMerged, int color, Point start) {
|
||||||
Next = next;
|
Next = next;
|
||||||
IsMerged = isMerged;
|
IsMerged = isMerged;
|
||||||
LastX = start.X;
|
LastX = start.X;
|
||||||
LastY = start.Y;
|
LastY = start.Y;
|
||||||
EndY = LastY;
|
EndY = LastY;
|
||||||
|
|
||||||
Line = new Line();
|
Path = new Path();
|
||||||
Line.Color = color % PENS.Length;
|
Path.Color = color % PENS.Length;
|
||||||
Line.Points.Add(start);
|
Path.Points.Add(start);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LineHelper(string next, bool isMerged, int color, Point start, Point to) {
|
public PathHelper(string next, bool isMerged, int color, Point start, Point to) {
|
||||||
Next = next;
|
Next = next;
|
||||||
IsMerged = isMerged;
|
IsMerged = isMerged;
|
||||||
LastX = to.X;
|
LastX = to.X;
|
||||||
LastY = to.Y;
|
LastY = to.Y;
|
||||||
EndY = LastY;
|
EndY = LastY;
|
||||||
|
|
||||||
Line = new Line();
|
Path = new Path();
|
||||||
Line.Color = color % PENS.Length;
|
Path.Color = color % PENS.Length;
|
||||||
Line.Points.Add(start);
|
Path.Points.Add(start);
|
||||||
Line.Points.Add(to);
|
Path.Points.Add(to);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(double x, double y, bool isEnd = false) {
|
public void Add(double x, double y, bool isEnd = false) {
|
||||||
if (x > LastX) {
|
if (x > LastX) {
|
||||||
Add(new Point(LastX, LastY));
|
Add(new Point(LastX, LastY));
|
||||||
Add(new Point(x, y - HALF_HEIGHT));
|
Add(new Point(x, y - HALF_HEIGHT));
|
||||||
|
if (isEnd) Add(new Point(x, y));
|
||||||
} else if (x < LastX) {
|
} else if (x < LastX) {
|
||||||
if (y > LastY + HALF_HEIGHT) Add(new Point(LastX, LastY + HALF_HEIGHT));
|
if (y > LastY + HALF_HEIGHT) Add(new Point(LastX, LastY + HALF_HEIGHT));
|
||||||
Add(new Point(x, y));
|
Add(new Point(x, y));
|
||||||
|
} else if (isEnd) {
|
||||||
|
Add(new Point(x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
LastX = x;
|
LastX = x;
|
||||||
LastY = y;
|
LastY = y;
|
||||||
|
|
||||||
if (isEnd) Add(new Point(LastX, LastY));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Add(Point p) {
|
private void Add(Point p) {
|
||||||
if (EndY < p.Y) {
|
if (EndY < p.Y) {
|
||||||
Line.Points.Add(p);
|
Path.Points.Add(p);
|
||||||
EndY = p.Y;
|
EndY = p.Y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,7 +100,7 @@ namespace SourceGit.Views.Controls {
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Data {
|
public class Data {
|
||||||
public List<Line> Lines = new List<Line>();
|
public List<Path> Paths = new List<Path>();
|
||||||
public List<Link> Links = new List<Link>();
|
public List<Link> Links = new List<Link>();
|
||||||
public List<Dot> Dots = new List<Dot>();
|
public List<Dot> Dots = new List<Dot>();
|
||||||
}
|
}
|
||||||
|
@ -125,14 +126,14 @@ namespace SourceGit.Views.Controls {
|
||||||
}
|
}
|
||||||
|
|
||||||
var temp = new Data();
|
var temp = new Data();
|
||||||
var unsolved = new List<LineHelper>();
|
var unsolved = new List<PathHelper>();
|
||||||
var mapUnsolved = new Dictionary<string, LineHelper>();
|
var mapUnsolved = new Dictionary<string, PathHelper>();
|
||||||
var ended = new List<LineHelper>();
|
var ended = new List<PathHelper>();
|
||||||
var offsetY = -HALF_HEIGHT;
|
var offsetY = -HALF_HEIGHT;
|
||||||
var colorIdx = 0;
|
var colorIdx = 0;
|
||||||
|
|
||||||
foreach (var commit in commits) {
|
foreach (var commit in commits) {
|
||||||
var major = null as LineHelper;
|
var major = null as PathHelper;
|
||||||
var isMerged = commit.IsMerged;
|
var isMerged = commit.IsMerged;
|
||||||
var oldCount = unsolved.Count;
|
var oldCount = unsolved.Count;
|
||||||
|
|
||||||
|
@ -171,7 +172,7 @@ namespace SourceGit.Views.Controls {
|
||||||
// 处理本提交为非当前分支HEAD的情况(创建新依赖线路)
|
// 处理本提交为非当前分支HEAD的情况(创建新依赖线路)
|
||||||
if (major == null && commit.Parents.Count > 0) {
|
if (major == null && commit.Parents.Count > 0) {
|
||||||
offsetX += UNIT_WIDTH;
|
offsetX += UNIT_WIDTH;
|
||||||
major = new LineHelper(commit.Parents[0], isMerged, colorIdx, new Point(offsetX, offsetY));
|
major = new PathHelper(commit.Parents[0], isMerged, colorIdx, new Point(offsetX, offsetY));
|
||||||
unsolved.Add(major);
|
unsolved.Add(major);
|
||||||
colorIdx++;
|
colorIdx++;
|
||||||
}
|
}
|
||||||
|
@ -182,7 +183,7 @@ namespace SourceGit.Views.Controls {
|
||||||
major.IsMerged = isMerged;
|
major.IsMerged = isMerged;
|
||||||
position.X = major.LastX;
|
position.X = major.LastX;
|
||||||
position.Y = offsetY;
|
position.Y = offsetY;
|
||||||
temp.Dots.Add(new Dot() { Center = position, Color = major.Line.Color });
|
temp.Dots.Add(new Dot() { Center = position, Color = major.Path.Color });
|
||||||
} else {
|
} else {
|
||||||
temp.Dots.Add(new Dot() { Center = position, Color = 0 });
|
temp.Dots.Add(new Dot() { Center = position, Color = 0 });
|
||||||
}
|
}
|
||||||
|
@ -197,13 +198,13 @@ namespace SourceGit.Views.Controls {
|
||||||
link.Start = position;
|
link.Start = position;
|
||||||
link.End = new Point(l.LastX, offsetY + HALF_HEIGHT);
|
link.End = new Point(l.LastX, offsetY + HALF_HEIGHT);
|
||||||
link.Control = new Point(link.End.X, link.Start.Y);
|
link.Control = new Point(link.End.X, link.Start.Y);
|
||||||
link.Color = l.Line.Color;
|
link.Color = l.Path.Color;
|
||||||
temp.Links.Add(link);
|
temp.Links.Add(link);
|
||||||
} else {
|
} else {
|
||||||
offsetX += UNIT_WIDTH;
|
offsetX += UNIT_WIDTH;
|
||||||
|
|
||||||
// 防止有下一个提交有ended线时,新的分支线与旧线重合
|
// 防止有下一个提交有ended线时,新的分支线与旧线重合
|
||||||
unsolved.Add(new LineHelper(commit.Parents[j], isMerged, colorIdx, position, new Point(offsetX, position.Y + HALF_HEIGHT)));
|
unsolved.Add(new PathHelper(commit.Parents[j], isMerged, colorIdx, position, new Point(offsetX, position.Y + HALF_HEIGHT)));
|
||||||
colorIdx++;
|
colorIdx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,7 +212,7 @@ namespace SourceGit.Views.Controls {
|
||||||
// 处理已终止的线
|
// 处理已终止的线
|
||||||
foreach (var l in ended) {
|
foreach (var l in ended) {
|
||||||
l.Add(position.X, position.Y, true);
|
l.Add(position.X, position.Y, true);
|
||||||
temp.Lines.Add(l.Line);
|
temp.Paths.Add(l.Path);
|
||||||
unsolved.Remove(l);
|
unsolved.Remove(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,15 +230,15 @@ namespace SourceGit.Views.Controls {
|
||||||
var path = unsolved[i];
|
var path = unsolved[i];
|
||||||
var endY = (commits.Count - 0.5) * UNIT_HEIGHT;
|
var endY = (commits.Count - 0.5) * UNIT_HEIGHT;
|
||||||
|
|
||||||
if (path.Line.Points.Count == 1 && path.Line.Points[0].Y == endY) continue;
|
if (path.Path.Points.Count == 1 && path.Path.Points[0].Y == endY) continue;
|
||||||
|
|
||||||
path.Add((i + 0.5) * UNIT_WIDTH, endY, true);
|
path.Add((i + 0.5) * UNIT_WIDTH, endY, true);
|
||||||
temp.Lines.Add(path.Line);
|
temp.Paths.Add(path.Path);
|
||||||
}
|
}
|
||||||
unsolved.Clear();
|
unsolved.Clear();
|
||||||
|
|
||||||
// 排序
|
// 排序
|
||||||
temp.Lines.Sort((l, h) => l.Points[0].Y.CompareTo(h.Points[0].Y));
|
temp.Paths.Sort((l, h) => l.Points[0].Y.CompareTo(h.Points[0].Y));
|
||||||
|
|
||||||
Dispatcher.Invoke(() => {
|
Dispatcher.Invoke(() => {
|
||||||
data = temp;
|
data = temp;
|
||||||
|
@ -256,9 +257,9 @@ namespace SourceGit.Views.Controls {
|
||||||
|
|
||||||
// 绘制线
|
// 绘制线
|
||||||
if (Models.Preference.Instance.Window.UsePolylineInGraph) {
|
if (Models.Preference.Instance.Window.UsePolylineInGraph) {
|
||||||
DrawPolyLine(dc, top, bottom);
|
DrawPolyLines(dc, top, bottom);
|
||||||
} else {
|
} else {
|
||||||
DrawCurveLine(dc, top, bottom);
|
DrawCurves(dc, top, bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 绘制点
|
// 绘制点
|
||||||
|
@ -271,8 +272,8 @@ namespace SourceGit.Views.Controls {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawCurveLine(DrawingContext dc, double top, double bottom) {
|
private void DrawCurves(DrawingContext dc, double top, double bottom) {
|
||||||
foreach (var line in data.Lines) {
|
foreach (var line in data.Paths) {
|
||||||
var last = line.Points[0];
|
var last = line.Points[0];
|
||||||
var size = line.Points.Count;
|
var size = line.Points.Count;
|
||||||
|
|
||||||
|
@ -334,8 +335,8 @@ namespace SourceGit.Views.Controls {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawPolyLine(DrawingContext dc, double top, double bottom) {
|
private void DrawPolyLines(DrawingContext dc, double top, double bottom) {
|
||||||
foreach (var line in data.Lines) {
|
foreach (var line in data.Paths) {
|
||||||
var last = line.Points[0];
|
var last = line.Points[0];
|
||||||
var size = line.Points.Count;
|
var size = line.Points.Count;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue