home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / TCL / BLT / _BLT.TAR / usr / lib / blt / demos / barchart next >
Encoding:
Text File  |  1994-04-09  |  4.3 KB  |  143 lines

  1. #!../blt_wish -f
  2.  
  3. if [file exists ../library] {
  4.     set blt_library ../library
  5. }
  6. set graph .graph
  7.  
  8. blt_bitmap define pattern1 { {4 4} {01 02 04 08} }
  9. blt_bitmap define pattern2 { {4 4} {08 04 02 01} }
  10. blt_bitmap define pattern3 { {2 2} {01 02 } }
  11. blt_bitmap define pattern4 { {4 4} {0f 00 00 00} }
  12. blt_bitmap define pattern5 { {4 4} {01 01 01 01} }
  13. blt_bitmap define pattern6 { {2 2} {01 00 } }
  14. blt_bitmap define pattern7 { {4 4} {0f 01 01 01} }
  15. blt_bitmap define pattern8 { {8 8} {ff 00 ff 00 ff 00 ff 00 } }
  16. blt_bitmap define pattern9 { {4 4} {03 03 0c 0c} }
  17. blt_bitmap define hobbes { {25 25} {
  18.    00 00 00 00 00 00 00 00 00 c0 03 00 78 e0 07 00 fc f8 07 00 cc 07 04 00
  19.    0c f0 0b 00 7c 1c 06 00 38 00 00 00 e0 03 10 00 e0 41 11 00 20 40 11 00
  20.    e0 07 10 00 e0 c1 17 00 10 e0 2f 00 20 e0 6f 00 18 e0 2f 00 20 c6 67 00
  21.    18 84 2b 00 20 08 64 00 70 f0 13 00 80 01 08 00 00 fe 07 00 00 00 00 00
  22.    00 00 00 00 }
  23. }
  24.  
  25. option add *Blt_htext.Font *Times-Bold-R*14*
  26. option add *graph.xTitle "X Axis Label"
  27. option add *graph.yTitle "Y Axis Label"
  28. option add *graph.title "A Simple Barchart"
  29. option add *graph.xFont *Times-Medium-R*12*
  30. option add *graph.elemBackground white
  31. option add *graph.elemRelief raised
  32.  
  33. set visual [winfo screenvisual .] 
  34. if { $visual != "staticgray" && $visual != "grayscale" } {
  35.     option add *print.background yellow
  36.     option add *quit.background red
  37. }
  38.  
  39. blt_htext .header -text \
  40. {This is an example of the blt_barchart widget.  The barchart has 
  41. many components; x and y axis, legend, crosshairs, elements, etc.  
  42. You can configure any component by pressing this %% 
  43. button $blt_htext(widget).config -text button \
  44.     -command "exec [list ../blt_wish -f ./grconf.tcl [winfo name .] $graph &]"\
  45.     -bg green
  46. $blt_htext(widget) append $blt_htext(widget).config
  47. %%.
  48.  
  49. To create a postscript file "bar.ps", press the %%
  50. button $blt_htext(widget).print -text {Print} -command {
  51.   $graph postscript bar.ps -pagewidth 6.5i -pageheight 9i -landscape true
  52. $blt_htext(widget) append $blt_htext(widget).print
  53. %% button.}
  54.  
  55. blt_barchart $graph  
  56. $graph xaxis configure -rotate 90 -command FormatLabel
  57.  
  58. blt_htext .footer -text {Hit the %%
  59. button $blt_htext(widget).quit -text quit -command {destroy .} 
  60. $blt_htext(widget) append $blt_htext(widget).quit 
  61. %% button when you've seen enough.%%
  62. label $blt_htext(widget).logo -bitmap BLT
  63. $blt_htext(widget) append $blt_htext(widget).logo -padx 20
  64. %%}
  65.  
  66. set names { One Two Three Four Five Six Seven Eight }
  67. if { $visual == "staticgray" || $visual == "grayscale" } {
  68.     set fgcolors { white white white white white white white white }
  69.     set bgcolors { black black black black black black black black }
  70. } else {
  71.     set fgcolors { red green blue purple orange brown cyan navy }
  72.     set bgcolors { green blue purple orange brown cyan navy red }
  73. }
  74. set numColors [llength $names]
  75.  
  76. for { set i 0} { $i < $numColors } { incr i } {
  77.     $graph element create [lindex $names $i] \
  78.     -data { $i+1 $i+1 } \
  79.     -fg [lindex $fgcolors $i] \
  80.     -bg [lindex $bgcolors $i] \
  81.     -stipple pattern[expr $i+1]  \
  82.     -relief raised \
  83.     -bd 2 
  84. }
  85.  
  86. $graph element create Nine \
  87.     -data { 9 -0.5 } \
  88.     -fg red  \
  89.     -relief sunken 
  90. $graph element create Ten \
  91.     -data { 10 2 } \
  92.     -fg seagreen \
  93.     -stipple hobbes \
  94.     -background palegreen 
  95. $graph element create Eleven \
  96.     -data { 11 3.3 } \
  97.     -fg blue  
  98.  
  99. pack append . \
  100.     .header { padx 20 pady 10 }  \
  101.     .graph {} \
  102.     .footer { padx 20 pady 10 }
  103.     
  104. wm min . 0 0
  105. bind $graph <B1-ButtonRelease> { %W crosshairs toggle }
  106. bind $graph <ButtonPress-3> {
  107.     set info [%W element closest %x %y]
  108.     if { $info == "" } {
  109.         blt_bell
  110.     } else {
  111.         puts stdout "$info"
  112.     }
  113. }
  114.     
  115. proc TurnOnHairs { graph } {
  116.     bind $graph <Any-Motion> {%W crosshairs configure -position @%x,%y}
  117. }
  118. proc TurnOffHairs { graph } {
  119.     bind $graph <Any-Motion> {%W crosshairs configure -position @%x,%y}
  120. }
  121.  
  122. bind $graph <Enter> { TurnOnHairs %W }
  123. bind $graph <Leave> { TurnOffHairs %W }
  124.  
  125. proc FormatLabel { w value } {
  126.     # Determine the element name from the value
  127.     set displaylist [$w element show]
  128.     set index [expr round($value)-1]
  129.     set name [lindex $displaylist $index]
  130.     if { $name == "" } { 
  131.     return $name
  132.     }
  133.     # Return the element label
  134.     set info [$w element configure $name -label]
  135.     return [lindex $info 4]
  136. }
  137.  
  138. source features.tcl
  139. SetActiveLegend $graph
  140. SetClosestPoint $graph
  141. SetZoom $graph
  142.