/usr/share/tcltk/tklib0.6/plotchart/plotannot.tcl is in tklib 0.6-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | # plotannot.tcl --
# Facilities for annotating charts
#
# Note:
# This source file contains such functions as to draw a
# balloon text in an xy-graph.
# It is the companion of "plotchart.tcl"
#
#
# Static data
#
namespace eval ::Plotchart {
# Index, three pairs of scale factors to determine xy-coordinates
set BalloonDir(north-west) {0 0 1 -2 -2 1 0}
set BalloonDir(north) {1 -1 0 0 -3 1 0}
set BalloonDir(north-east) {2 -1 0 2 -2 0 1}
set BalloonDir(east) {3 0 -1 3 0 0 1}
set BalloonDir(south-east) {4 0 -1 2 2 -1 0}
set BalloonDir(south) {5 1 0 0 3 -1 0}
set BalloonDir(south-west) {6 1 0 -2 2 0 -1}
set BalloonDir(west) {7 0 1 -3 0 0 -1}
set TextDir(centre) c
set TextDir(center) c
set TextDir(c) c
set TextDir(west) w
set TextDir(w) w
set TextDir(north-west) nw
set TextDir(nw) nw
set TextDir(north) n
set TextDir(n) n
set TextDir(north-east) ew
set TextDir(ne) ew
set TextDir(east) e
set TextDir(e) e
set TextDir(south-west) nw
set TextDir(sw) sw
set TextDir(south) s
set TextDir(s) s
set TextDir(south-east) ew
set TextDir(east) e
}
# DefaultBalloon --
# Set the default properties of balloon text and other types of annotation
# Arguments:
# w Name of the canvas
# Result:
# None
# Side effects:
# Stores the default settings
#
proc ::Plotchart::DefaultBalloon { w } {
variable settings
foreach {option value} {font fixed
margin 5
textcolour black
justify left
arrowsize 5
background white
outline black
rimwidth 1} {
set settings($w,balloon$option) $value
}
foreach {option value} {font fixed
colour black
justify left} {
set settings($w,text$option) $value
}
}
# ConfigBalloon --
# Configure the properties of balloon text
# Arguments:
# w Name of the canvas
# args List of arguments
# Result:
# None
# Side effects:
# Stores the new settings for the next balloon text
#
proc ::Plotchart::ConfigBalloon { w args } {
variable settings
foreach {option value} $args {
set option [string range $option 1 end]
switch -- $option {
"font" -
"margin" -
"textcolour" -
"justify" -
"arrowsize" -
"background" -
"outline" -
"rimwidth" {
set settings($w,balloon$option) $value
}
"textcolor" {
set settings($w,balloontextcolour) $value
}
}
}
}
# ConfigPlainText --
# Configure the properties of plain text
# Arguments:
# w Name of the canvas
# args List of arguments
# Result:
# None
# Side effects:
# Stores the new settings for the next plain text
#
proc ::Plotchart::ConfigPlainText { w args } {
variable settings
foreach {option value} $args {
set option [string range $option 1 end]
switch -- $option {
"font" -
"textcolour" -
"justify" {
set settings($w,text$option) $value
}
"textcolor" {
set settings($w,textcolour) $value
}
"textfont" {
# Ugly hack!
set settings($w,$option) $value
}
}
}
}
# DrawBalloon --
# Plot a balloon text in a chart
# Arguments:
# w Name of the canvas
# x X-coordinate of the point the arrow points to
# y Y-coordinate of the point the arrow points to
# text Text in the balloon
# dir Direction of the arrow (north, north-east, ...)
# Result:
# None
# Side effects:
# Text and polygon drawn in the chart
#
proc ::Plotchart::DrawBalloon { w x y text dir } {
variable settings
variable BalloonDir
#
# Create the item and then determine the coordinates
# of the frame around the text
#
set item [$w create text 0 0 -text $text -tag BalloonText \
-font $settings($w,balloonfont) -fill $settings($w,balloontextcolour) \
-justify $settings($w,balloonjustify)]
if { ![info exists BalloonDir($dir)] } {
set dir south-east
}
foreach {xmin ymin xmax ymax} [$w bbox $item] {break}
set xmin [expr {$xmin-$settings($w,balloonmargin)}]
set xmax [expr {$xmax+$settings($w,balloonmargin)}]
set ymin [expr {$ymin-$settings($w,balloonmargin)}]
set ymax [expr {$ymax+$settings($w,balloonmargin)}]
set xcentr [expr {($xmin+$xmax)/2}]
set ycentr [expr {($ymin+$ymax)/2}]
set coords [list $xmin $ymin \
$xcentr $ymin \
$xmax $ymin \
$xmax $ycentr \
$xmax $ymax \
$xcentr $ymax \
$xmin $ymax \
$xmin $ycentr ]
set idx [lindex $BalloonDir($dir) 0]
set scales [lrange $BalloonDir($dir) 1 end]
set factor $settings($w,balloonarrowsize)
set extraCoords {}
set xbase [lindex $coords [expr {2*$idx}]]
set ybase [lindex $coords [expr {2*$idx+1}]]
foreach {xscale yscale} $scales {
set xnew [expr {$xbase+$xscale*$factor}]
set ynew [expr {$ybase+$yscale*$factor}]
lappend extraCoords $xnew $ynew
}
#
# Insert the extra coordinates
#
set coords [eval lreplace [list $coords] [expr {2*$idx}] [expr {2*$idx+1}] \
$extraCoords]
set xpoint [lindex $coords [expr {2*$idx+2}]]
set ypoint [lindex $coords [expr {2*$idx+3}]]
set poly [$w create polygon $coords -tag BalloonFrame \
-fill $settings($w,balloonbackground) \
-width $settings($w,balloonrimwidth) \
-outline $settings($w,balloonoutline)]
#
# Position the two items
#
foreach {xtarget ytarget} [coordsToPixel $w $x $y] {break}
set dx [expr {$xtarget-$xpoint}]
set dy [expr {$ytarget-$ypoint}]
$w move $item $dx $dy
$w move $poly $dx $dy
$w raise BalloonFrame
$w raise BalloonText
}
# DrawPlainText --
# Plot plain text in a chart
# Arguments:
# w Name of the canvas
# x X-coordinate of the point the text is positioned to
# y Y-coordinate of the point the text is positioned to
# text Text to be drawn
# anchor Anchor position (north, north-east, ..., defaults to centre)
# Result:
# None
# Side effects:
# Text drawn in the chart
#
proc ::Plotchart::DrawPlainText { w x y text {anchor centre} } {
variable settings
variable TextDir
foreach {xtext ytext} [coordsToPixel $w $x $y] {break}
if { [info exists TextDir($anchor)] } {
set anchor $TextDir($anchor)
} else {
set anchor c
}
$w create text $xtext $ytext -text $text -tag PlainText \
-font $settings($w,textfont) -fill $settings($w,textcolour) \
-justify $settings($w,textjustify) -anchor $anchor
$w raise PlainText
}
# DrawTimeBalloon --
# Plot a balloon text in a TXPlot
# Arguments:
# w Name of the canvas
# time Time-coordinate of the point the arrow points to
# y Y-coordinate of the point the arrow points to
# text Text in the balloon
# dir Direction of the arrow (north, north-east, ...)
# Result:
# None
# Side effects:
# Text and polygon drawn in the chart
#
proc ::Plotchart::DrawTimeBalloon { w time y text dir } {
DrawBalloon $w [clock scan $time] $y $text $dir
}
# DrawTimePlainText --
# Plot plain text in a TXPlot
# Arguments:
# w Name of the canvas
# time Time-coordinate of the point the text is positioned to
# y Y-coordinate of the point the text is positioned to
# text Text to be drawn
# anchor Anchor position (north, north-east, ..., defaults to centre)
# Result:
# None
# Side effects:
# Text drawn in the chart
#
proc ::Plotchart::DrawTimePlainText { w time y text {anchor centre} } {
DrawPlainText $w [clock scan $time] $y $text $anchor
}
# BrightenColour --
# Compute a brighter colour
# Arguments:
# color Original colour
# intensity Colour to interpolate with
# factor Factor by which to brighten the colour
# Result:
# New colour
# Note:
# Adapted from R. Suchenwirths Wiki page on 3D bars
#
proc ::Plotchart::BrightenColour {color intensity factor} {
foreach i {r g b} n [winfo rgb . $color] d [winfo rgb . $intensity] f [winfo rgb . white] {
#checker exclude warnVarRef
set $i [expr {int(255.*($n+($d-$n)*$factor)/$f)}]
}
#checker exclude warnUndefinedVar
format #%02x%02x%02x $r $g $b
}
# DrawGradientBackground --
# Add a gradient background to the plot
# Arguments:
# w Name of the canvas
# colour Main colour
# dir Direction of the gradient (left-right, top-down,
# bottom-up, right-left)
# intensity Brighten (white) or darken (black) the colours
# rect (Optional) coordinates of the rectangle to be filled
# Result:
# None
# Side effects:
# Gradient background drawn in the chart
#
proc ::Plotchart::DrawGradientBackground { w colour dir intensity {rect {}} } {
variable scaling
set pxmin $scaling($w,pxmin)
set pxmax $scaling($w,pxmax)
set pymin $scaling($w,pymin)
set pymax $scaling($w,pymax)
if { $rect != {} } {
foreach {rxmin rymin rxmax rymax} $rect {break}
} else {
set rxmin $pxmin
set rxmax $pxmax
set rymin $pymin
set rymax $pymax
}
switch -- $dir {
"left-right" {
set dir h
set first 0.0
set last 1.0
set fac [expr {($pxmax-$pxmin)/50.0}]
}
"right-left" {
set dir h
set first 1.0
set last 0.0
set fac [expr {($pxmax-$pxmin)/50.0}]
}
"top-down" {
set dir v
set first 0.0
set last 1.0
set fac [expr {($pymin-$pymax)/50.0}]
}
"bottom-up" {
set dir v
set first 1.0
set last 0.0
set fac [expr {($pymin-$pymax)/50.0}]
}
default {
set dir v
set first 0.0
set last 1.0
set fac [expr {($pymin-$pymax)/50.0}]
}
}
if { $dir == "h" } {
set x2 $rxmin
set y1 $rymin
set y2 $rymax
} else {
set y2 $rymax
set x1 $rxmin
set x2 $rxmax
}
set n 50
if { $dir == "h" } {
set nmax [expr {ceil($n*($rxmax-$rxmin)/double($pxmax-$pxmin))}]
} else {
set nmax [expr {ceil($n*($rymin-$rymax)/double($pymin-$pymax))}]
}
for { set i 0 } { $i < $nmax } { incr i } {
set factor [expr {($first*$i+$last*($n-$i-1))/double($n)}]
set gcolour [BrightenColour $colour $intensity $factor]
if { $dir == "h" } {
set x1 $x2
set x2 [expr {$rxmin+($i+1)*$fac}]
if { $i == $nmax-1 } {
set x2 $rxmax
}
} else {
set y1 $y2
set y2 [expr {$rymax+($i+1)*$fac}]
if { $i == $nmax-1 } {
set y2 $rymin
}
}
$w create rectangle $x1 $y1 $x2 $y2 -fill $gcolour -outline $gcolour -tag {data background}
}
$w lower data
$w lower background
}
# DrawImageBackground --
# Add an image (tilde) to the background to the plot
# Arguments:
# w Name of the canvas
# colour Main colour
# image Name of the image
# Result:
# None
# Side effects:
# Image appears in the plot area, tiled if needed
#
proc ::Plotchart::DrawImageBackground { w image } {
variable scaling
set pxmin $scaling($w,pxmin)
set pxmax $scaling($w,pxmax)
set pymin $scaling($w,pymin)
set pymax $scaling($w,pymax)
set iwidth [image width $image]
set iheight [image height $image]
for { set y $pymax } { $y > $pymin } { set y [expr {$y-$iheight}] } {
for { set x $pxmin } { $x < $pxmax } { incr x $iwidth } {
$w create image $x $y -image $image -anchor sw -tags {data background}
}
}
$w lower data
$w lower background
}
|