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

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

fixes #1354, recovering procedures which were lost in last commit of graph.tcl

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

  • Property mode set to 100644
File size: 7.1 KB
RevLine 
[6d7779d]1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : graph.tcl
3# PURPOSE : This file is part of BLT Toolkit
4#/////////////////////////////////////////////////////////////////////////////
5
[af9a0af]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
[6d7779d]13}
14
[af9a0af]15proc Busy_Patched { cmd args } {
16    puts "-- Busy $cmd $args --"
17    switch $cmd {
18      patched {
19        return 1
20      }
21      default {
22       
23      }
24    }
[6d7779d]25}
26
[af9a0af]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"
[6d7779d]31}
32
[af9a0af]33
[6d7779d]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
[7ec9cb0]77proc blt::RemoveBindTag { widget args } {
78  set oldTagList [bindtags $widget]
79  foreach tag $args {
80    set index [lsearch $oldTagList $tag]
81    if { $index >= 0 } {
82        bindtags $widget [lreplace $oldTagList $index $index]
83    }
84  }
85}
86
[af9a0af]87proc blt::InitStack { graph {mode zoom-frame} } {
88    global zoomInfo
89 
90    _blt_InitStack $graph
91    # this is to allow zoom in, out scroll
92 
93    set zoomInfo($graph,mode) $mode
94}
95
96
[6d7779d]97proc blt::SetZoomScale { graph scale } {
98  global zoomInfo
99
100  set zoomInfo($graph,scale) $scale
101}
102
103proc blt::ClearMode { graph newmode } {
104  global zoomInfo
105
106  if { [info exists zoomInfo($graph,mode)] } {
107    if { [string equal $newmode $zoomInfo($graph,mode)] } {
108      return 0
109    }
110    set zoomInfo($graph,corner) A
111    if { [string equal $zoomInfo($graph,mode) "scroll"] } {
112      eval $graph marker delete [$graph marker names "scroll*"]
113      blt::RemoveBindTag $graph "scroll-region-$graph" "scroll-$graph"
114    } else {
115      eval $graph marker delete [$graph marker names "zoom*"]
116      blt::RemoveBindTag $graph "select-region-$graph" "zoom-$graph"
117    }
118  } else {
119    blt::InitStack $graph ""
120  }
121  return 1
122}
123
124proc blt::ZoomScale { graph } {
125  global zoomInfo
126
127  set cmd {}
128  foreach axis {x y} {
129    set limits [$graph axis limits $axis]
130    set min [lindex $limits 0]
131    set max [lindex $limits 1]
132    set delta$axis [expr 0.5 * ($max - $min)]
133    set c [list $graph axis configure $axis -min $min -max $max]
134    append cmd "$c\n"
135  }
136  set zoomInfo($graph,stack) [linsert $zoomInfo($graph,stack) 0 $cmd]
137  busy hold $graph
138  # This update lets the busy cursor take effect.
139  update
140
[af9a0af]141  Tolcon_Trace "En ZoomScale zoomInfo($graph,scale) vale  $zoomInfo($graph,scale)"
[6d7779d]142
143  if { [string equal $zoomInfo($graph,mode) "zoom-in"] } {
144    set deltax [expr $deltax * $zoomInfo($graph,scale)]
145    set deltay [expr $deltay * $zoomInfo($graph,scale)]
146  } else {
147    set deltax [expr $deltax / $zoomInfo($graph,scale)]
148    set deltay [expr $deltay / $zoomInfo($graph,scale)]
149  }
150
151  foreach {axis delta} [list x $deltax y $deltay] {
152    set v [$graph axis invtransform $axis $zoomInfo($graph,A,$axis)]
153    set min [expr $v - $delta]
154    set max [expr $v + $delta]
155    $graph axis configure $axis -min $min -max $max
156  }
157  # This "update" forces the graph to be redrawn
158  set this [::bayesGraph::getInstance $graph]
159  upvar \#0 ${this}::data data
160  set gr $data(gr,active)
161  #Tolcon_Trace "Aplicando Axis Ticks ZoomScale"
162  ::bayesGraph::GrapOptApplyAxisTicks    $this ${this}::options gr,$gr
163  update
164 
165  busy release $graph
166}
167
168proc blt::SetZoomPoint { graph x y } {
169  global zoomInfo zoomMod
170  if { ![info exists zoomInfo($graph,corner)] } {
171    blt::InitStack $graph
172  }
173  blt::GetCoords $graph $x $y $zoomInfo($graph,corner)
174
175  #puts  blt::SetZoomPoint
176
177  if { [string compare $zoomInfo($graph,mode) "zoom-frame"] } {
178    blt::ZoomScale $graph
179    return
180  }
181
182  if { [info exists zoomMod] } {
183    set modifier $zoomMod
184  } else {
185    set modifier "Any-"
186  }
187  bind select-region-$graph <${modifier}Motion> {
188    blt::GetCoords %W %x %y B
189    #blt::MarkPoint $graph B
190    blt::Box %W
191  }
192  if { $zoomInfo($graph,corner) == "A" } {
193        if { ![$graph inside $x $y] } {
194            return
195        }
196        # First corner selected, start watching motion events
197
198        #blt::MarkPoint $graph A
199        blt::ZoomTitleNext $graph
200
201        blt::AddBindTag $graph select-region-$graph
202        set zoomInfo($graph,corner) B
203  } else {
204        # Delete the modal binding
205        blt::RemoveBindTag $graph select-region-$graph
206        blt::PushZoom $graph
207        set zoomInfo($graph,corner) A
208  }
209}
210
211proc blt::SetScrollPoint { graph x y } {
212    global zoomInfo
213
214    blt::GetCoords $graph $x $y A
215    bind scroll-region-$graph <Any-Motion> {
216        blt::GetCoords %W %x %y B
217        #blt::MarkPoint $graph B
218        blt::Scroll %W
219    }
220    if { $zoomInfo($graph,corner) == "A" } {
221        if { ![$graph inside $x $y] } {
222            return
223        }
224        # First corner selected, start watching motion events
225
226        #blt::MarkPoint $graph A
227        blt::ScrollTitle $graph
228
229        blt::AddBindTag $graph scroll-region-$graph
230        set zoomInfo($graph,corner) B
231    } else {
232        # Delete the modal binding
233      ResetScroll $graph
234    }
235}
236
237proc blt::Scroll { graph } {
238  global zoomInfo
239
240  set x1 [$graph xaxis invtransform $zoomInfo($graph,A,x)]
241  set x2 [$graph xaxis invtransform $zoomInfo($graph,B,x)]
242  set y1 [$graph yaxis invtransform $zoomInfo($graph,A,y)]
243  set y2 [$graph yaxis invtransform $zoomInfo($graph,B,y)]
244  #set deltax [expr $x2 - $x1]
245  #set deltay [expr $y2 - $y1]
246  # Cambiado para efecto 'agarrar el gráfico'
247  set deltax [expr $x1 - $x2]
248  set deltay [expr $y1 - $y2]
249  foreach {delta axis} [list $deltax x $deltay y] {
250    set limits [$graph axis limits $axis]
251    set lower [expr [lindex $limits 0] + $delta]
252    set upper [expr [lindex $limits 1] + $delta]
253    $graph axis configure $axis -min $lower -max $upper
254  }
255  set zoomInfo($graph,A,x) $zoomInfo($graph,B,x)
256  set zoomInfo($graph,A,y) $zoomInfo($graph,B,y)
257}
[7ec9cb0]258
259proc blt::ResetScroll { graph } {
260  global zoomInfo
261
262  eval $graph marker delete [$graph marker names "scroll*"]
263  blt::RemoveBindTag $graph scroll-region-$graph
264  set zoomInfo($graph,corner) A 
265}
266
267proc blt::ScrollTitle { graph } {
268    if { [$graph cget -invertxy] } {
269        set coords "-Inf -Inf"
270    } else {
271        set coords "-Inf Inf"
272    }
273    $graph marker create text -name "scrollTitle" -text "scrolling ..." \
274        -coords $coords -bindtags "" -anchor nw
275}
Note: See TracBrowser for help on using the repository browser.