Changeset af9a0af in tol
- Timestamp:
- Dec 4, 2011, 1:58:58 PM (15 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 8d0dffc
- Parents:
- 5c67e4e
- File:
-
- 1 edited
-
tolbase/lib/toltk/graph.tcl (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tolbase/lib/toltk/graph.tcl
r5c67e4e raf9a0af 4 4 #///////////////////////////////////////////////////////////////////////////// 5 5 6 proc Blt_ActiveLegend { graph } { 7 $graph legend bind all <Enter> [list blt::ActivateLegend $graph ] 8 $graph legend bind all <Leave> [list blt::DeactivateLegend $graph] 9 $graph legend bind all <ButtonPress-1> [list blt::HighlightLegend $graph] 10 } 11 12 proc Blt_Crosshairs { graph } { 13 blt::Crosshairs $graph 14 } 15 16 proc Blt_ZoomStack { graph } { 17 blt::ZoomStack $graph 18 } 6 # force blt load 7 8 if { [ info command "Blt_ZoomStack" ] eq "" } { 9 blt::graph .__g__ 10 Blt_ZoomStack .__g__ 11 destroy .__g__ 12 rename blt::InitStack _blt_InitStack 13 } 14 15 proc 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 27 if { [ 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 19 33 20 34 # Cambia el ViewMode … … 61 75 } 62 76 77 proc 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 63 87 proc blt::SetZoomScale { graph scale } { 64 88 global zoomInfo … … 86 110 } 87 111 return 1 88 }89 90 proc Blt_PrintKey { graph } {91 blt::PrintKey $graph92 }93 94 proc Blt_ClosestPoint { graph } {95 blt::ClosestPoint $graph96 }97 98 #99 # The following procedures that reside in the "blt" namespace are100 # supposed to be private.101 #102 103 proc blt::ActivateLegend { graph } {104 set elem [$graph legend get current]105 $graph legend activate $elem106 }107 proc blt::DeactivateLegend { graph } {108 set elem [$graph legend get current]109 $graph legend deactivate $elem110 }111 112 proc blt::HighlightLegend { graph } {113 set elem [$graph legend get current]114 set relief [$graph element cget $elem -labelrelief]115 if { $relief == "flat" } {116 $graph element configure $elem -labelrelief raised117 $graph element activate $elem118 } else {119 $graph element configure $elem -labelrelief flat120 $graph element deactivate $elem121 }122 }123 124 proc blt::Crosshairs { graph { event "Any-Motion" } } {125 $graph crosshairs on126 bind crosshairs-$graph <$event> {127 %W crosshairs configure -position @%x,%y128 }129 bind crosshairs-$graph <Leave> {130 %W crosshairs off131 }132 bind crosshairs-$graph <Enter> {133 %W crosshairs on134 }135 $graph crosshairs configure -color red136 blt::AddBindTag $graph crosshairs-$graph137 }138 139 proc blt::ClearCrosshairs { graph } {140 blt::RemoveBindTag $graph crosshairs-$graph141 $graph crosshairs off142 }143 144 proc blt::InitStack { graph {mode zoom-frame} } {145 global zoomInfo146 set zoomInfo($graph,interval) 100147 set zoomInfo($graph,afterId) 0148 set zoomInfo($graph,afterId1) 0149 set zoomInfo($graph,A,x) {}150 set zoomInfo($graph,A,y) {}151 set zoomInfo($graph,B,x) {}152 set zoomInfo($graph,B,y) {}153 set zoomInfo($graph,stack) {}154 set zoomInfo($graph,corner) A155 156 # this is to allow zoom in, out scroll157 158 set zoomInfo($graph,mode) $mode159 }160 161 proc blt::DeleteStack { graph } {162 global zoomInfo163 164 foreach it [array names zoomInfo $graph,*] {165 unset zoomInfo($it)166 }167 }168 169 proc blt::ZoomStack { graph {start "ButtonPress-1"} {reset "ButtonPress-3"} } {170 global zoomInfo zoomMod171 172 blt::InitStack $graph173 174 if { [info exists zoomMod] } {175 set modifier $zoomMod176 } else {177 set modifier ""178 }179 bind zoom-$graph <${modifier}${start}> { blt::SetZoomPoint %W %x %y }180 bind zoom-$graph <${modifier}${reset}> {181 if { [%W inside %x %y] } {182 blt::ResetZoom %W183 }184 }185 blt::AddBindTag $graph zoom-$graph186 }187 188 proc blt::PrintKey { graph {event "Shift-ButtonRelease-3"} } {189 bind print-$graph <$event> { Blt_PostScriptDialog %W }190 blt::AddBindTag $graph print-$graph191 }192 193 proc blt::ClosestPoint { graph {event "Control-ButtonPress-2"} } {194 bind closest-point-$graph <$event> {195 blt::FindElement %W %x %y196 }197 blt::AddBindTag $graph closest-point-$graph198 }199 200 proc blt::AddBindTag { widget tag } {201 set oldTagList [bindtags $widget]202 if { [lsearch $oldTagList $tag] < 0 } {203 bindtags $widget [linsert $oldTagList 0 $tag]204 }205 }206 207 proc blt::RemoveBindTag { widget args } {208 set oldTagList [bindtags $widget]209 foreach tag $args {210 set index [lsearch $oldTagList $tag]211 if { $index >= 0 } {212 bindtags $widget [lreplace $oldTagList $index $index]213 }214 }215 }216 217 proc blt::FindElement { graph x y } {218 if ![$graph element closest $x $y info -interpolate yes] {219 beep220 return221 }222 # --------------------------------------------------------------223 # find(name) - element Id224 # find(index) - index of closest point225 # find(x) find(y) - coordinates of closest point226 # or closest point on line segment.227 # find(dist) - distance from sample coordinate228 # --------------------------------------------------------------229 set markerName "bltClosest_$info(name)"230 catch { $graph marker delete $markerName }231 $graph marker create text -coords { $info(x) $info(y) } \232 -name $markerName \233 -text "$info(name): $info(dist)\nindex $info(index)" \234 -font *lucida*-r-*-10-* \235 -anchor center -justify left \236 -yoffset 0 -bg {}237 238 set coords [$graph invtransform $x $y]239 set nx [lindex $coords 0]240 set ny [lindex $coords 1]241 242 $graph marker create line -coords "$nx $ny $info(x) $info(y)" \243 -name line.$markerName244 245 blt::FlashPoint $graph $info(name) $info(index) 10246 blt::FlashPoint $graph $info(name) [expr $info(index) + 1] 10247 }248 249 proc blt::FlashPoint { graph name index count } {250 if { $count & 1 } {251 $graph element deactivate $name252 } else {253 $graph element activate $name $index254 }255 incr count -1256 if { $count > 0 } {257 after 200 blt::FlashPoint $graph $name $index $count258 update259 } else {260 eval $graph marker delete [$graph marker names "bltClosest_*"]261 }262 }263 264 proc blt::GetCoords { graph x y index } {265 global zoomInfo266 if { [$graph cget -invertxy] } {267 set zoomInfo($graph,$index,x) $y268 set zoomInfo($graph,$index,y) $x269 } else {270 set zoomInfo($graph,$index,x) $x271 set zoomInfo($graph,$index,y) $y272 }273 }274 275 proc blt::MarkPoint { graph index } {276 global zoomInfo277 set x [$graph xaxis invtransform $zoomInfo($graph,$index,x)]278 set y [$graph yaxis invtransform $zoomInfo($graph,$index,y)]279 set marker "zoomText_$index"280 set text [format "x=%.4g\ny=%.4g" $x $y]281 282 if [$graph marker exists $marker] {283 $graph marker configure $marker -coords { $x $y } -text $text284 } else {285 $graph marker create text -coords { $x $y } -name $marker \286 -font *lucida*-r-*-10-* \287 -text $text -anchor center -bg {} -justify left288 }289 }290 291 proc blt::DestroyZoomTitle { graph } {292 global zoomInfo293 294 if { $zoomInfo($graph,corner) == "A" } {295 catch { $graph marker delete "zoomTitle" }296 }297 }298 299 proc blt::PopZoom { graph } {300 global zoomInfo301 302 set zoomStack $zoomInfo($graph,stack)303 if { [llength $zoomStack] > 0 } {304 set cmd [lindex $zoomStack 0]305 set zoomInfo($graph,stack) [lrange $zoomStack 1 end]306 eval $cmd307 blt::ZoomTitleLast $graph308 busy hold $graph309 set this [::bayesGraph::getInstance $graph]310 upvar \#0 ${this}::data data311 set gr $data(gr,active)312 #Tolcon_Trace "Aplicando Axis Ticks PopZoom"313 ::bayesGraph::GrapOptApplyAxisTicks $this ${this}::options gr,$gr314 update315 set id [after 2000 "blt::DestroyZoomTitle $graph"]316 set zoomInfo($graph,afterId1) $id317 busy release $graph318 } else {319 catch { $graph marker delete "zoomTitle" }320 }321 }322 323 # Push the old axis limits on the stack and set the new ones324 325 proc blt::PushZoom { graph } {326 global zoomInfo327 eval $graph marker delete [$graph marker names "zoom*"]328 if { [info exists zoomInfo($graph,afterId)] } {329 after cancel $zoomInfo($graph,afterId)330 }331 set x1 $zoomInfo($graph,A,x)332 set y1 $zoomInfo($graph,A,y)333 set x2 $zoomInfo($graph,B,x)334 set y2 $zoomInfo($graph,B,y)335 336 if { ($x1 == $x2) || ($y1 == $y2) } {337 # No delta, revert to start338 return339 }340 set cmd {}341 foreach margin { xaxis yaxis x2axis y2axis } {342 foreach axis [$graph $margin use] {343 set min [$graph axis cget $axis -min]344 set max [$graph axis cget $axis -max]345 set c [list $graph axis configure $axis -min $min -max $max]346 append cmd "$c\n"347 }348 }349 set zoomInfo($graph,stack) [linsert $zoomInfo($graph,stack) 0 $cmd]350 351 busy hold $graph352 # This update lets the busy cursor take effect.353 update354 355 foreach margin { xaxis x2axis } {356 foreach axis [$graph $margin use] {357 set min [$graph axis invtransform $axis $x1]358 set max [$graph axis invtransform $axis $x2]359 if { $min > $max } {360 set tmp $min361 set min $max362 set max $tmp363 }364 # this code is to allow zoom-out operations365 if { [string equal $zoomInfo($graph,mode) "zoom-out"] } {366 set limits [$graph axis limits $axis]367 set lower [lindex $limits 0]368 set upper [lindex $limits 1]369 set delta [expr ($upper - $lower)/2.0]370 set min [expr $min - $delta]371 set max [expr $max + $delta]372 }373 # end zoom-out path374 375 # if { $min > $max } {376 # $graph axis configure $axis -min $max -max $min377 # } else {378 # $graph axis configure $axis -min $min -max $max379 # }380 $graph axis configure $axis -min $min -max $max381 }382 }383 foreach margin { yaxis y2axis } {384 foreach axis [$graph $margin use] {385 set min [$graph axis invtransform $axis $y1]386 set max [$graph axis invtransform $axis $y2]387 388 if { $min > $max } {389 set tmp $min390 set min $max391 set max $tmp392 }393 394 # this code is to allow zoom-out operations395 if { [string equal $zoomInfo($graph,mode) "zoom-out"] } {396 set limits [$graph axis limits $axis]397 set lower [lindex $limits 0]398 set upper [lindex $limits 1]399 set delta [expr ($upper - $lower)/2.0]400 set min [expr $min - $delta]401 set max [expr $max + $delta]402 }403 #end zoom-out patch404 405 # if { $min > $max } {406 # $graph axis configure $axis -min $max -max $min407 # } else {408 # $graph axis configure $axis -min $min -max $max409 # }410 $graph axis configure $axis -min $min -max $max411 }412 }413 # This "update" forces the graph to be redrawn414 set this [::bayesGraph::getInstance $graph]415 upvar \#0 ${this}::data data416 set gr $data(gr,active)417 #Tolcon_Trace "Aplicando Axis Ticks PushZoom"418 ::bayesGraph::GrapOptApplyAxisTicks $this ${this}::options gr,$gr419 update420 421 busy release $graph422 }423 424 #425 # This routine terminates either an existing zoom, or pops back to426 # the previous zoom level (if no zoom is in progress).427 #428 429 proc blt::ResetZoom { graph } {430 global zoomInfo431 432 if { ![info exists zoomInfo($graph,corner)] } {433 blt::InitStack $graph434 }435 eval $graph marker delete [$graph marker names "zoom*"]436 437 if { $zoomInfo($graph,corner) == "A" } {438 # Reset the whole axis439 blt::PopZoom $graph440 } else {441 global zoomMod442 if { [info exists zoomMod] } {443 set modifier $zoomMod444 } else {445 set modifier "Any-"446 }447 set zoomInfo($graph,corner) A448 blt::RemoveBindTag $graph select-region-$graph449 }450 }451 452 proc blt::ResetScroll { graph } {453 global zoomInfo454 455 eval $graph marker delete [$graph marker names "scroll*"]456 blt::RemoveBindTag $graph scroll-region-$graph457 set zoomInfo($graph,corner) A458 }459 460 option add *zoomTitle.font -*-helvetica-medium-R-*-*-18-*-*-*-*-*-*-*461 option add *zoomTitle.shadow yellow4462 option add *zoomTitle.foreground yellow1463 option add *zoomTitle.coords "-Inf Inf"464 465 option add *scrollTitle.font -*-helvetica-medium-R-*-*-18-*-*-*-*-*-*-*466 option add *scrollTitle.shadow yellow4467 option add *scrollTitle.foreground yellow1468 option add *scrollTitle.coords "-Inf Inf"469 470 proc blt::ZoomTitleNext { graph } {471 global zoomInfo472 set level [expr [llength $zoomInfo($graph,stack)] + 1]473 if { [$graph cget -invertxy] } {474 set coords "-Inf -Inf"475 } else {476 set coords "-Inf Inf"477 }478 $graph marker create text -name "zoomTitle" -text "Zoom #$level" \479 -coords $coords -bindtags "" -anchor nw480 }481 482 proc blt::ScrollTitle { graph } {483 if { [$graph cget -invertxy] } {484 set coords "-Inf -Inf"485 } else {486 set coords "-Inf Inf"487 }488 $graph marker create text -name "scrollTitle" -text "scrolling ..." \489 -coords $coords -bindtags "" -anchor nw490 }491 492 proc blt::ZoomTitleLast { graph } {493 global zoomInfo494 495 set level [llength $zoomInfo($graph,stack)]496 if { $level > 0 } {497 $graph marker create text -name "zoomTitle" -anchor nw \498 -text "Zoom #$level"499 }500 112 } 501 113 … … 517 129 update 518 130 519 Tolcon_Trace "En ZoomScale zoomInfo($graph,scale) vale $zoomInfo($graph,scale)"131 Tolcon_Trace "En ZoomScale zoomInfo($graph,scale) vale $zoomInfo($graph,scale)" 520 132 521 133 if { [string equal $zoomInfo($graph,mode) "zoom-in"] } { … … 610 222 # Delete the modal binding 611 223 ResetScroll $graph 612 }613 }614 615 option add *zoomOutline.dashes 4616 option add *zoomTitle.anchor nw617 option add *zoomOutline.lineWidth 2618 option add *zoomOutline.xor yes619 620 proc blt::MarchingAnts { graph offset } {621 global zoomInfo622 623 incr offset624 if { [$graph marker exists zoomOutline] } {625 $graph marker configure zoomOutline -dashoffset $offset626 set interval $zoomInfo($graph,interval)627 set id [after $interval [list blt::MarchingAnts $graph $offset]]628 set zoomInfo($graph,afterId) $id629 }630 }631 632 proc blt::Box { graph } {633 global zoomInfo634 635 if { $zoomInfo($graph,A,x) > $zoomInfo($graph,B,x) } {636 set x1 [$graph xaxis invtransform $zoomInfo($graph,B,x)]637 set y1 [$graph yaxis invtransform $zoomInfo($graph,B,y)]638 set x2 [$graph xaxis invtransform $zoomInfo($graph,A,x)]639 set y2 [$graph yaxis invtransform $zoomInfo($graph,A,y)]640 } else {641 set x1 [$graph xaxis invtransform $zoomInfo($graph,A,x)]642 set y1 [$graph yaxis invtransform $zoomInfo($graph,A,y)]643 set x2 [$graph xaxis invtransform $zoomInfo($graph,B,x)]644 set y2 [$graph yaxis invtransform $zoomInfo($graph,B,y)]645 }646 set coords { $x1 $y1 $x2 $y1 $x2 $y2 $x1 $y2 $x1 $y1 }647 if { [$graph marker exists "zoomOutline"] } {648 $graph marker configure "zoomOutline" -coords $coords649 } else {650 set X [lindex [$graph xaxis use] 0]651 set Y [lindex [$graph yaxis use] 0]652 $graph marker create line -coords $coords -name "zoomOutline" \653 -mapx $X -mapy $Y654 set interval $zoomInfo($graph,interval)655 set id [after $interval [list blt::MarchingAnts $graph 0]]656 set zoomInfo($graph,afterId) $id657 224 } 658 225 } … … 679 246 set zoomInfo($graph,A,y) $zoomInfo($graph,B,y) 680 247 } 681 682 proc Blt_PostScriptDialog { graph } {683 set top $graph.top684 toplevel $top685 686 foreach var { center landscape maxpect preview decorations padx687 pady paperwidth paperheight width height colormode } {688 global $graph.$var689 set $graph.$var [$graph postscript cget -$var]690 }691 set row 1692 set col 0693 label $top.title -text "PostScript Options"694 table $top $top.title -cspan 7695 foreach bool { center landscape maxpect preview decorations } {696 set w $top.$bool-label697 label $w -text "-$bool" -font *courier*-r-*12*698 table $top $row,$col $w -anchor e -pady { 2 0 } -padx { 0 4 }699 set w $top.$bool-yes700 global $graph.$bool701 radiobutton $w -text "yes" -variable $graph.$bool -value 1702 table $top $row,$col+1 $w -anchor w703 set w $top.$bool-no704 radiobutton $w -text "no" -variable $graph.$bool -value 0705 table $top $row,$col+2 $w -anchor w706 incr row707 }708 label $top.modes -text "-colormode" -font *courier*-r-*12*709 table $top $row,0 $top.modes -anchor e -pady { 2 0 } -padx { 0 4 }710 set col 1711 foreach m { color greyscale } {712 set w $top.$m713 radiobutton $w -text $m -variable $graph.colormode -value $m714 table $top $row,$col $w -anchor w715 incr col716 }717 set row 1718 frame $top.sep -width 2 -bd 1 -relief sunken719 table $top $row,3 $top.sep -fill y -rspan 6720 set col 4721 foreach value { padx pady paperwidth paperheight width height } {722 set w $top.$value-label723 label $w -text "-$value" -font *courier*-r-*12*724 table $top $row,$col $w -anchor e -pady { 2 0 } -padx { 0 4 }725 set w $top.$value-entry726 global $graph.$value727 entry $w -textvariable $graph.$value -width 8728 table $top $row,$col+1 $w -cspan 2 -anchor w -padx 8729 incr row730 }731 table configure $top c3 -width .125i732 button $top.cancel -text "Cancel" -command "destroy $top"733 table $top $row,0 $top.cancel -width 1i -pady 2 -cspan 3734 button $top.reset -text "Reset" -command "destroy $top"735 #table $top $row,1 $top.reset -width 1i736 button $top.print -text "Print" -command "blt::ResetPostScript $graph"737 table $top $row,4 $top.print -width 1i -pady 2 -cspan 2738 }739 740 proc blt::ResetPostScript { graph } {741 foreach var { center landscape maxpect preview decorations padx742 pady paperwidth paperheight width height colormode } {743 global $graph.$var744 set old [$graph postscript cget -$var]745 if { [catch {$graph postscript configure -$var [set $graph.$var]}] != 0 } {746 $graph postscript configure -$var $old747 set $graph.$var $old748 }749 }750 $graph postscript output "out.ps"751 puts stdout "wrote file \"out.ps\"."752 flush stdout753 }
Note: See TracChangeset
for help on using the changeset viewer.
