source: tol/tolbase/lib/toltk/graph.tcl @ e946b884

1941-docker-image-to-testdevel
Last change on this file since e946b884 was af9a0af, checked in by Jorge Pérez <josp.jorge@…>, 15 years ago

patch for a bug in BLT 2.4 related to blt::busy command

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@3884 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 6.4 KB
Line 
1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : graph.tcl
3# PURPOSE : This file is part of BLT Toolkit
4#/////////////////////////////////////////////////////////////////////////////
5
6# force blt load
7
8if { [ info command "Blt_ZoomStack" ] eq "" } {
9  blt::graph .__g__
10  Blt_ZoomStack .__g__
11  destroy .__g__
12  rename blt::InitStack _blt_InitStack
13}
14
15proc Busy_Patched { cmd args } {
16    puts "-- Busy $cmd $args --"
17    switch $cmd {
18      patched {
19        return 1
20      }
21      default {
22       
23      }
24    }
25}
26
27if { [ catch { blt::busy patched } ] } {
28  rename ::blt::busy _blt_busy
29  interp alias {} ::blt::busy {} Busy_Patched
30  puts "interp alias {} ::blt::busy {} Busy_Patched"
31}
32
33
34# Cambia el ViewMode
35# modos posibles:
36#   zoom-frame
37#   zoom-in
38#   zoom-out
39#   scroll
40
41proc Blt_ViewMode { graph mode } {
42  global zoomInfo
43
44  if { ![blt::ClearMode $graph $mode] } return
45
46  set zoomInfo($graph,mode) $mode
47
48  if { [string equal $mode "scroll"] } {
49    # limpio el stack
50    blt::InitStack $graph $mode
51    bind scroll-$graph <ButtonPress-1> { blt::SetScrollPoint %W %x %y }
52    bind scroll-$graph <ButtonRelease-1> { blt::SetScrollPoint %W %x %y }
53    # este evento posiblemente ya no hara falta
54    bind scroll-$graph <ButtonPress-3> {
55      if { [%W inside %x %y] } {
56        blt::ResetScroll %W
57      }
58    }
59    blt::AddBindTag $graph scroll-$graph
60  } elseif { [regexp "zoom-*" $mode] } {
61    puts "mode = $mode"
62    bind zoom-$graph <ButtonPress-1> { blt::SetZoomPoint %W %x %y }
63    if { [string equal $mode zoom-frame] } {
64      bind zoom-$graph <ButtonRelease-1> { blt::SetZoomPoint %W %x %y }
65    } else {
66      bind zoom-$graph <ButtonRelease-1> ""
67    }
68    bind zoom-$graph <ButtonPress-3> {
69      if { [%W inside %x %y] } {
70        blt::ResetZoom %W
71      }
72    }
73    blt::AddBindTag $graph zoom-$graph
74  }
75}
76
77proc blt::InitStack { graph {mode zoom-frame} } {
78    global zoomInfo
79 
80    _blt_InitStack $graph
81    # this is to allow zoom in, out scroll
82 
83    set zoomInfo($graph,mode) $mode
84}
85
86
87proc blt::SetZoomScale { graph scale } {
88  global zoomInfo
89
90  set zoomInfo($graph,scale) $scale
91}
92
93proc blt::ClearMode { graph newmode } {
94  global zoomInfo
95
96  if { [info exists zoomInfo($graph,mode)] } {
97    if { [string equal $newmode $zoomInfo($graph,mode)] } {
98      return 0
99    }
100    set zoomInfo($graph,corner) A
101    if { [string equal $zoomInfo($graph,mode) "scroll"] } {
102      eval $graph marker delete [$graph marker names "scroll*"]
103      blt::RemoveBindTag $graph "scroll-region-$graph" "scroll-$graph"
104    } else {
105      eval $graph marker delete [$graph marker names "zoom*"]
106      blt::RemoveBindTag $graph "select-region-$graph" "zoom-$graph"
107    }
108  } else {
109    blt::InitStack $graph ""
110  }
111  return 1
112}
113
114proc blt::ZoomScale { graph } {
115  global zoomInfo
116
117  set cmd {}
118  foreach axis {x y} {
119    set limits [$graph axis limits $axis]
120    set min [lindex $limits 0]
121    set max [lindex $limits 1]
122    set delta$axis [expr 0.5 * ($max - $min)]
123    set c [list $graph axis configure $axis -min $min -max $max]
124    append cmd "$c\n"
125  }
126  set zoomInfo($graph,stack) [linsert $zoomInfo($graph,stack) 0 $cmd]
127  busy hold $graph
128  # This update lets the busy cursor take effect.
129  update
130
131  Tolcon_Trace "En ZoomScale zoomInfo($graph,scale) vale  $zoomInfo($graph,scale)"
132
133  if { [string equal $zoomInfo($graph,mode) "zoom-in"] } {
134    set deltax [expr $deltax * $zoomInfo($graph,scale)]
135    set deltay [expr $deltay * $zoomInfo($graph,scale)]
136  } else {
137    set deltax [expr $deltax / $zoomInfo($graph,scale)]
138    set deltay [expr $deltay / $zoomInfo($graph,scale)]
139  }
140
141  foreach {axis delta} [list x $deltax y $deltay] {
142    set v [$graph axis invtransform $axis $zoomInfo($graph,A,$axis)]
143    set min [expr $v - $delta]
144    set max [expr $v + $delta]
145    $graph axis configure $axis -min $min -max $max
146  }
147  # This "update" forces the graph to be redrawn
148  set this [::bayesGraph::getInstance $graph]
149  upvar \#0 ${this}::data data
150  set gr $data(gr,active)
151  #Tolcon_Trace "Aplicando Axis Ticks ZoomScale"
152  ::bayesGraph::GrapOptApplyAxisTicks    $this ${this}::options gr,$gr
153  update
154 
155  busy release $graph
156}
157
158proc blt::SetZoomPoint { graph x y } {
159  global zoomInfo zoomMod
160  if { ![info exists zoomInfo($graph,corner)] } {
161    blt::InitStack $graph
162  }
163  blt::GetCoords $graph $x $y $zoomInfo($graph,corner)
164
165  #puts  blt::SetZoomPoint
166
167  if { [string compare $zoomInfo($graph,mode) "zoom-frame"] } {
168    blt::ZoomScale $graph
169    return
170  }
171
172  if { [info exists zoomMod] } {
173    set modifier $zoomMod
174  } else {
175    set modifier "Any-"
176  }
177  bind select-region-$graph <${modifier}Motion> {
178    blt::GetCoords %W %x %y B
179    #blt::MarkPoint $graph B
180    blt::Box %W
181  }
182  if { $zoomInfo($graph,corner) == "A" } {
183        if { ![$graph inside $x $y] } {
184            return
185        }
186        # First corner selected, start watching motion events
187
188        #blt::MarkPoint $graph A
189        blt::ZoomTitleNext $graph
190
191        blt::AddBindTag $graph select-region-$graph
192        set zoomInfo($graph,corner) B
193  } else {
194        # Delete the modal binding
195        blt::RemoveBindTag $graph select-region-$graph
196        blt::PushZoom $graph
197        set zoomInfo($graph,corner) A
198  }
199}
200
201proc blt::SetScrollPoint { graph x y } {
202    global zoomInfo
203
204    blt::GetCoords $graph $x $y A
205    bind scroll-region-$graph <Any-Motion> {
206        blt::GetCoords %W %x %y B
207        #blt::MarkPoint $graph B
208        blt::Scroll %W
209    }
210    if { $zoomInfo($graph,corner) == "A" } {
211        if { ![$graph inside $x $y] } {
212            return
213        }
214        # First corner selected, start watching motion events
215
216        #blt::MarkPoint $graph A
217        blt::ScrollTitle $graph
218
219        blt::AddBindTag $graph scroll-region-$graph
220        set zoomInfo($graph,corner) B
221    } else {
222        # Delete the modal binding
223      ResetScroll $graph
224    }
225}
226
227proc blt::Scroll { graph } {
228  global zoomInfo
229
230  set x1 [$graph xaxis invtransform $zoomInfo($graph,A,x)]
231  set x2 [$graph xaxis invtransform $zoomInfo($graph,B,x)]
232  set y1 [$graph yaxis invtransform $zoomInfo($graph,A,y)]
233  set y2 [$graph yaxis invtransform $zoomInfo($graph,B,y)]
234  #set deltax [expr $x2 - $x1]
235  #set deltay [expr $y2 - $y1]
236  # Cambiado para efecto 'agarrar el gráfico'
237  set deltax [expr $x1 - $x2]
238  set deltay [expr $y1 - $y2]
239  foreach {delta axis} [list $deltax x $deltay y] {
240    set limits [$graph axis limits $axis]
241    set lower [expr [lindex $limits 0] + $delta]
242    set upper [expr [lindex $limits 1] + $delta]
243    $graph axis configure $axis -min $lower -max $upper
244  }
245  set zoomInfo($graph,A,x) $zoomInfo($graph,B,x)
246  set zoomInfo($graph,A,y) $zoomInfo($graph,B,y)
247}
Note: See TracBrowser for help on using the repository browser.