Skip to content

Commit 8d858d1

Browse files
committed
Compress the graph horizontally if it gets too wide.
If the graph gets to use more than a certain percentage (default 50%) of the width of the top-left pane, we now reduce the amount of space allowed for each graph line. This means it doesn't look quite as nice but you can still see the headline for the commit. (Currently the only way to customize the percentage is to edit your ~/.gitk file manually.)
1 parent 1115fb3 commit 8d858d1

File tree

1 file changed

+81
-28
lines changed

1 file changed

+81
-28
lines changed

gitk

Lines changed: 81 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ proc click {w} {
480480

481481
proc savestuff {w} {
482482
global canv canv2 canv3 ctext cflist mainfont textfont
483-
global stuffsaved findmergefiles gaudydiff
483+
global stuffsaved findmergefiles gaudydiff maxgraphpct
484484

485485
if {$stuffsaved} return
486486
if {![winfo viewable .]} return
@@ -490,6 +490,7 @@ proc savestuff {w} {
490490
puts $f [list set textfont $textfont]
491491
puts $f [list set findmergefiles $findmergefiles]
492492
puts $f [list set gaudydiff $gaudydiff]
493+
puts $f [list set maxgraphpct $maxgraphpct]
493494
puts $f "set geometry(width) [winfo width .ctop]"
494495
puts $f "set geometry(height) [winfo height .ctop]"
495496
puts $f "set geometry(canv1) [expr [winfo width $canv]-2]"
@@ -694,7 +695,7 @@ proc bindline {t id} {
694695

695696
proc drawcommitline {level} {
696697
global parents children nparents nchildren todo
697-
global canv canv2 canv3 mainfont namefont canvx0 canvy linespc
698+
global canv canv2 canv3 mainfont namefont canvy linespc
698699
global lineid linehtag linentag linedtag commitinfo
699700
global colormap numcommits currentparents dupparents
700701
global oldlevel oldnlines oldtodo
@@ -728,7 +729,7 @@ proc drawcommitline {level} {
728729
}
729730
}
730731
}
731-
set x [expr $canvx0 + $level * $linespc]
732+
set x [xcoord $level $level $lineno]
732733
set y1 $canvy
733734
set canvy [expr $canvy + $linespc]
734735
allcanvs conf -scrollregion \
@@ -756,7 +757,7 @@ proc drawcommitline {level} {
756757
-fill $ofill -outline black -width 1]
757758
$canv raise $t
758759
$canv bind $t <1> {selcanvline {} %x %y}
759-
set xt [expr $canvx0 + [llength $todo] * $linespc]
760+
set xt [xcoord [llength $todo] $level $lineno]
760761
if {[llength $currentparents] > 2} {
761762
set xt [expr {$xt + ([llength $currentparents] - 2) * $linespc}]
762763
}
@@ -832,8 +833,8 @@ proc drawtags {id x xt y1} {
832833
proc updatetodo {level noshortcut} {
833834
global currentparents ncleft todo
834835
global mainline oldlevel oldtodo oldnlines
835-
global canvx0 canvy linespc mainline
836-
global commitinfo
836+
global canvy linespc mainline
837+
global commitinfo lineno xspc1
837838

838839
set oldlevel $level
839840
set oldtodo $todo
@@ -842,10 +843,11 @@ proc updatetodo {level noshortcut} {
842843
set p [lindex $currentparents 0]
843844
if {$ncleft($p) == 1 && [lsearch -exact $todo $p] < 0} {
844845
set ncleft($p) 0
845-
set x [expr $canvx0 + $level * $linespc]
846+
set x [xcoord $level $level $lineno]
846847
set y [expr $canvy - $linespc]
847848
set mainline($p) [list $x $y]
848849
set todo [lreplace $todo $level $level $p]
850+
set xspc1([expr {$lineno + 1}]) $xspc1($lineno)
849851
return 0
850852
}
851853
}
@@ -891,28 +893,54 @@ proc notecrossings {id lo hi corner} {
891893
}
892894
}
893895

894-
proc drawslants {} {
895-
global canv mainline sidelines canvx0 canvy linespc
896-
global oldlevel oldtodo todo currentparents dupparents
897-
global lthickness linespc canvy colormap
896+
proc xcoord {i level ln} {
897+
global canvx0 xspc1 xspc2
898+
899+
set x [expr {$canvx0 + $i * $xspc1($ln)}]
900+
if {$i > 0 && $i == $level} {
901+
set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
902+
} elseif {$i > $level} {
903+
set x [expr {$x + $xspc2 - $xspc1($ln)}]
904+
}
905+
return $x
906+
}
898907

908+
proc drawslants {level} {
909+
global canv mainline sidelines canvx0 canvy xspc1 xspc2 lthickness
910+
global oldlevel oldtodo todo currentparents dupparents
911+
global lthickness linespc canvy colormap lineno geometry
912+
global maxgraphpct
913+
914+
# decide on the line spacing for the next line
915+
set lj [expr {$lineno + 1}]
916+
set maxw [expr {$maxgraphpct * $geometry(canv1) / 100}]
917+
set n [llength $todo]
918+
if {$n <= 1 || $canvx0 + $n * $xspc2 <= $maxw} {
919+
set xspc1($lj) $xspc2
920+
} else {
921+
set xspc1($lj) [expr {($maxw - $canvx0 - $xspc2) / ($n - 1)}]
922+
if {$xspc1($lj) < $lthickness} {
923+
set xspc1($lj) $lthickness
924+
}
925+
}
926+
899927
set y1 [expr $canvy - $linespc]
900928
set y2 $canvy
901929
set i -1
902930
foreach id $oldtodo {
903931
incr i
904932
if {$id == {}} continue
905-
set xi [expr {$canvx0 + $i * $linespc}]
933+
set xi [xcoord $i $oldlevel $lineno]
906934
if {$i == $oldlevel} {
907935
foreach p $currentparents {
908936
set j [lsearch -exact $todo $p]
909937
set coords [list $xi $y1]
910-
set xj [expr {$canvx0 + $j * $linespc}]
911-
if {$j < $i - 1} {
912-
lappend coords [expr $xj + $linespc] $y1
938+
set xj [xcoord $j $level $lj]
939+
if {$xj < $xi - $linespc} {
940+
lappend coords [expr {$xj + $linespc}] $y1
913941
notecrossings $p $j $i [expr {$j + 1}]
914-
} elseif {$j > $i + 1} {
915-
lappend coords [expr $xj - $linespc] $y1
942+
} elseif {$xj > $xi + $linespc} {
943+
lappend coords [expr {$xj - $linespc}] $y1
916944
notecrossings $p $i $j [expr {$j - 1}]
917945
}
918946
if {[lsearch -exact $dupparents $p] >= 0} {
@@ -924,28 +952,48 @@ proc drawslants {} {
924952
}
925953
} else {
926954
# normal case, no parent duplicated
955+
set yb $y2
956+
set dx [expr {abs($xi - $xj)}]
957+
if {0 && $dx < $linespc} {
958+
set yb [expr {$y1 + $dx}]
959+
}
927960
if {![info exists mainline($p)]} {
928-
if {$i != $j} {
929-
lappend coords $xj $y2
961+
if {$xi != $xj} {
962+
lappend coords $xj $yb
930963
}
931964
set mainline($p) $coords
932965
} else {
933-
lappend coords $xj $y2
966+
lappend coords $xj $yb
967+
if {$yb < $y2} {
968+
lappend coords $xj $y2
969+
}
934970
lappend sidelines($p) [list $coords 1]
935971
}
936972
}
937973
}
938-
} elseif {[lindex $todo $i] != $id} {
939-
set j [lsearch -exact $todo $id]
940-
set xj [expr {$canvx0 + $j * $linespc}]
941-
lappend mainline($id) $xi $y1 $xj $y2
974+
} else {
975+
set j $i
976+
if {[lindex $todo $i] != $id} {
977+
set j [lsearch -exact $todo $id]
978+
}
979+
if {$j != $i || $xspc1($lineno) != $xspc1($lj)
980+
|| ($oldlevel <= $i && $i <= $level)
981+
|| ($level <= $i && $i <= $oldlevel)} {
982+
set xj [xcoord $j $level $lj]
983+
set dx [expr {abs($xi - $xj)}]
984+
set yb $y2
985+
if {0 && $dx < $linespc} {
986+
set yb [expr {$y1 + $dx}]
987+
}
988+
lappend mainline($id) $xi $y1 $xj $yb
989+
}
942990
}
943991
}
944992
}
945993

946994
proc decidenext {{noread 0}} {
947995
global parents children nchildren ncleft todo
948-
global canv canv2 canv3 mainfont namefont canvx0 canvy linespc
996+
global canv canv2 canv3 mainfont namefont canvy linespc
949997
global datemode cdate
950998
global commitinfo
951999
global currentparents oldlevel oldnlines oldtodo
@@ -1036,7 +1084,7 @@ proc drawcommit {id} {
10361084
return
10371085
}
10381086
while 1 {
1039-
drawslants
1087+
drawslants $level
10401088
drawcommitline $level
10411089
if {[updatetodo $level $datemode]} {
10421090
set level [decidenext 1]
@@ -1065,8 +1113,8 @@ proc finishcommits {} {
10651113
-font $mainfont -tags textitems
10661114
set phase {}
10671115
} else {
1068-
drawslants
10691116
set level [decidenext]
1117+
drawslants $level
10701118
drawrest $level [llength $startcommits]
10711119
}
10721120
. config -cursor $maincursor
@@ -1114,7 +1162,7 @@ proc drawrest {level startix} {
11141162
if {$hard} {
11151163
set level [decidenext]
11161164
if {$level < 0} break
1117-
drawslants
1165+
drawslants $level
11181166
}
11191167
if {[clock clicks -milliseconds] >= $nextupdate} {
11201168
update
@@ -2451,10 +2499,14 @@ proc listboxsel {} {
24512499

24522500
proc setcoords {} {
24532501
global linespc charspc canvx0 canvy0 mainfont
2502+
global xspc1 xspc2
2503+
24542504
set linespc [font metrics $mainfont -linespace]
24552505
set charspc [font measure $mainfont "m"]
24562506
set canvy0 [expr 3 + 0.5 * $linespc]
24572507
set canvx0 [expr 3 + 0.5 * $linespc]
2508+
set xspc1(0) $linespc
2509+
set xspc2 $linespc
24582510
}
24592511

24602512
proc redisplay {} {
@@ -2941,6 +2993,7 @@ set mainfont {Helvetica 9}
29412993
set textfont {Courier 9}
29422994
set findmergefiles 0
29432995
set gaudydiff 0
2996+
set maxgraphpct 50
29442997

29452998
set colors {green red blue magenta darkgrey brown orange}
29462999

0 commit comments

Comments
 (0)