Debian Codegraph @

demos/graph1.tcl

raw
1 #!../src/bltwish
2
3 package require BLT
4
5 # --------------------------------------------------------------------------
6 # Starting with Tcl 8.x, the BLT commands are stored in their own
7 # namespace called "blt". The idea is to prevent name clashes with
8 # Tcl commands and variables from other packages, such as a "table"
9 # command in two different packages.
10 #
11 # You can access the BLT commands in a couple of ways. You can prefix
12 # all the BLT commands with the namespace qualifier "blt::"
13 #
14 # blt::graph .g
15 # blt::table . .g -resize both
16 #
17 # or you can import all the command into the global namespace.
18 #
19 # namespace import blt::*
20 # graph .g
21 # table . .g -resize both
22 #
23 # --------------------------------------------------------------------------
24
25 if { $tcl_version >= 8.0 } {
26 namespace import blt::*
27 namespace import -force blt::tile::*
28 }
29
30 source scripts/demo.tcl
31
32 if { [winfo screenvisual .] != "staticgray" } {
33 option add *print.background yellow
34 option add *quit.background red
35 set image [image create photo -file ./images/rain.gif]
36 option add *Graph.Tile $image
37 option add *Label.Tile $image
38 option add *Frame.Tile $image
39 option add *Htext.Tile $image
40 option add *TileOffset 0
41 }
42
43 set graph [graph .g]
44 htext .header \
45 -text {\
46 This is an example of the graph widget. It displays two-variable data
47 with assorted line attributes and symbols. To create a postscript file
48 "xy.ps", press the %%
49 button $htext(widget).print -text print -command {
50 puts stderr [time {
51 blt::busy hold .
52 update
53 .g postscript output demo1.eps
54 update
55 blt::busy release .
56 update
57 }]
58 }
59 $htext(widget) append $htext(widget).print
60 %% button.}
61
62 source scripts/graph1.tcl
63
64 htext .footer \
65 -text {Hit the %%
66 button $htext(widget).quit -text quit -command { exit }
67 $htext(widget) append $htext(widget).quit
68 %% button when you've seen enough.%%
69 label $htext(widget).logo -bitmap BLT
70 $htext(widget) append $htext(widget).logo -padx 20
71 %%}
72
73 proc MultiplexView { args } {
74 eval .g axis view y $args
75 eval .g axis view y2 $args
76 }
77
78 scrollbar .xbar \
79 -command { .g axis view x } \
80 -orient horizontal -relief flat \
81 -highlightthickness 0 -elementborderwidth 2 -bd 0
82 scrollbar .ybar \
83 -command MultiplexView \
84 -orient vertical -relief flat -highlightthickness 0 -elementborderwidth 2
85 table . \
86 0,0 .header -cspan 3 -fill x \
87 1,0 .g -fill both -cspan 3 -rspan 3 \
88 2,3 .ybar -fill y -padx 0 -pady 0 \
89 4,1 .xbar -fill x \
90 5,0 .footer -cspan 3 -fill x
91
92 table configure . c3 r0 r4 r5 -resize none
93
94 .g postscript configure \
95 -center yes \
96 -maxpect yes \
97 -landscape no \
98 -preview yes
99
100 .g axis configure x \
101 -scrollcommand { .xbar set } \
102 -scrollmax 10 \
103 -scrollmin 2
104
105 .g axis configure y \
106 -scrollcommand { .ybar set }
107
108 .g axis configure y2 \
109 -scrollmin 0.0 -scrollmax 1.0 \
110 -hide no \
111 -title "Y2"
112
113 .g legend configure \
114 -activerelief flat \
115 -activeborderwidth 1 \
116 -position top -anchor ne
117
118 .g pen configure "activeLine" \
119 -showvalues y
120 .g element bind all <Enter> {
121 %W legend activate [%W element get current]
122 }
123 .g configure -plotpady { 1i 0 }
124 .g element bind all <Leave> {
125 %W legend deactivate [%W element get current]
126 }
127 .g axis bind all <Enter> {
128 set axis [%W axis get current]
129 %W axis configure $axis -background lightblue2
130 }
131 .g axis bind all <Leave> {
132 set axis [%W axis get current]
133 %W axis configure $axis -background ""
134 }
135 .g configure -leftvariable left
136 trace variable left w "UpdateTable .g"
137 proc UpdateTable { graph p1 p2 how } {
138 table configure . c0 -width [$graph extents leftmargin]
139 table configure . c2 -width [$graph extents rightmargin]
140 table configure . r1 -height [$graph extents topmargin]
141 table configure . r3 -height [$graph extents bottommargin]
142 }
143
144 set image2 [image create photo -file images/blt98.gif]
145 .g element configure line2 -areapattern @bitmaps/sharky.xbm \
146
147 # -areaforeground blue -areabackground ""
148 .g element configure line3 -areatile $image2
149 .g configure -title [pwd]