@@ -56,22 +56,33 @@ public override void Render(DrawingContext context)
5656 return ;
5757
5858 // 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 ;
6374
6475 // Apply scroll offset and clip.
6576 using ( context . PushClip ( new Rect ( 0 , 0 , width , height ) ) )
6677 using ( context . PushTransform ( Matrix . CreateTranslation ( 0 , - startY ) ) )
6778 {
6879 // 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 ) ;
7182 }
7283 }
7384
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 )
7586 {
7687 var grayedPen = new Pen ( new SolidColorBrush ( Colors . Gray , 0.4 ) , Models . CommitGraph . Pens [ 0 ] . Thickness ) ;
7788 var onlyHighlightCurrentBranch = OnlyHighlightCurrentBranch ;
@@ -82,16 +93,20 @@ private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double
8293 {
8394 if ( link . IsMerged )
8495 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 )
86101 continue ;
87- if ( link . Start . Y > bottom )
102+ if ( startY > bottom )
88103 break ;
89104
90105 var geo = new StreamGeometry ( ) ;
91106 using ( var ctx = geo . Open ( ) )
92107 {
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 ) ) ;
95110 }
96111
97112 context . DrawGeometry ( null , grayedPen , geo ) ;
@@ -100,10 +115,11 @@ private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double
100115
101116 foreach ( var line in graph . Paths )
102117 {
103- var last = line . Points [ 0 ] ;
118+ var last = new Point ( line . Points [ 0 ] . X , line . Points [ 0 ] . Y * rowHeight ) ;
104119 var size = line . Points . Count ;
120+ var endY = line . Points [ size - 1 ] . Y * rowHeight ;
105121
106- if ( line . Points [ size - 1 ] . Y < top )
122+ if ( endY < top )
107123 continue ;
108124 if ( last . Y > bottom )
109125 break ;
@@ -117,7 +133,7 @@ private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double
117133 var ended = false ;
118134 for ( int i = 1 ; i < size ; i ++ )
119135 {
120- var cur = line . Points [ i ] ;
136+ var cur = new Point ( line . Points [ i ] . X , line . Points [ i ] . Y * rowHeight ) ;
121137 if ( cur . Y < top )
122138 {
123139 last = cur ;
@@ -173,23 +189,27 @@ private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double
173189 {
174190 if ( onlyHighlightCurrentBranch && ! link . IsMerged )
175191 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 )
177197 continue ;
178- if ( link . Start . Y > bottom )
198+ if ( startY > bottom )
179199 break ;
180200
181201 var geo = new StreamGeometry ( ) ;
182202 using ( var ctx = geo . Open ( ) )
183203 {
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 ) ) ;
186206 }
187207
188208 context . DrawGeometry ( null , Models . CommitGraph . Pens [ link . Color ] , geo ) ;
189209 }
190210 }
191211
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 )
193213 {
194214 var dotFill = DotBrush ;
195215 var dotFillPen = new Pen ( dotFill , 2 ) ;
@@ -198,9 +218,11 @@ private void DrawAnchors(DrawingContext context, Models.CommitGraph graph, doubl
198218
199219 foreach ( var dot in graph . Dots )
200220 {
201- if ( dot . Center . Y < top )
221+ var center = new Point ( dot . Center . X , dot . Center . Y * rowHeight ) ;
222+
223+ if ( center . Y < top )
202224 continue ;
203- if ( dot . Center . Y > bottom )
225+ if ( center . Y > bottom )
204226 break ;
205227
206228 var pen = Models . CommitGraph . Pens [ dot . Color ] ;
@@ -210,16 +232,16 @@ private void DrawAnchors(DrawingContext context, Models.CommitGraph graph, doubl
210232 switch ( dot . Type )
211233 {
212234 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 ) ;
215237 break ;
216238 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 ) ) ;
220242 break ;
221243 default :
222- context . DrawEllipse ( dotFill , pen , dot . Center , 3 , 3 ) ;
244+ context . DrawEllipse ( dotFill , pen , center , 3 , 3 ) ;
223245 break ;
224246 }
225247 }
0 commit comments