@@ -6,8 +6,6 @@ import { RootState } from '../../../reducers';
66type BranchGrapProps = {
77 hideGraph : boolean ;
88 logEntries : LogEntry [ ] ;
9- height ?: string ;
10- width ?: string ;
119 itemHeight ?: number ;
1210 updateTick ?: number ;
1311} ;
@@ -48,11 +46,10 @@ function drawGitGraph(svg: SVGSVGElement, content: HTMLElement, startAt: number,
4846 }
4947 svg . style . display = '' ;
5048 // Draw the graph
51- const circleOffset = 0 ; //0.5 * logEntryHeight;
49+ const circleOffset = 0 ;
5250 const standardOffset = ( 0 + 0.5 ) * logEntryHeight ;
5351 let currentY = ( 0 + 0.5 ) * logEntryHeight ;
5452 let topMostY = ( 0 + 0.5 ) * logEntryHeight ;
55- // topMostY = (0 + 0.5) * logEntryHeight;
5653 let maxLeft = 0 ;
5754 let lastXOffset = 12 ;
5855 let maxXOffset = 12 ;
@@ -275,69 +272,31 @@ function drawGitGraph(svg: SVGSVGElement, content: HTMLElement, startAt: number,
275272 branch . path . setAttribute ( 'd' , branch . path . cmds + currentY ) ;
276273 } ) ;
277274
278- // Commented only fo debugging
279- // circlesToAppend.forEach(svg.appendChild.bind(svg));
275+ // calculate the height
276+ if ( entries . length > 0 && ! isNaN ( logEntryHeight ) ) {
277+ svg . setAttribute ( 'height' , ( entries . length * logEntryHeight ) . toString ( ) ) ;
278+ }
280279}
281280
282281class BrachGraph extends React . Component < BranchGrapProps > {
283282 componentWillReceiveProps ( newProps : BranchGrapProps ) {
284283 }
285284 componentWillUpdate ( newProps : BranchGrapProps ) {
286285 if ( newProps . hideGraph ) {
287- this . grahWasHidden = true ;
288286 drawGitGraph ( this . svg , this . svg . nextSibling as HTMLElement , 0 , newProps . itemHeight , [ ] , true ) ;
289287 return ;
290288 }
291- if ( this . props . hideGraph && ! newProps . hideGraph ) {
292- drawGitGraph ( this . svg , this . svg . nextSibling as HTMLElement , 0 , newProps . itemHeight , newProps . logEntries || [ ] ) ;
293- }
294- if ( Array . isArray ( newProps . logEntries ) && newProps . logEntries . length === 0 ) {
295- drawGitGraph ( this . svg , this . svg . nextSibling as HTMLElement , 0 , newProps . itemHeight , [ ] ) ;
296- }
297- if ( ! newProps . height || ! newProps . width || ! newProps . itemHeight || ! Array . isArray ( newProps . logEntries ) ) {
298- return ;
299- }
300- if ( newProps . itemHeight > 0 && ( ! Array . isArray ( newProps . logEntries ) || newProps . logEntries . length === 0 ) ) {
301- drawGitGraph ( this . svg , this . svg . nextSibling as HTMLElement , 0 , newProps . itemHeight , newProps . logEntries ) ;
302- return ;
303- }
304- if ( newProps . itemHeight > 0 && newProps . itemHeight === this . props . itemHeight &&
305- Array . isArray ( this . props . logEntries ) && this . props . logEntries . length > 0 &&
306- newProps . updateTick === this . props . updateTick &&
307- newProps . logEntries . length === this . props . logEntries . length &&
308- newProps . logEntries [ 0 ] . hash . full === this . props . logEntries [ 0 ] . hash . full ) {
309- return ;
310- }
311289 if ( newProps . updateTick === this . props . updateTick ) {
312290 return ;
313- }
314- if ( ! this . grahWasHidden && this . lastDrawnDetails && newProps . logEntries . length > 0 &&
315- this . lastDrawnDetails . count === newProps . logEntries . length &&
316- this . lastDrawnDetails . firstHash === newProps . logEntries [ 0 ] . hash . full &&
317- this . lastDrawnDetails . firstHash === newProps . logEntries [ 0 ] . hash . full ) {
318- return ;
319- }
320-
321- // Hack (dependant components).
322- this . grahWasHidden = false ;
323- this . lastDrawnDetails = {
324- count : newProps . logEntries . length ,
325- firstHash : newProps . logEntries . length > 0 ? newProps . logEntries [ 0 ] . hash . full : '' ,
326- lastHash : newProps . logEntries . length > 0 ? newProps . logEntries [ newProps . logEntries . length - 1 ] . hash . full : '' ,
327- } ;
328-
329- this . svg . setAttribute ( 'height' , newProps . height ) ;
330- this . svg . setAttribute ( 'width' , newProps . width ) ;
291+ }
331292
332293 // Hack, first clear before rebuilding.
333294 // Remember, we will need to support apending results, as opposed to clearing page
334295 drawGitGraph ( this . svg , this . svg . nextSibling as HTMLElement , 0 , newProps . itemHeight , [ ] ) ;
335- drawGitGraph ( this . svg , this . svg . nextSibling as HTMLElement , 0 , newProps . itemHeight , newProps . logEntries ) ;
296+ drawGitGraph ( this . svg , this . svg . nextSibling as HTMLElement , 0 , newProps . itemHeight , newProps . logEntries ) ;
336297 }
337- private lastDrawnDetails : { firstHash : string , lastHash : string , count : number } ;
338- private grahWasHidden : boolean ;
298+
339299 private svg : SVGSVGElement ;
340-
341300 render ( ) {
342301 return (
343302 < svg className = 'commitGraph' ref = { ( ref ) => this . svg = ref } xmlns = 'http://www.w3.org/2000/svg' > </ svg >
@@ -348,13 +307,12 @@ class BrachGraph extends React.Component<BranchGrapProps> {
348307function mapStateToProps ( state : RootState ) : BranchGrapProps {
349308 const hideGraph = ( state && state . logEntries ) && ( ( state . logEntries . searchText && state . logEntries . searchText . length > 0 ) ||
350309 ( state . logEntries . file && state . logEntries . file . fsPath && state . logEntries . file . fsPath . length > 0 ) ||
351- ( state . logEntries . author && state . logEntries . author . length > 0 ) ) ;
310+ ( state . logEntries . author && state . logEntries . author . length > 0 ) || state . logEntries . isLoading
311+ ) ;
352312
353313 return {
354314 logEntries : state . logEntries . items ,
355315 hideGraph,
356- height : state . graph . height ,
357- width : state . graph . width ,
358316 itemHeight : state . graph . itemHeight ,
359317 updateTick : state . graph . updateTick
360318 } ;
0 commit comments