@@ -20,7 +20,6 @@ public class PathHelper
20
20
public bool IsMerged ;
21
21
public double LastX ;
22
22
public double LastY ;
23
- public double EndY ;
24
23
public Path Path ;
25
24
26
25
public PathHelper ( string next , bool isMerged , int color , Point start )
@@ -29,7 +28,6 @@ public PathHelper(string next, bool isMerged, int color, Point start)
29
28
IsMerged = isMerged ;
30
29
LastX = start . X ;
31
30
LastY = start . Y ;
32
- EndY = LastY ;
33
31
34
32
Path = new Path ( ) ;
35
33
Path . Color = color ;
@@ -42,51 +40,94 @@ public PathHelper(string next, bool isMerged, int color, Point start, Point to)
42
40
IsMerged = isMerged ;
43
41
LastX = to . X ;
44
42
LastY = to . Y ;
45
- EndY = LastY ;
46
43
47
44
Path = new Path ( ) ;
48
45
Path . Color = color ;
49
46
Path . Points . Add ( start ) ;
50
47
Path . Points . Add ( to ) ;
51
48
}
52
49
53
- public void Add ( double x , double y , double halfHeight , bool isEnd = false )
50
+ /// <summary>
51
+ /// A path that just passed this row.
52
+ /// </summary>
53
+ /// <param name="x"></param>
54
+ /// <param name="y"></param>
55
+ /// <param name="halfHeight"></param>
56
+ public void Pass ( double x , double y , double halfHeight )
54
57
{
55
58
if ( x > LastX )
56
59
{
57
- Add ( new Point ( LastX , LastY ) ) ;
58
- Add ( new Point ( x , y - halfHeight ) ) ;
59
- if ( isEnd )
60
- Add ( new Point ( x , y ) ) ;
60
+ Add ( LastX , LastY ) ;
61
+ Add ( x , y - halfHeight ) ;
61
62
}
62
63
else if ( x < LastX )
63
64
{
64
- var testY = LastY + halfHeight ;
65
- if ( y > testY )
66
- Add ( new Point ( LastX , testY ) ) ;
65
+ Add ( LastX , y - halfHeight ) ;
66
+ y += halfHeight ;
67
+ Add ( x , y ) ;
68
+ }
67
69
68
- if ( ! isEnd )
69
- y += halfHeight ;
70
+ LastX = x ;
71
+ LastY = y ;
72
+ }
70
73
71
- Add ( new Point ( x , y ) ) ;
74
+ /// <summary>
75
+ /// A path that has commit in this row but not ended
76
+ /// </summary>
77
+ /// <param name="x"></param>
78
+ /// <param name="y"></param>
79
+ /// <param name="halfHeight"></param>
80
+ public void Goto ( double x , double y , double halfHeight )
81
+ {
82
+ if ( x > LastX )
83
+ {
84
+ Add ( LastX , LastY ) ;
85
+ Add ( x , y - halfHeight ) ;
72
86
}
73
- else if ( isEnd )
87
+ else if ( x < LastX )
74
88
{
75
- Add ( new Point ( x , y ) ) ;
89
+ Add ( LastX , y - halfHeight ) ;
90
+ Add ( x , y ) ;
76
91
}
77
92
78
93
LastX = x ;
79
94
LastY = y ;
80
95
}
81
96
82
- private void Add ( Point p )
97
+ /// <summary>
98
+ /// A path that has commit in this row and end.
99
+ /// </summary>
100
+ /// <param name="x"></param>
101
+ /// <param name="y"></param>
102
+ /// <param name="halfHeight"></param>
103
+ public void End ( double x , double y , double halfHeight )
104
+ {
105
+ if ( x > LastX )
106
+ {
107
+ Add ( LastX , LastY ) ;
108
+ Add ( x , y - halfHeight ) ;
109
+ }
110
+ else if ( x < LastX )
111
+ {
112
+ Add ( LastX , y - halfHeight ) ;
113
+ }
114
+
115
+ Add ( x , y ) ;
116
+
117
+ LastX = x ;
118
+ LastY = y ;
119
+ }
120
+
121
+ private void Add ( double x , double y )
83
122
{
84
- if ( EndY < p . Y )
123
+ if ( _endY < y )
85
124
{
86
- Path . Points . Add ( p ) ;
87
- EndY = p . Y ;
125
+ Path . Points . Add ( new Point ( x , y ) ) ;
126
+ _endY = y ;
88
127
}
89
128
}
129
+
130
+ private double _endY = 0 ;
90
131
}
91
132
92
133
public class Link
@@ -173,17 +214,17 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
173
214
if ( commit . Parents . Count > 0 )
174
215
{
175
216
major . Next = commit . Parents [ 0 ] ;
176
- major . Add ( offsetX , offsetY , HALF_HEIGHT ) ;
217
+ major . Goto ( offsetX , offsetY , HALF_HEIGHT ) ;
177
218
}
178
219
else
179
220
{
180
- major . Add ( offsetX , offsetY , HALF_HEIGHT , true ) ;
221
+ major . End ( offsetX , offsetY , HALF_HEIGHT ) ;
181
222
ended . Add ( l ) ;
182
223
}
183
224
}
184
225
else
185
226
{
186
- l . Add ( major . LastX , offsetY , HALF_HEIGHT , true ) ;
227
+ l . End ( major . LastX , offsetY , HALF_HEIGHT ) ;
187
228
ended . Add ( l ) ;
188
229
}
189
230
@@ -193,7 +234,7 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
193
234
else
194
235
{
195
236
offsetX += UNIT_WIDTH ;
196
- l . Add ( offsetX , offsetY , HALF_HEIGHT ) ;
237
+ l . Pass ( offsetX , offsetY , HALF_HEIGHT ) ;
197
238
}
198
239
}
199
240
@@ -278,7 +319,7 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
278
319
if ( path . Path . Points . Count == 1 && Math . Abs ( path . Path . Points [ 0 ] . Y - endY ) < 0.0001 )
279
320
continue ;
280
321
281
- path . Add ( ( i + 0.5 ) * UNIT_WIDTH + H_MARGIN , endY + HALF_HEIGHT , HALF_HEIGHT , true ) ;
322
+ path . End ( ( i + 0.5 ) * UNIT_WIDTH + H_MARGIN , endY + HALF_HEIGHT , HALF_HEIGHT ) ;
282
323
}
283
324
unsolved . Clear ( ) ;
284
325
0 commit comments