source: trunk/kitgen/8.x/blt/time_axis.tcl@ 181

Last change on this file since 181 was 175, checked in by demin, 12 years ago

initial commit

File size: 1.6 KB
Line 
1package require BLT
2
3pack [blt::graph .g -width 10i]
4
5# Proc passed as a callback to BLT to draw custom tick labels.
6#
7proc format_timeAxis_tick {win seconds} {
8 set hour [clock format $seconds -format "%H"]
9 regsub {^0*} $hour {} label
10 if {[string equal $label {}]} {
11 return "$label\n[string repeat { } $::nSpaces]\
12 [clock format $seconds -format "%d/%m"]"
13 } else {
14 return $label
15 }
16}
17
18# Construct a list of major tick positions in seconds - the
19# month, year and the range of days can be varied to suit
20# the application.
21#
22for {set day 20} {$day <= 23} {incr day} {
23 foreach hours {0 4 8 12 16 20} {
24 lappend majorticks [clock scan "3/$day/2001 $hours:00"]
25 }
26}
27lappend majorticks [clock scan "3/$day/2001 00:00"]
28
29# Create the graph.
30.g axis configure x \
31 -min [lindex $majorticks 0] \
32 -max [lindex $majorticks end] \
33 -title "Day" \
34 -majorticks $majorticks
35
36# Need to do an update to display the graph before the
37# distance can be measured.
38update
39
40# Measure the width of a day on the graph - the example
41# dates need not be in the displayed range.
42set dayFieldWidth [expr {
43 [.g axis transform x [clock scan 3/2/2001]] -
44 [.g axis transform x [clock scan 3/1/2001]]}]
45
46# Work out how many spaces this corresponds to in the
47# font for the tick labels.
48set nSpaces [expr {$dayFieldWidth /
49 [font measure [.g axis cget x -tickfont] " "]}]
50
51# Configure the axis to use the custom label command.
52.g axis configure x -command format_timeAxis_tick
Note: See TracBrowser for help on using the repository browser.