gitk: Improve appearance of first child links
The point where the line for a parent joins to the first child shown is visually different from the lines to the other children, because the line doesn't branch, but terminates at the child. Because of this, we now treat the first child a little differently in the optimizer, and we draw its link in drawlineseg rather than drawparentlinks. This improves the appearance of the graph. Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras committed
Mar 18, 2006 at 23:11 UTC
eb447a126ce90fa1e8a4887d50fb04902167e57a
1 file changed
+53
-6
gitk
+53
-6
@@ -1148,6 +1148,15 @@ proc optimize_rows {row col endrow} {
1148
set z [lindex $offs $col]
1149
set haspad 1
1150
}
1151
+ if {$z0 eq {} && !$isarrow} {
1152
+ # this line links to its first child on row $row-2
1153
+ set rm2 [expr {$row - 2}]
1154
+ set id [lindex $displayorder $rm2]
1155
+ set xc [lsearch -exact [lindex $rowidlist $rm2] $id]
1156
+ if {$xc >= 0} {
1157
+ set z0 [expr {$xc - $x0}]
1158
+ }
1159
+ }
1160
if {$z0 ne {} && $z < 0 && $z0 > 0} {
1161
insert_pad $y0 $x0 1
1162
set offs [incrange $offs $col 1]
@@ -1155,11 +1164,26 @@ proc optimize_rows {row col endrow} {
1164
}
1165
}
1166
if {!$haspad} {
1167
+ set o {}
1168
for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
1169
set o [lindex $offs $col]
1170
+ if {$o eq {}} {
1171
+ # check if this is the link to the first child
1172
+ set id [lindex $idlist $col]
1173
+ if {[info exists idrowranges($id)] &&
1174
+ $row == [lindex $idrowranges($id) 0]} {
1175
+ # it is, work out offset to child
1176
+ set y0 [expr {$row - 1}]
1177
+ set id [lindex $displayorder $y0]
1178
+ set x0 [lsearch -exact [lindex $rowidlist $y0] $id]
1179
+ if {$x0 >= 0} {
1180
+ set o [expr {$x0 - $col}]
1181
+ }
1182
+ }
1183
+ }
1184
if {$o eq {} || $o <= 0} break
1185
}
1162
- if {[incr col] < [llength $idlist]} {
1186
+ if {$o ne {} && [incr col] < [llength $idlist]} {
1187
set y1 [expr {$row + 1}]
1188
set offs2 [lindex $rowoffsets $y1]
1189
set x1 -1
@@ -1203,6 +1227,7 @@ proc linewidth {id} {
1227
1228
proc drawlineseg {id i} {
1229
global rowoffsets rowidlist idrowranges
1230
+ global displayorder
1231
global canv colormap
1232
1233
set startrow [lindex $idrowranges($id) [expr {2 * $i}]]
@@ -1230,13 +1255,29 @@ proc drawlineseg {id i} {
1255
incr col $o
1256
incr row -1
1257
}
1233
- if {$coords eq {}} return
1234
- set last [expr {[llength $idrowranges($id)] / 2 - 1}]
1235
- set arrow [expr {2 * ($i > 0) + ($i < $last)}]
1236
- set arrow [lindex {none first last both} $arrow]
1258
set x [xc $row $col]
1259
set y [yc $row]
1260
lappend coords $x $y
1261
+ if {$i == 0} {
1262
+ # draw the link to the first child as part of this line
1263
+ incr row -1
1264
+ set child [lindex $displayorder $row]
1265
+ set ccol [lsearch -exact [lindex $rowidlist $row] $child]
1266
+ if {$ccol >= 0} {
1267
+ set x [xc $row $ccol]
1268
+ set y [yc $row]
1269
+ if {$ccol < $col - 1} {
1270
+ lappend coords [xc $row [expr {$col - 1}]] $yc
1271
+ } elseif {$ccol > $col + 1} {
1272
+ lappend coords [xc $row [expr {$col + 1}]] $yc
1273
+ }
1274
+ lappend coords $x $y
1275
+ }
1276
+ }
1277
+ if {[llength $coords] < 4} return
1278
+ set last [expr {[llength $idrowranges($id)] / 2 - 1}]
1279
+ set arrow [expr {2 * ($i > 0) + ($i < $last)}]
1280
+ set arrow [lindex {none first last both} $arrow]
1281
set t [$canv create line $coords -width [linewidth $id] \
1282
-fill $colormap($id) -tags lines.$id -arrow $arrow]
1283
$canv lower $t
@@ -1244,7 +1285,7 @@ proc drawlineseg {id i} {
1285
}
1286
1287
proc drawparentlinks {id row col olds} {
1247
- global rowidlist canv colormap
1288
+ global rowidlist canv colormap idrowranges
1289
1290
set row2 [expr {$row + 1}]
1291
set x [xc $row $col]
@@ -1254,6 +1295,12 @@ proc drawparentlinks {id row col olds} {
1295
# rmx = right-most X coord used
1296
set rmx 0
1297
foreach p $olds {
1298
+ if {[info exists idrowranges($p)] &&
1299
+ $row2 == [lindex $idrowranges($p) 0] &&
1300
+ $row2 < [lindex $idrowranges($p) 1]} {
1301
+ # drawlineseg will do this one for us
1302
+ continue
1303
+ }
1304
set i [lsearch -exact $ids $p]
1305
if {$i < 0} {
1306
puts "oops, parent $p of $id not in list"