11package require snit
22package require Tk 8.6
3- package provide ukaz 2.0a2
3+ package provide ukaz 2.0a3
44
55namespace eval ukaz {
66
@@ -415,7 +415,7 @@ namespace eval ukaz {
415415 }
416416
417417 # ########### Function for automatic axis scaling ##########
418- proc compute_ticlist {min max tics log widen format } {
418+ proc compute_ticlist {min max tics log widen formatcmd } {
419419 # automatically compute sensible values
420420 # for the tics position, if not requested otherwise
421421 lassign $tics ticrequest spec
@@ -477,7 +477,7 @@ namespace eval ukaz {
477477 foreach mantisse $minor {
478478 set tic [expr {$mantisse *$base }]
479479 if {$tic >= $min && $tic <=$max } {
480- lappend ticlist [format $format $tic ] $tic
480+ lappend ticlist [{*} $formatcmd $tic ] $tic
481481 }
482482 }
483483 }
@@ -490,7 +490,7 @@ namespace eval ukaz {
490490 set tic [expr {$mantisse *10.0**$expmax }]
491491 if {$tic >= $max } {
492492 set max $tic
493- lappend ticlist [format $format $tic ] $tic
493+ lappend ticlist [{*} $formatcmd $tic ] $tic
494494 break
495495 }
496496 }
@@ -541,7 +541,7 @@ namespace eval ukaz {
541541 for {set i $start } {$i <=$stop } {incr i} {
542542 set v [expr {$i *$ticbase }]
543543 # if {$log && $v<=0} { continue }
544- lappend ticlist [format $format $v ] $v
544+ lappend ticlist [{*} $formatcmd $v ] $v
545545 }
546546 return [list $ticlist $min $max ]
547547 }
@@ -1121,6 +1121,37 @@ namespace eval ukaz {
11211121 $self RedrawRequest
11221122 }
11231123
1124+ method {set format} {axis args} {
1125+ switch $axis {
1126+ x { upvar 0 options(-xformat) fmtvar }
1127+ y { upvar 0 options(-yformat) fmtvar }
1128+ default { return -code error " Unknown axis $axis " }
1129+ }
1130+ switch [llength $args ] {
1131+ 0 {
1132+ # restore default
1133+ set fmt %g
1134+ }
1135+ 1 {
1136+ # one argument = "format" formatstring
1137+ set fmt [list numeric {*}$args ]
1138+ }
1139+ 2 {
1140+ # two arguments = swap order for formatcmd
1141+ lassign $args fmtstring type
1142+ if {$type ni {command timedate numeric}} {
1143+ return -code error " Unknown formatting procedure $type "
1144+ }
1145+ set fmt [list $type $fmtstring ]
1146+ }
1147+ default {
1148+ return -code error " Wrong # arguments ($args given): $self set format <axis> ?fmt? ?type?"
1149+ }
1150+ }
1151+ set fmtvar $fmt
1152+ $self RedrawRequest
1153+ }
1154+
11241155 method {set key} {args} {
11251156 # no argument - just enable legend
11261157 if {[llength $args ]==0} {
@@ -1231,14 +1262,31 @@ namespace eval ukaz {
12311262 # now we have the tight range in xmin,xmax, ymin, ymax
12321263 # compute ticlists and round for data determined values
12331264 lassign [compute_ticlist $xmin $xmax $options(-xtics) \
1234- $options(-logx) $xwiden $options(-xformat) ] xticlist xmin xmax
1265+ $options(-logx) $xwiden [formatcmd $options(-xformat) ] ] xticlist xmin xmax
12351266
12361267 lassign [compute_ticlist $ymin $ymax $options(-ytics) \
1237- $options(-logy) $ywiden $options(-yformat) ] yticlist ymin ymax
1268+ $options(-logy) $ywiden [formatcmd $options(-yformat) ] ] yticlist ymin ymax
12381269
12391270 set displayrange [dict create xmin $xmin xmax $xmax ymin $ymin ymax $ymax ]
12401271
12411272 }
1273+
1274+ proc formatcmd {fmt} {
1275+ # return a cmd prefix to convert
1276+ # tic positions into strings
1277+ if {[llength $fmt ]<=1} {
1278+ # single argument - use format
1279+ return [list format {*}$fmt ]
1280+ }
1281+ lassign $fmt type arg
1282+ switch $type {
1283+ command { return $arg }
1284+ timedate { return [list apply {{fmt t} {clock format [expr {entier($t )}] -format $fmt }} $arg ] }
1285+ numeric { return [list format $arg ] }
1286+ default { return -code error " Wrong tic format option" }
1287+ }
1288+ error " Shit happens"
1289+ }
12421290
12431291 method calcsize {} {
12441292 # compute size of the plot area in pixels
0 commit comments