@@ -56,22 +56,33 @@ public override void Render(DrawingContext context)
56
56
return ;
57
57
58
58
// Calculate drawing area.
59
- double width = Bounds . Width - 273 - histories . AuthorNameColumnWidth . Value ;
60
- double height = Bounds . Height ;
61
- double startY = list . Scroll ? . Offset . Y ?? 0 ;
62
- double endY = startY + height + 28 ;
59
+ var width = Bounds . Width - 273 - histories . AuthorNameColumnWidth . Value ;
60
+ var height = Bounds . Height ;
61
+
62
+ // Calculate row height
63
+ var container = list . ItemsPanelRoot as VirtualizingStackPanel ;
64
+ if ( container == null )
65
+ return ;
66
+
67
+ var item = list . ContainerFromIndex ( container . FirstRealizedIndex ) ;
68
+ if ( item == null )
69
+ return ;
70
+
71
+ var rowHeight = item . Bounds . Height ;
72
+ var startY = container . FirstRealizedIndex * rowHeight - item . TranslatePoint ( new Point ( 0 , 0 ) , list ) . Value ! . Y ;
73
+ var endY = startY + height + 28 ;
63
74
64
75
// Apply scroll offset and clip.
65
76
using ( context . PushClip ( new Rect ( 0 , 0 , width , height ) ) )
66
77
using ( context . PushTransform ( Matrix . CreateTranslation ( 0 , - startY ) ) )
67
78
{
68
79
// Draw contents
69
- DrawCurves ( context , graph , startY , endY ) ;
70
- DrawAnchors ( context , graph , startY , endY ) ;
80
+ DrawCurves ( context , graph , startY , endY , rowHeight ) ;
81
+ DrawAnchors ( context , graph , startY , endY , rowHeight ) ;
71
82
}
72
83
}
73
84
74
- private void DrawCurves ( DrawingContext context , Models . CommitGraph graph , double top , double bottom )
85
+ private void DrawCurves ( DrawingContext context , Models . CommitGraph graph , double top , double bottom , double rowHeight )
75
86
{
76
87
var grayedPen = new Pen ( new SolidColorBrush ( Colors . Gray , 0.4 ) , Models . CommitGraph . Pens [ 0 ] . Thickness ) ;
77
88
var onlyHighlightCurrentBranch = OnlyHighlightCurrentBranch ;
@@ -82,16 +93,20 @@ private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double
82
93
{
83
94
if ( link . IsMerged )
84
95
continue ;
85
- if ( link . End . Y < top )
96
+
97
+ var startY = link . Start . Y * rowHeight ;
98
+ var endY = link . End . Y * rowHeight ;
99
+
100
+ if ( endY < top )
86
101
continue ;
87
- if ( link . Start . Y > bottom )
102
+ if ( startY > bottom )
88
103
break ;
89
104
90
105
var geo = new StreamGeometry ( ) ;
91
106
using ( var ctx = geo . Open ( ) )
92
107
{
93
- ctx . BeginFigure ( link . Start , false ) ;
94
- ctx . QuadraticBezierTo ( link . Control , link . End ) ;
108
+ ctx . BeginFigure ( new Point ( link . Start . X , startY ) , false ) ;
109
+ ctx . QuadraticBezierTo ( new Point ( link . Control . X , link . Control . Y * rowHeight ) , new Point ( link . End . X , endY ) ) ;
95
110
}
96
111
97
112
context . DrawGeometry ( null , grayedPen , geo ) ;
@@ -100,10 +115,11 @@ private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double
100
115
101
116
foreach ( var line in graph . Paths )
102
117
{
103
- var last = line . Points [ 0 ] ;
118
+ var last = new Point ( line . Points [ 0 ] . X , line . Points [ 0 ] . Y * rowHeight ) ;
104
119
var size = line . Points . Count ;
120
+ var endY = line . Points [ size - 1 ] . Y * rowHeight ;
105
121
106
- if ( line . Points [ size - 1 ] . Y < top )
122
+ if ( endY < top )
107
123
continue ;
108
124
if ( last . Y > bottom )
109
125
break ;
@@ -117,7 +133,7 @@ private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double
117
133
var ended = false ;
118
134
for ( int i = 1 ; i < size ; i ++ )
119
135
{
120
- var cur = line . Points [ i ] ;
136
+ var cur = new Point ( line . Points [ i ] . X , line . Points [ i ] . Y * rowHeight ) ;
121
137
if ( cur . Y < top )
122
138
{
123
139
last = cur ;
@@ -173,23 +189,27 @@ private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double
173
189
{
174
190
if ( onlyHighlightCurrentBranch && ! link . IsMerged )
175
191
continue ;
176
- if ( link . End . Y < top )
192
+
193
+ var startY = link . Start . Y * rowHeight ;
194
+ var endY = link . End . Y * rowHeight ;
195
+
196
+ if ( endY < top )
177
197
continue ;
178
- if ( link . Start . Y > bottom )
198
+ if ( startY > bottom )
179
199
break ;
180
200
181
201
var geo = new StreamGeometry ( ) ;
182
202
using ( var ctx = geo . Open ( ) )
183
203
{
184
- ctx . BeginFigure ( link . Start , false ) ;
185
- ctx . QuadraticBezierTo ( link . Control , link . End ) ;
204
+ ctx . BeginFigure ( new Point ( link . Start . X , startY ) , false ) ;
205
+ ctx . QuadraticBezierTo ( new Point ( link . Control . X , link . Control . Y * rowHeight ) , new Point ( link . End . X , endY ) ) ;
186
206
}
187
207
188
208
context . DrawGeometry ( null , Models . CommitGraph . Pens [ link . Color ] , geo ) ;
189
209
}
190
210
}
191
211
192
- private void DrawAnchors ( DrawingContext context , Models . CommitGraph graph , double top , double bottom )
212
+ private void DrawAnchors ( DrawingContext context , Models . CommitGraph graph , double top , double bottom , double rowHeight )
193
213
{
194
214
var dotFill = DotBrush ;
195
215
var dotFillPen = new Pen ( dotFill , 2 ) ;
@@ -198,9 +218,11 @@ private void DrawAnchors(DrawingContext context, Models.CommitGraph graph, doubl
198
218
199
219
foreach ( var dot in graph . Dots )
200
220
{
201
- if ( dot . Center . Y < top )
221
+ var center = new Point ( dot . Center . X , dot . Center . Y * rowHeight ) ;
222
+
223
+ if ( center . Y < top )
202
224
continue ;
203
- if ( dot . Center . Y > bottom )
225
+ if ( center . Y > bottom )
204
226
break ;
205
227
206
228
var pen = Models . CommitGraph . Pens [ dot . Color ] ;
@@ -210,16 +232,16 @@ private void DrawAnchors(DrawingContext context, Models.CommitGraph graph, doubl
210
232
switch ( dot . Type )
211
233
{
212
234
case Models . CommitGraph . DotType . Head :
213
- context . DrawEllipse ( dotFill , pen , dot . Center , 6 , 6 ) ;
214
- context . DrawEllipse ( pen . Brush , null , dot . Center , 3 , 3 ) ;
235
+ context . DrawEllipse ( dotFill , pen , center , 6 , 6 ) ;
236
+ context . DrawEllipse ( pen . Brush , null , center , 3 , 3 ) ;
215
237
break ;
216
238
case Models . CommitGraph . DotType . Merge :
217
- context . DrawEllipse ( pen . Brush , null , dot . Center , 6 , 6 ) ;
218
- context . DrawLine ( dotFillPen , new Point ( dot . Center . X , dot . Center . Y - 3 ) , new Point ( dot . Center . X , dot . Center . Y + 3 ) ) ;
219
- context . DrawLine ( dotFillPen , new Point ( dot . Center . X - 3 , dot . Center . Y ) , new Point ( dot . Center . X + 3 , dot . Center . Y ) ) ;
239
+ context . DrawEllipse ( pen . Brush , null , center , 6 , 6 ) ;
240
+ context . DrawLine ( dotFillPen , new Point ( center . X , center . Y - 3 ) , new Point ( center . X , center . Y + 3 ) ) ;
241
+ context . DrawLine ( dotFillPen , new Point ( center . X - 3 , center . Y ) , new Point ( center . X + 3 , center . Y ) ) ;
220
242
break ;
221
243
default :
222
- context . DrawEllipse ( dotFill , pen , dot . Center , 3 , 3 ) ;
244
+ context . DrawEllipse ( dotFill , pen , center , 3 , 3 ) ;
223
245
break ;
224
246
}
225
247
}
0 commit comments