Debian Codegraph @

demos/barchart3.tcl

raw
1 #!../src/bltwish
2
3 package require BLT
4 # --------------------------------------------------------------------------
5 # Starting with Tcl 8.x, the BLT commands are stored in their own
6 # namespace called "blt". The idea is to prevent name clashes with
7 # Tcl commands and variables from other packages, such as a "table"
8 # command in two different packages.
9 #
10 # You can access the BLT commands in a couple of ways. You can prefix
11 # all the BLT commands with the namespace qualifier "blt::"
12 #
13 # blt::graph .g
14 # blt::table . .g -resize both
15 #
16 # or you can import all the command into the global namespace.
17 #
18 # namespace import blt::*
19 # graph .g
20 # table . .g -resize both
21 #
22 # --------------------------------------------------------------------------
23
24 if { $tcl_version >= 8.0 } {
25 namespace import blt::*
26 namespace import -force blt::tile::*
27 }
28
29 source scripts/demo.tcl
30
31 source scripts/stipples.tcl
32 source scripts/patterns.tcl
33
34
35 option add *graph.xTitle "X Axis Label"
36 option add *graph.yTitle "Y Axis Label"
37 option add *graph.title "A Simple Barchart"
38 option add *graph.xFont *Times-Medium-R*12*
39 option add *graph.elemBackground white
40 option add *graph.elemRelief raised
41
42 set visual [winfo screenvisual .]
43 if { $visual != "staticgray" && $visual != "grayscale" } {
44 option add *print.background yellow
45 option add *quit.background red
46 }
47
48 htext .header -text {
49 This is an example of the barchart widget. To create a postscript
50 file "bar.ps", press the %%
51 button $htext(widget).print -text {Print} -command {
52 $graph postscript output bar.ps -maxpect 1
53 }
54 $htext(widget) append $htext(widget).print
55 %% button.}
56
57 set graph [barchart .b]
58 $graph configure \
59 -invert true \
60 -baseline 1.2
61 $graph xaxis configure \
62 -command FormatLabel \
63 -descending true
64 $graph legend configure \
65 -hide yes
66
67 htext .footer -text {Hit the %%
68 button $htext(widget).quit -text quit -command exit
69 $htext(widget) append $htext(widget).quit
70 %% button when you've seen enough.%%
71 label $htext(widget).logo -bitmap BLT
72 $htext(widget) append $htext(widget).logo -padx 20
73 %%}
74
75 set names { One Two Three Four Five Six Seven Eight }
76 if { $visual == "staticgray" || $visual == "grayscale" } {
77 set fgcolors { white white white white white white white white }
78 set bgcolors { black black black black black black black black }
79 } else {
80 set fgcolors { red green blue purple orange brown cyan navy }
81 set bgcolors { green blue purple orange brown cyan navy red }
82 }
83 set bitmaps {
84 bdiagonal1 bdiagonal2 checker2 checker3 cross1 cross2 cross3 crossdiag
85 dot1 dot2 dot3 dot4 fdiagonal1 fdiagonal2 hline1 hline2 lbottom ltop
86 rbottom rtop vline1 vline2
87 }
88 set numColors [llength $names]
89
90 for { set i 0} { $i < $numColors } { incr i } {
91 $graph element create [lindex $names $i] \
92 -data { $i+1 $i+1 } \
93 -fg [lindex $fgcolors $i] \
94 -bg [lindex $bgcolors $i] \
95 -stipple [lindex $bitmaps $i] \
96 -relief raised \
97 -bd 2
98 }
99
100 $graph element create Nine \
101 -data { 9 -1.0 } \
102 -fg red \
103 -relief sunken
104 $graph element create Ten \
105 -data { 10 2 } \
106 -fg seagreen \
107 -stipple hobbes \
108 -background palegreen
109 $graph element create Eleven \
110 -data { 11 3.3 } \
111 -fg blue
112
113 # -coords { -Inf Inf }
114
115 $graph marker create bitmap \
116 -coords { 11 3.3 } -anchor center \
117 -bitmap @bitmaps/sharky.xbm \
118 -name bitmap \
119 -fill ""
120
121 $graph marker create polygon \
122 -coords { 5 0 7 2 10 10 10 2 } \
123 -name poly -linewidth 0 -fill ""
124
125 table . \
126 .header 0,0 -padx .25i \
127 $graph 1,0 -fill both \
128 .footer 2,0 -padx .25i
129
130 table configure . r0 r2 -resize none
131
132 wm min . 0 0
133
134 proc FormatLabel { w value } {
135 # Determine the element name from the value
136 set displaylist [$w element show]
137 set index [expr round($value)-1]
138 set name [lindex $displaylist $index]
139 if { $name == "" } {
140 return $name
141 }
142 # Return the element label
143 set info [$w element configure $name -label]
144 return [lindex $info 4]
145 }
146
147 Blt_ZoomStack $graph
148 Blt_Crosshairs $graph
149 Blt_ActiveLegend $graph
150 Blt_ClosestPoint $graph
151
152
153 $graph marker bind all <B3-Motion> {
154 set coords [%W invtransform %x %y]
155 catch { %W marker configure [%W marker get current] -coords $coords }
156 }
157
158 $graph marker bind all <Enter> {
159 set marker [%W marker get current]
160 catch { %W marker configure $marker -fill green -outline black}
161 }
162
163 $graph marker bind all <Leave> {
164 set marker [%W marker get current]
165 catch {
166 set default [lindex [%W marker configure $marker -fill] 3]
167 %W marker configure $marker -fill "$default"
168 }
169 }
170