| 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 |
|
| 32 |
source scripts/stipples.tcl |
| 33 |
|
| 34 |
option add *graph.x.Title "X Axis Label" |
| 35 |
option add *graph.y.Title "Y Axis Label" |
| 36 |
option add *graph.title "A Simple Barchart" |
| 37 |
option add *graph.x.Font { Times 10 } |
| 38 |
option add *graph.Element.Relief raised |
| 39 |
|
| 40 |
set visual [winfo screenvisual .] |
| 41 |
if { $visual != "staticgray" && $visual != "grayscale" } { |
| 42 |
option add *graph.LineMarker.color yellow |
| 43 |
option add *graph.Element.Background white |
| 44 |
option add *graph.Legend.activeForeground pink |
| 45 |
option add *print.background yellow |
| 46 |
option add *quit.background red |
| 47 |
option add *graph.background palegreen |
| 48 |
option add *graph.plotBackground lightblue |
| 49 |
} |
| 50 |
|
| 51 |
htext .htext -text \ |
| 52 |
{ This is an example of the barchart widget. The barchart has |
| 53 |
many components; x and y axis, legend, crosshairs, elements, etc. |
| 54 |
To create a postscript file "bar.ps", press the %% |
| 55 |
set w $htext(widget) |
| 56 |
button $w.print -text {Print} -command { |
| 57 |
$graph postscript output bar.ps |
| 58 |
} |
| 59 |
$w append $w.print |
| 60 |
|
| 61 |
%% button. |
| 62 |
%% |
| 63 |
|
| 64 |
set graph [barchart .htext.graph] |
| 65 |
$graph configure \ |
| 66 |
-relief raised \ |
| 67 |
-bd 2 |
| 68 |
$graph xaxis configure \ |
| 69 |
-rotate 90 \ |
| 70 |
-stepsize 0 |
| 71 |
$w append $graph -fill both -padx 4 |
| 72 |
|
| 73 |
%% |
| 74 |
Hit the %% |
| 75 |
|
| 76 |
button $w.quit -text quit -command exit |
| 77 |
$w append $w.quit |
| 78 |
|
| 79 |
%% button when you've seen enough.%% |
| 80 |
|
| 81 |
label $w.logo -bitmap BLT |
| 82 |
$w append $w.logo -padx 20 |
| 83 |
|
| 84 |
%% } |
| 85 |
|
| 86 |
set names { One Two Three Four Five Six Seven Eight } |
| 87 |
if { $visual == "staticgray" || $visual == "grayscale" } { |
| 88 |
set fgcolors { white white white white white white white white } |
| 89 |
set bgcolors { black black black black black black black black } |
| 90 |
} else { |
| 91 |
set fgcolors { yellow orange red magenta purple blue cyan green } |
| 92 |
set bgcolors { yellow4 orange4 red4 magenta4 purple4 blue4 cyan4 green4 } |
| 93 |
} |
| 94 |
|
| 95 |
set numColors [llength $names] |
| 96 |
|
| 97 |
set tcl_precision 15 |
| 98 |
vector create x |
| 99 |
vector create y |
| 100 |
x seq -5.0 5.0 0.2 |
| 101 |
y expr sin(x) |
| 102 |
set barWidth 0.19 |
| 103 |
|
| 104 |
$graph element create sin -relief raised -bd 1 -x x -y y -barwidth $barWidth |
| 105 |
table . .htext -fill both |
| 106 |
|
| 107 |
wm min . 0 0 |
| 108 |
|
| 109 |
Blt_ZoomStack $graph |
| 110 |
Blt_Crosshairs $graph |
| 111 |
Blt_ActiveLegend $graph |
| 112 |
Blt_ClosestPoint $graph |