gitk: Eliminate diagonal arrows
This changes the optimizer to insert pads to straighten downward pointing arrows so they point straight down. When drawing the parent link to the first child in drawlineseg, this draws it with 3 segments like other parent links if it is only one row high with an arrow. These two things mean we can dispense with the workarounds for arrows on diagonal segments. This also fixes a couple of other minor bugs. Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras committed
Aug 12, 2007 at 12:42 UTC
e341c06d8140b689001ddc183ec3476c1ede264a
1 file changed
+36
-51
gitk
+36
-51
@@ -2600,7 +2600,7 @@ proc idcol {idlist id {i 0}} {
2600
proc makeuparrow {oid y x} {
2601
global rowidlist uparrowlen idrowranges displayorder
2602
2603
- for {set i 1} {$i < $uparrowlen && $y > 1} {incr i} {
2603
+ for {set i 0} {$i < $uparrowlen && $y > 1} {incr i} {
2604
incr y -1
2605
set idl [lindex $rowidlist $y]
2606
set x [idcol $idl $oid $x]
@@ -3005,7 +3005,14 @@ proc insert_pad {row col npad} {
3005
global rowidlist
3006
3007
set pad [ntimes $npad {}]
3008
- lset rowidlist $row [eval linsert [list [lindex $rowidlist $row]] $col $pad]
3008
+ set idlist [lindex $rowidlist $row]
3009
+ set bef [lrange $idlist 0 [expr {$col - 1}]]
3010
+ set aft [lrange $idlist $col end]
3011
+ set i [lsearch -exact $aft {}]
3012
+ if {$i > 0} {
3013
+ set aft [lreplace $aft $i $i]
3014
+ }
3015
+ lset rowidlist $row [concat $bef $pad $aft]
3016
}
3017
3018
proc optimize_rows {row col endrow} {
@@ -3053,6 +3060,10 @@ proc optimize_rows {row col endrow} {
3060
set isarrow 1
3061
}
3062
}
3063
+ if {!$isarrow && $id ne [lindex $displayorder $row] &&
3064
+ [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
3065
+ set isarrow 1
3066
+ }
3067
# Looking at lines from this row to the previous row,
3068
# make them go straight up if they end in an arrow on
3069
# the previous row; otherwise make them go straight up
@@ -3077,8 +3088,8 @@ proc optimize_rows {row col endrow} {
3088
# Line currently goes right too much;
3089
# insert pads in this line
3090
set npad [expr {$z - 1 + $isarrow}]
3080
- set pad [ntimes $npad {}]
3081
- set idlist [eval linsert \$idlist $col $pad]
3091
+ insert_pad $row $col $npad
3092
+ set idlist [lindex $rowidlist $row]
3093
incr col $npad
3094
set z [expr {$x0 - $col}]
3095
set haspad 1
@@ -3169,31 +3180,9 @@ proc rowranges {id} {
3180
return $linenos
3181
}
3182
3172
-# work around tk8.4 refusal to draw arrows on diagonal segments
3173
-proc adjarrowhigh {coords} {
3174
- global linespc
3175
-
3176
- set x0 [lindex $coords 0]
3177
- set x1 [lindex $coords 2]
3178
- if {$x0 != $x1} {
3179
- set y0 [lindex $coords 1]
3180
- set y1 [lindex $coords 3]
3181
- if {$y0 - $y1 <= 2 * $linespc && $x1 == [lindex $coords 4]} {
3182
- # we have a nearby vertical segment, just trim off the diag bit
3183
- set coords [lrange $coords 2 end]
3184
- } else {
3185
- set slope [expr {($x0 - $x1) / ($y0 - $y1)}]
3186
- set xi [expr {$x0 - $slope * $linespc / 2}]
3187
- set yi [expr {$y0 - $linespc / 2}]
3188
- set coords [lreplace $coords 0 1 $xi $y0 $xi $yi]
3189
- }
3190
- }
3191
- return $coords
3192
-}
3193
-
3183
proc drawlineseg {id row endrow arrowlow} {
3184
global rowidlist displayorder iddrawn linesegs
3196
- global canv colormap linespc curview maxlinelen
3185
+ global canv colormap linespc curview maxlinelen parentlist
3186
3187
set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
3188
set le [expr {$row + 1}]
@@ -3268,9 +3257,11 @@ proc drawlineseg {id row endrow arrowlow} {
3257
set itl [lindex $lines [expr {$i-1}] 2]
3258
set al [$canv itemcget $itl -arrow]
3259
set arrowlow [expr {$al eq "last" || $al eq "both"}]
3271
- } elseif {$arrowlow &&
3272
- [lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0} {
3273
- set arrowlow 0
3260
+ } elseif {$arrowlow} {
3261
+ if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
3262
+ [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
3263
+ set arrowlow 0
3264
+ }
3265
}
3266
set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
3267
for {set y $le} {[incr y -1] > $row} {} {
@@ -3289,8 +3280,19 @@ proc drawlineseg {id row endrow arrowlow} {
3280
set xc [lsearch -exact [lindex $rowidlist $row] $ch]
3281
if {$xc < 0} {
3282
puts "oops: drawlineseg: child $ch not on row $row"
3292
- } else {
3293
- if {$xc < $x - 1} {
3283
+ } elseif {$xc != $x} {
3284
+ if {($arrowhigh && $le == $row + 1) || $dir == 0} {
3285
+ set d [expr {int(0.5 * $linespc)}]
3286
+ set x1 [xc $row $x]
3287
+ if {$xc < $x} {
3288
+ set x2 [expr {$x1 - $d}]
3289
+ } else {
3290
+ set x2 [expr {$x1 + $d}]
3291
+ }
3292
+ set y2 [yc $row]
3293
+ set y1 [expr {$y2 + $d}]
3294
+ lappend coords $x1 $y1 $x2 $y2
3295
+ } elseif {$xc < $x - 1} {
3296
lappend coords [xc $row [expr {$x-1}]] [yc $row]
3297
} elseif {$xc > $x + 1} {
3298
lappend coords [xc $row [expr {$x+1}]] [yc $row]
@@ -3301,23 +3303,9 @@ proc drawlineseg {id row endrow arrowlow} {
3303
} else {
3304
set xn [xc $row $xp]
3305
set yn [yc $row]
3304
- # work around tk8.4 refusal to draw arrows on diagonal segments
3305
- if {$arrowlow && $xn != [lindex $coords end-1]} {
3306
- if {[llength $coords] < 4 ||
3307
- [lindex $coords end-3] != [lindex $coords end-1] ||
3308
- [lindex $coords end] - $yn > 2 * $linespc} {
3309
- set xn [xc $row [expr {$xp - 0.5 * $dir}]]
3310
- set yo [yc [expr {$row + 0.5}]]
3311
- lappend coords $xn $yo $xn $yn
3312
- }
3313
- } else {
3314
- lappend coords $xn $yn
3315
- }
3306
+ lappend coords $xn $yn
3307
}
3308
if {!$joinhigh} {
3318
- if {$arrowhigh} {
3319
- set coords [adjarrowhigh $coords]
3320
- }
3309
assigncolor $id
3310
set t [$canv create line $coords -width [linewidth $id] \
3311
-fill $colormap($id) -tags lines.$id -arrow $arrow]
@@ -3341,9 +3329,6 @@ proc drawlineseg {id row endrow arrowlow} {
3329
set coords [concat $coords $clow]
3330
if {!$joinhigh} {
3331
lset lines [expr {$i-1}] 1 $le
3344
- if {$arrowhigh} {
3345
- set coords [adjarrowhigh $coords]
3346
- }
3332
} else {
3333
# coalesce two pieces
3334
$canv delete $ith
@@ -3373,7 +3358,7 @@ proc drawparentlinks {id row} {
3358
set x [xc $row $col]
3359
set y [yc $row]
3360
set y2 [yc $row2]
3376
- set d [expr {int(0.4 * $linespc)}]
3361
+ set d [expr {int(0.5 * $linespc)}]
3362
set ymid [expr {$y + $d}]
3363
set ids [lindex $rowidlist $row2]
3364
# rmx = right-most X coord used