4 proc bltResetBindings { graph type } {
7 set all [array names bindings]
10 if [string match "$type,$graph,*" $i] {
11 lappend cmds $bindings($i)
14 bind $graph $type [join $cmds \n]
17 proc bltActivateLegend { graph name } {
20 set last $lastActive($graph)
21 if { $name != $last } {
23 $graph legend deactivate $last
24 $graph element deactivate $last
27 $graph legend activate $name
28 $graph element activate $name
30 set lastActive($graph) $name
34 proc SetActiveLegend { graph } {
35 global lastActive bindings
37 set lastActive($graph) {}
38 set bindings(<Motion>,$graph,activeLegend) {
39 set info [%W legend get @%x,%y]
40 bltActivateLegend %W $info
42 bltResetBindings $graph <Motion>
46 proc SetCrosshairs { graph } {
50 set bindings(<Motion>,$graph,crosshairs) {
51 %W crosshairs configure -position @%x,%y
53 bltResetBindings $graph <Motion>
57 proc bltFindElement { graph x y } {
58 set info [$graph element closest $x $y ]
63 set name [lindex $info 0]
64 set points [lrange $info 2 3]
65 set index [lindex $info 1]
67 catch { $graph tag delete $tagId($graph,$name,$index) }
68 set tagId($graph,$name,$index) \
69 [$graph tag create text $points -text " $name \[$index\] " -anchor s \
70 -yoffset -10 -fg black -bg {}]
71 bltFlashPoint $graph $name $index 10
74 proc bltFlashPoint { graph name index count } {
76 $graph element deactivate $name
78 $graph element activate $name $index
82 after 200 bltFlashPoint $graph $name $index $count
86 catch { $graph tag delete $tagId($graph,$name,$index) }
90 proc SetClosestPoint { graph } {
95 set bindings(<ButtonPress-3>,$graph,closestPoint) {
96 bltFindElement %W %x %y
98 bltResetBindings $graph <ButtonPress-3>
102 proc bltGetCoords { graph winX winY var index } {
103 scan [$graph invtransform $winX $winY] "%s %s" x y
104 scan [$graph xaxis limits] "%s %s" xmin xmax
105 scan [$graph yaxis limits] "%s %s" ymin ymax
109 } elseif { $x < $xmin } {
115 } elseif { $y < $ymin } {
124 proc bltGetAnchor { graph x y } {
129 bltGetCoords $graph $x $y pos A
130 set bindings(<B1-Motion>,$graph,zoom) {
133 set bindings(<ButtonRelease-1>,$graph,zoom) {
136 bltResetBindings $graph <ButtonRelease-1>
137 bltResetBindings $graph <B1-Motion>
140 proc bltGetAnchorX { graph x y } {
145 bltGetCoords $graph $x $y pos A
146 set bindings(<B1-Motion>,$graph,zoomx) {
149 set bindings(<ButtonRelease-1>,$graph,zoomx) {
152 bltResetBindings $graph <ButtonRelease-1>
153 bltResetBindings $graph <B1-Motion>
157 proc bltBox { graph x1 y1 x2 y2 } {
160 set text [format "%.4g,%.4g" $x1 $y1]
161 if { $tagId($graph,text1) == "" } then {
162 set tagId($graph,text1) \
163 [$graph tag create text {$x1 $y1} -text $text ]
165 $graph tag configure $tagId($graph,text1) -text $text
166 $graph tag coords $tagId($graph,text1) "$x1 $y1"
168 set text [format "%.4g,%.4g" $x2 $y2]
169 if { $tagId($graph,text2) == "" } then {
170 set tagId($graph,text2) \
171 [$graph tag create text {$x2 $y2} -text $text ]
173 $graph tag configure $tagId($graph,text2) -text $text
174 $graph tag coords $tagId($graph,text2) "$x2 $y2"
177 $x1 $y1 $x1 $y2 $x1 $y1 $x2 $y1 $x2 $y1 $x2 $y2 $x1 $y2 $x2 $y2
179 if { $tagId($graph,outline) == "" } then {
180 set tagId($graph,outline) [$graph tag create line $coords]
182 $graph tag coords $tagId($graph,outline) $coords
186 proc bltBoxX { graph x1 y1 x2 y2 } {
189 set text [format "%.4g" $x1]
190 if { $tagId($graph,text1) == "" } then {
191 set tagId($graph,text1) \
192 [$graph tag create text {$x1 $y1} -text $text ]
194 $graph tag configure $tagId($graph,text1) -text $text
195 $graph tag coords $tagId($graph,text1) "$x1 $y1"
197 set text [format "%.4g" $x2]
198 if { $tagId($graph,text2) == "" } then {
199 set tagId($graph,text2) \
200 [$graph tag create text {$x2 $y2} -text $text ]
202 $graph tag configure $tagId($graph,text2) -text $text
203 $graph tag coords $tagId($graph,text2) "$x2 $y2"
206 $x1 $y1 $x1 $y2 $x1 $y1 $x2 $y1 $x2 $y1 $x2 $y2 $x1 $y2 $x2 $y2
208 if { $tagId($graph,outline) == "" } then {
209 set tagId($graph,outline) [$graph tag create line $coords]
211 $graph tag coords $tagId($graph,outline) $coords
218 proc bltScan { graph x y } {
221 set deltaX [expr abs($pos(last,x)-$x)]
222 set deltaY [expr abs($pos(last,y)-$y)]
223 if { ($deltaX < 5) && ($deltaY < 5) } {
229 bltGetCoords $graph $x $y pos B
230 if { $pos(A,x) > $pos(B,x) } {
231 bltBox $graph $pos(B,x) $pos(B,y) $pos(A,x) $pos(A,y)
233 bltBox $graph $pos(A,x) $pos(A,y) $pos(B,x) $pos(B,y)
237 proc bltScanX { graph x y } {
240 set deltaX [expr abs($pos(last,x)-$x)]
241 set deltaY [expr abs($pos(last,y)-$y)]
242 if { ($deltaX < 5) && ($deltaY < 5) } {
248 bltGetCoords $graph $x $y pos B
249 if { $pos(A,x) > $pos(B,x) } {
250 bltBox $graph $pos(B,x) $pos(B,y) $pos(A,x) $pos(A,y)
252 bltBox $graph $pos(A,x) $pos(A,y) $pos(B,x) $pos(B,y)
256 proc bltZoom { graph x y } {
257 global bindings pos tagId
259 # Go back to original bindings
260 set bindings(<ButtonPress-1>,$graph,zoom) {
261 bltGetAnchor %W %x %y
263 set bindings(<B1-Motion>,$graph,zoom) {}
265 catch {$graph tag delete $tagId($graph,text1) $tagId($graph,text2)}
266 set tagId($graph,text1) {}
267 set tagId($graph,text2) {}
269 bltResetBindings $graph <B1-Motion>
270 bltResetBindings $graph <ButtonPress-1>
272 if { $pos(B,x) == "" } then {
273 catch {$graph tag delete $tagId($graph,outline)}
274 set tagId($graph,outline) {}
275 $graph xaxis configure -min {} -max {}
276 $graph yaxis configure -min {} -max {}
279 if { $pos(A,x) > $pos(B,x) } {
280 $graph xaxis configure -min $pos(B,x) -max $pos(A,x)
282 if { $pos(A,x) < $pos(B,x) } {
283 $graph xaxis configure -min $pos(A,x) -max $pos(B,x)
286 if { $pos(A,y) > $pos(B,y) } {
287 $graph yaxis configure -min $pos(B,y) -max $pos(A,y)
289 if { $pos(A,y) < $pos(B,y) } {
290 $graph yaxis configure -min $pos(A,y) -max $pos(B,y)
293 # $graph configure -cursor crosshair
294 catch {$graph tag delete $tagId($graph,outline)}
295 set tagId($graph,outline) {}
298 blt_busy release $graph
301 proc bltZoomX { graph x y } {
302 global bindings pos tagId
304 # Go back to original bindings
305 set bindings(<ButtonPress-1>,$graph,zoomx) {
306 bltGetAnchorX %W %x %y
308 set bindings(<B1-Motion>,$graph,zoomx) {}
310 catch {$graph tag delete $tagId($graph,text1) $tagId($graph,text2)}
311 set tagId($graph,text1) {}
312 set tagId($graph,text2) {}
314 bltResetBindings $graph <B1-Motion>
315 bltResetBindings $graph <ButtonPress-1>
317 if { $pos(B,x) == "" } then {
318 catch {$graph tag delete $tagId($graph,outline)}
319 set tagId($graph,outline) {}
320 $graph xaxis configure -min {} -max {}
321 $graph yaxis configure -min {} -max {}
324 if { $pos(A,x) > $pos(B,x) } {
325 $graph xaxis configure -min $pos(B,x) -max $pos(A,x)
327 if { $pos(A,x) < $pos(B,x) } {
328 $graph xaxis configure -min $pos(A,x) -max $pos(B,x)
331 # $graph configure -cursor crosshair
332 catch {$graph tag delete $tagId($graph,outline)}
333 set tagId($graph,outline) {}
336 blt_busy release $graph
340 proc SetZoom { graph } {
341 global bindings tagId
343 set tagId($graph,text1) {}
344 set tagId($graph,text2) {}
345 set tagId($graph,outline) {}
346 set bindings(<ButtonRelease-2>,$graph,zoom) {
347 catch {%W tag delete $tagId(outline) }
348 set tagId(outline) {}
349 %W yaxis configure -min {} -max {}
350 %W xaxis configure -min {} -max {}
355 set bindings(<ButtonPress-1>,$graph,zoom) {
356 # %W configure -cursor {crosshair red black}
357 bltGetAnchor %W %x %y
360 bltResetBindings $graph <ButtonPress-1>
361 bltResetBindings $graph <ButtonRelease-2>
364 proc SetZoomX { graph } {
365 global bindings tagId
367 set tagId($graph,text1) {}
368 set tagId($graph,text2) {}
369 set tagId($graph,outline) {}
370 set bindings(<ButtonRelease-2>,$graph,zoomx) {
371 catch {%W tag delete $tagId(outline) }
372 set tagId(outline) {}
373 %W yaxis configure -min {} -max {}
374 %W xaxis configure -min {} -max {}
379 set bindings(<ButtonPress-1>,$graph,zoomx) {
380 # %W configure -cursor {crosshair red black}
381 bltGetAnchorX %W %x %y
384 bltResetBindings $graph <ButtonPress-1>
385 bltResetBindings $graph <ButtonRelease-2>
388 proc SetPrint { graph } {
390 set bindings(<Shift-ButtonRelease-3>,$graph,print) {
391 puts stdout "creating file \"out.ps\... " nonewline
393 %W postscript "out.ps" -pagewidth 6.5i -pageheight 8.5i -landscape true
397 bltResetBindings $graph <Shift-ButtonRelease-3>