- Timestamp:
- Aug 16, 2011, 3:41:57 PM (13 years ago)
- Location:
- trunk/gui/scripts
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/histogram.tcl
r1929 r2388 25 25 26 26 public method components {{pattern *}} 27 public method locations {} 28 public method heights {} 29 public method widths {} 27 public method mesh { component } 28 public method values { component } 29 public method widths { component } 30 public method xlabels { component } 30 31 public method limits {which} 31 32 public method xmarkers {} … … 33 34 public method hints {{key ""}} 34 35 35 protected method _build {} 36 protected method Build {} 37 private method Clear { {comp ""} } 38 private method ParseData { comp } 36 39 37 40 private variable _xmlobj "" ;# ref to lib obj with histogram data 38 41 private variable _hist "" ;# lib obj representing this histogram 39 private variable _widths "" ;# vector of bin widths (may be empty string). 40 private variable _heights "" ;# vector of bin heights along y-axis. 41 private variable _locations "" ;# vector of bin locations along x-axis. 42 42 private variable _widths ;# array of vectors of bin widths 43 private variable _yvalues ;# array of vectors of bin heights along 44 ;# y-axis. 45 private variable _xvalues ;# array of vectors of bin locations along 46 ;# x-axis. 47 private variable _xlabels ;# array of labels 43 48 private variable _hints ;# cache of hints stored in XML 44 49 private variable _xmarkers "";# list of {x,label,options} triplets. 45 50 private variable _ymarkers "";# list of {y,label,options} triplets. 46 51 private common _counter 0 ;# counter for unique vector names 52 private variable _comp2hist ;# maps component name => x,y,w,l vectors 47 53 } 48 54 … … 58 64 59 65 # build up vectors for various components of the histogram 60 _build66 Build 61 67 } 62 68 … … 65 71 # ---------------------------------------------------------------------- 66 72 itcl::body Rappture::Histogram::destructor {} { 73 # don't destroy the _xmlobj! we don't own it! 67 74 itcl::delete object $_hist 68 # don't destroy the _xmlobj! we don't own it! 69 if {"" != $_widths} { 70 blt::vector destroy $_widths 71 } 72 if {"" != $_heights} { 73 blt::vector destroy $_heights 74 } 75 if {"" != $_locations} { 76 blt::vector destroy $_locations 77 } 78 } 79 80 # ---------------------------------------------------------------------- 81 # USAGE: locations 75 Clear 76 } 77 78 # ---------------------------------------------------------------------- 79 # USAGE: mesh 82 80 # 83 81 # Returns the vector for the histogram bin locations along the 84 82 # x-axis. 85 83 # ---------------------------------------------------------------------- 86 itcl::body Rappture::Histogram::locations {} { 87 return $_locations 84 itcl::body Rappture::Histogram::mesh { comp } { 85 if { [info exists _xvalues($comp)] } { 86 return $_xvalues($comp) 87 } 88 return "" 88 89 } 89 90 … … 93 94 # Returns the vector for the histogram bin heights along the y-axis. 94 95 # ---------------------------------------------------------------------- 95 itcl::body Rappture::Histogram::heights {} { 96 return $_heights 96 itcl::body Rappture::Histogram::values { comp } { 97 if { [info exists _yvalues($comp)] } { 98 return $_yvalues($comp) 99 } 100 return "" 97 101 } 98 102 … … 104 108 # overall histogram (sum of all components). 105 109 # ---------------------------------------------------------------------- 106 itcl::body Rappture::Histogram::widths {} { 107 return $_widths 110 itcl::body Rappture::Histogram::widths { comp } { 111 if { [info exists _widths($comp)] } { 112 return $_widths($comp) 113 } 114 return "" 115 } 116 117 # ---------------------------------------------------------------------- 118 # USAGE: xlabels 119 # 120 # Returns the vector for the specified histogram component <name>. 121 # If the name is not specified, then it returns the vectors for the 122 # overall histogram (sum of all components). 123 # ---------------------------------------------------------------------- 124 itcl::body Rappture::Histogram::xlabels { comp } { 125 if { [info exists _xlabels($comp)] } { 126 return $_xlabels($comp) 127 } 128 return "" 108 129 } 109 130 … … 116 137 itcl::body Rappture::Histogram::xmarkers {} { 117 138 return $_xmarkers; 139 } 140 141 # ---------------------------------------------------------------------- 142 # USAGE: components ?<pattern>? 143 # 144 # Returns a list of names for the various components of this curve. 145 # If the optional glob-style <pattern> is specified, then it returns 146 # only the component names matching the pattern. 147 # ---------------------------------------------------------------------- 148 itcl::body Rappture::Histogram::components {{pattern *}} { 149 set rlist "" 150 foreach name [array names _comp2hist] { 151 if {[string match $pattern $name]} { 152 lappend rlist $name 153 } 154 } 155 return $rlist 118 156 } 119 157 … … 140 178 set max "" 141 179 switch -- $which { 142 x - xlin { 143 set vname $_locations; 144 set log 0; 145 set axis xaxis 146 } 147 xlog { 148 set vname $_locations; 149 set log 1; 150 set axis xaxis 151 } 152 y - ylin { 153 set vname $_heights; 154 set log 0; 155 set axis yaxis 156 } 157 ylog { 158 set vname $_heights; 159 set log 1; 160 set axis yaxis 161 } 180 x - xlin { set pos 0; set log 0; set axis xaxis } 181 xlog { set pos 0; set log 1; set axis xaxis } 182 y - ylin - v - vlin { set pos 1; set log 0; set axis yaxis } 183 ylog - vlog { set pos 1; set log 1; set axis yaxis } 162 184 default { 163 error "bad option \"$which\": should be x, xlin, xlog, y, ylin, ylog" 164 } 165 } 166 if {"" == $vname} { 167 return {0 1} 168 } 169 $vname dup tmp 170 $vname dup zero 171 if {$log} { 172 # on a log scale, use abs value and ignore 0's 173 zero expr {tmp == 0} ;# find the 0's 174 tmp expr {abs(tmp)} ;# get the abs value 175 tmp expr {tmp + zero*max(tmp)} ;# replace 0's with abs max 176 set vmin [blt::vector expr min(tmp)] 177 set vmax [blt::vector expr max(tmp)] 178 } else { 179 set vmin [blt::vector expr min($vname)] 180 set vmax [blt::vector expr max($vname)] 181 } 182 183 if {"" == $min} { 184 set min $vmin 185 } elseif {$vmin < $min} { 186 set min $vmin 187 } 188 if {"" == $max} { 189 set max $vmax 190 } elseif {$vmax > $max} { 191 set max $vmax 185 error "bad option \"$which\": should be x, xlin, xlog, y, ylin, ylog, v, vlin, vlog" 186 } 187 } 188 189 blt::vector create tmp 190 blt::vector create zero 191 foreach comp [array names _comphist] { 192 set vname [lindex $_comp2hist($comp) $pos] 193 $vname variable vec 194 195 if {$log} { 196 # on a log scale, use abs value and ignore 0's 197 $vname dup tmp 198 $vname dup zero 199 zero expr {tmp == 0} ;# find the 0's 200 tmp expr {abs(tmp)} ;# get the abs value 201 tmp expr {tmp + zero*max(tmp)} ;# replace 0's with abs max 202 set vmin [blt::vector expr min(tmp)] 203 set vmax [blt::vector expr max(tmp)] 204 } else { 205 set vmin $vec(min) 206 set vmax $vec(max) 207 } 208 209 if {"" == $min} { 210 set min $vmin 211 } elseif {$vmin < $min} { 212 set min $vmin 213 } 214 if {"" == $max} { 215 set max $vmax 216 } elseif {$vmax > $max} { 217 set max $vmax 218 } 192 219 } 193 220 blt::vector destroy tmp zero … … 208 235 } 209 236 } 210 211 237 return [list $min $max] 212 238 } … … 271 297 272 298 # ---------------------------------------------------------------------- 273 # USAGE: _build299 # USAGE: Build 274 300 # 275 301 # Used internally to build up the vector representation for the … … 278 304 # from scratch. 279 305 # ---------------------------------------------------------------------- 280 itcl::body Rappture::Histogram:: _build {} {306 itcl::body Rappture::Histogram::Build {} { 281 307 # discard any existing data 282 if { $_locations != "" } { 283 blt::vector destroy $_locations 284 set _locations "" 285 } 286 if { $_widths != "" } { 287 blt::vector destroy $_widths 288 set _widths "" 289 } 290 if { $_heights != "" } { 291 blt::vector destroy $_heights 292 set _heights "" 293 } 294 308 Clear 295 309 # 296 310 # Scan through the components of the histogram and create … … 299 313 # enhancements require more than one component. 300 314 # 301 set xhwdata [$_hist get component.xhw] 302 if {"" != $xhwdata} { 303 set _widths [blt::vector create \#auto] 304 set _heights [blt::vector create \#auto] 305 set _locations [blt::vector create \#auto] 306 307 foreach line [split $xhwdata \n] { 308 set n [scan $line {%s %s %s} x h w] 309 if { $n == 2 } { 310 $_locations append $x 311 $_heights append $h 312 } elseif { $n == 3 } { 313 $_locations append $x 314 $_heights append $h 315 $_widths append $w 316 } 317 } 318 # FIXME: There must be a width specified for each bin location. 319 # If this isn't true, we default to uniform widths 320 # (zero-length _widths vector == uniform). 321 if { [$_locations length] != [$_widths length] } { 322 $_widths set {} 323 } 315 foreach cname [$_hist children -type component] { 316 ParseData $cname 324 317 } 325 318 # Creates lists of x and y marker data. … … 341 334 } 342 335 } 336 337 # 338 # ParseData -- 339 # 340 # Parse the components data representations. The following 341 # elements may be used <xy>, <xhw>, <namevalue>, <xvector>, 342 # <yvector>. Only one element is used for data. 343 # 344 itcl::body Rappture::Histogram::ParseData { comp } { 345 # Create new vectors or discard any existing data 346 set _xvalues($comp) [blt::vector create \#auto] 347 set _yvalues($comp) [blt::vector create \#auto] 348 set _widths($comp) [blt::vector create \#auto] 349 set _xlabels($comp) {} 350 351 set xydata [$_hist get ${comp}.xy] 352 if { $xydata != "" } { 353 set count 0 354 foreach line [split $xydata \n] { 355 foreach {name value} $line break 356 $_yvalues($comp) append $value 357 $_xvalues($comp) append $count 358 lappend _xlabels($comp) $name 359 incr count 360 } 361 set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)] 362 return 363 } 364 set xhwdata [$_hist get ${comp}.xhw] 365 if { $xhwdata != "" } { 366 set count 0 367 foreach line [split $xhwdata \n] { 368 set n [scan $line {%s %s %s} name h w] 369 lappend _xlabels($comp) $name 370 $_xvalues($comp) append $count 371 $_yvalues($comp) append $h 372 if { $n == 3 } { 373 $_widths($comp) append $w 374 } 375 incr count 376 } 377 set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)] 378 return 379 380 # FIXME: There must be a width specified for each bin location. 381 # If this isn't true, we default to uniform widths 382 # (zero-length _widths vector == uniform). 383 if { [$_xvalues($comp) length] != [$_widths($comp) length] } { 384 $_widths($comp) set {} 385 } 386 set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)] 387 return 388 } 389 set xv [$_hist get $comp.xvector] 390 set yv [$_hist get $comp.yvector] 391 if { $xv != "" && $yv != "" } { 392 $_yvalues($comp) set $yv 393 $_xvalues($comp) seq 0 [$yv length] 394 set _xlabels($comp) 395 } 396 set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)] 397 } 398 399 itcl::body Rappture::Histogram::Clear { {comp ""} } { 400 if { $comp == "" } { 401 foreach name [array names _widths] { 402 blt::vector destroy $_widths($name) 403 } 404 array unset _widths 405 foreach name [array names _yvalues] { 406 blt::vector destroy $_yvalues($name) 407 } 408 array unset _yvalues 409 foreach name [array names _xvalues] { 410 blt::vector destroy $_xvalues($name) 411 } 412 array unset _xvalues 413 array unset _xlabels 414 array unset _comp2hist 415 return 416 } 417 if { [info exists _widths($comp)] } { 418 blt::vector destroy $_widths($comp) 419 } 420 if { [info exists _yvalues($comp)] } { 421 blt::vector destroy $_yvalues($comp) 422 } 423 if { [info exists _xvalues($comp)] } { 424 blt::vector destroy $_xvalues($comp) 425 } 426 array unset _xvalues $comp 427 array unset _yvalues $comp 428 array unset _widths $comp 429 array unset _xlabels $comp 430 array unset _comp2hist $comp 431 } 432 -
trunk/gui/scripts/histogramresult.tcl
r2255 r2388 18 18 option add *HistogramResult*Element.borderWidth 1 widgetDefault 19 19 option add *HistogramResult*Element.relief solid widgetDefault 20 option add *HistogramResult*x.loose 1widgetDefault20 option add *HistogramResult*x.loose 0 widgetDefault 21 21 option add *HistogramResult*y.loose 1 widgetDefault 22 22 option add *HistogramResult*Element.relief solid widgetDefault 23 23 option add *HistogramResult*Element.borderWidth 1 widgetDefault 24 24 # Don't let the step size default to 1.0 (for barcharts) 25 option add *HistogramResult*x.stepSize 0.0 widgetDefault 25 option add *HistogramResult*x.stepSize 1.0 widgetDefault 26 option add *HistogramResult*x.subdivisions 0 widgetDefault 26 27 27 28 option add *HistogramResult.width 3i widgetDefault 28 29 option add *HistogramResult.height 3i widgetDefault 29 30 option add *HistogramResult.gridColor #d9d9d9 widgetDefault 30 option add *HistogramResult.activeColor blue widgetDefault31 option add *HistogramResult.activeColor blue2 widgetDefault 31 32 option add *HistogramResult.dimColor gray widgetDefault 32 33 option add *HistogramResult.controlBackground gray widgetDefault 33 34 option add *HistogramResult.font \ 34 35 -*-helvetica-medium-r-normal-*-12-* widgetDefault 35 36 option add *HistogramResult.autoColors {37 #0000ff #ff0000 #00cc0038 #cc00cc #ff9900 #cccc0039 #000080 #800000 #00660040 #660066 #996600 #66660041 }42 set autocolors {43 #0000cd44 #cd000045 #00cd0046 #3a5fcd47 #cdcd0048 #cd107649 #009acd50 #00c5cd51 #a2b5cd52 #7ac5cd53 #66cdaa54 #a2cd5a55 #cd9b9b56 #cdba9657 #cd333358 #cd660059 #cd8c9560 #cd00cd61 #9a32cd62 #6ca6cd63 #9ac0cd64 #9bcd9b65 #00cd6666 #cdc67367 #cdad0068 #cd555569 #cd853f70 #cd705471 #cd5b4572 #cd688973 #cd69c974 #551a8b75 }76 77 option add *HistogramResult.autoColors $autocolors widgetDefault78 36 option add *HistogramResult*Balloon*Entry.background white widgetDefault 37 38 option add *HistogramResult*autoColors { 39 #3a5fcd 40 #cdcd00 41 #cd1076 42 #0000cd 43 #cd0000 44 #00cd00 45 #009acd 46 #00c5cd 47 #a2b5cd 48 #7ac5cd 49 #66cdaa 50 #a2cd5a 51 #cd9b9b 52 #cdba96 53 #cd3333 54 #cd6600 55 #cd8c95 56 #cd00cd 57 #9a32cd 58 #6ca6cd 59 #9ac0cd 60 #9bcd9b 61 #00cd66 62 #cdc673 63 #cdad00 64 #cd5555 65 #cd853f 66 #cd7054 67 #cd5b45 68 #cd6889 69 #cd69c9 70 #551a8b 71 } widgetDefault 79 72 80 73 itcl::class Rappture::HistogramResult { … … 101 94 public method download {option args} 102 95 103 protected method _rebuild {} 104 protected method _resetLimits {} 105 protected method _zoom {option args} 106 protected method _hilite {state x y} 107 protected method _axis {option args} 108 protected method _getAxes {dataobj} 109 protected method _getLineMarkerOptions { style } 110 protected method _getTextMarkerOptions { style } 111 protected method _enterMarker { g name x y text } 112 protected method _leaveMarker { g name } 96 protected method Rebuild {} 97 protected method ResetLimits {} 98 protected method Zoom {option args} 99 protected method Hilite {state x y} 100 protected method Axis {option args} 101 protected method GetAxes {dataobj} 102 protected method GetLineMarkerOptions { style } 103 protected method GetTextMarkerOptions { style } 104 protected method EnterMarker { g name x y text } 105 protected method LeaveMarker { g name } 106 protected method FormatLabels { g value } 113 107 114 108 private variable _dispatcher "" ;# dispatcher for !events … … 129 123 common _downloadPopup ;# download options from popup 130 124 private variable _markers 125 private variable _xlabels 131 126 } 132 127 … … 141 136 Rappture::dispatcher _dispatcher 142 137 $_dispatcher register !rebuild 143 $_dispatcher dispatch $this !rebuild "[itcl::code $this _rebuild]; list"138 $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list" 144 139 145 140 array set _downloadPopup { … … 160 155 -highlightthickness 0 \ 161 156 -image [Rappture::icon reset-view] \ 162 -command [itcl::code $this _zoom reset]157 -command [itcl::code $this Zoom reset] 163 158 } { 164 159 usual … … 183 178 # Add bindings so you can mouse over points to see values: 184 179 # 185 bind $itk_component(plot) <Motion> \ 186 [itcl::code $this _hilite at %x %y] 187 bind $itk_component(plot) <Leave> \ 188 [itcl::code $this _hilite off %x %y] 180 $itk_component(plot) element bind all <Enter> \ 181 [itcl::code $this Hilite at %x %y] 182 $itk_component(plot) element bind all <Motion> \ 183 [itcl::code $this Hilite at %x %y] 184 $itk_component(plot) element bind all <Leave> \ 185 [itcl::code $this Hilite off %x %y] 189 186 190 187 # Add support for editing axes: … … 237 234 set _axisPopup(format-$axis) "%.6g" 238 235 } 239 _axis scale x linear240 _axis scale y linear236 Axis scale x linear 237 Axis scale y linear 241 238 242 239 $itk_component(plot) legend configure -hide yes … … 357 354 itcl::body Rappture::HistogramResult::get {} { 358 355 # put the dataobj list in order according to -raise options 359 set clist $_dlist 360 foreach obj $clist { 356 set bottom {} 357 set top {} 358 foreach obj $_dlist { 361 359 if {[info exists _dataobj2raise($obj)] && $_dataobj2raise($obj)} { 362 set i [lsearch -exact $clist $obj] 363 if {$i >= 0} { 364 set clist [lreplace $clist $i $i] 365 lappend clist $obj 366 } 367 } 368 } 369 return $clist 360 lappend top $obj 361 } else { 362 lappend bottom $obj 363 } 364 } 365 set _dlist [concat $bottom $top] 366 return $_dlist 370 367 } 371 368 … … 424 421 lappend allx x ;# fix main x-axis too 425 422 foreach axis $allx { 426 _axis scale $axis linear423 Axis scale $axis linear 427 424 } 428 425 … … 430 427 lappend ally y ;# fix main y-axis too 431 428 foreach axis $ally { 432 _axis scale $axis linear429 Axis scale $axis linear 433 430 } 434 431 … … 436 433 foreach dataobj $args { 437 434 # find the axes for this dataobj (e.g., {x y2}) 438 foreach {map(x) map(y)} [ _getAxes $dataobj] break435 foreach {map(x) map(y)} [GetAxes $dataobj] break 439 436 440 437 foreach axis {x y} { … … 460 457 461 458 if {[$dataobj hints ${axis}scale] == "log"} { 462 _axis scale $map($axis) log463 } 464 } 465 } 466 _resetLimits459 Axis scale $map($axis) log 460 } 461 } 462 } 463 ResetLimits 467 464 } 468 465 … … 590 587 591 588 # ---------------------------------------------------------------------- 592 # USAGE: _rebuild589 # USAGE: Rebuild 593 590 # 594 591 # Called automatically whenever something changes that affects the … … 596 593 # widget to display new data. 597 594 # ---------------------------------------------------------------------- 598 itcl::body Rappture::HistogramResult:: _rebuild {} {595 itcl::body Rappture::HistogramResult::Rebuild {} { 599 596 set g $itk_component(plot) 600 597 … … 664 661 foreach axis $all { 665 662 set _axisPopup(format-$axis) "%.6g" 666 667 663 $g axis bind $axis <Enter> \ 668 [itcl::code $this _axis hilite $axis on]664 [itcl::code $this Axis hilite $axis on] 669 665 $g axis bind $axis <Leave> \ 670 [itcl::code $this _axis hilite $axis off]666 [itcl::code $this Axis hilite $axis off] 671 667 $g axis bind $axis <ButtonPress-1> \ 672 [itcl::code $this _axis click $axis %x %y]668 [itcl::code $this Axis click $axis %x %y] 673 669 $g axis bind $axis <B1-Motion> \ 674 [itcl::code $this _axis drag $axis %x %y]670 [itcl::code $this Axis drag $axis %x %y] 675 671 $g axis bind $axis <ButtonRelease-1> \ 676 [itcl::code $this _axis release $axis %x %y]672 [itcl::code $this Axis release $axis %x %y] 677 673 $g axis bind $axis <KeyPress> \ 678 674 [list ::Rappture::Tooltip::tooltip cancel] 679 675 } 680 676 set invert 0 677 array unset _xlabels 681 678 # 682 679 # Plot all of the dataobjs. … … 685 682 foreach dataobj $_dlist { 686 683 set label [$dataobj hints label] 687 foreach {mapx mapy} [_getAxes $dataobj] break 688 689 set xv [$dataobj locations] 690 set yv [$dataobj heights] 691 set zv [$dataobj widths] 692 if {$xv eq "" || $yv eq "" || $zv eq ""} { 693 continue 694 } 695 696 if {[info exists _dataobj2color($dataobj)]} { 697 set color $_dataobj2color($dataobj) 698 } else { 699 set color [$dataobj hints color] 700 if {"" == $color} { 701 set color black 702 } 703 } 704 705 if {[info exists _dataobj2width($dataobj)]} { 706 set lwidth $_dataobj2width($dataobj) 707 } else { 708 set lwidth 2 709 } 710 711 if {[info exists _dataobj2dashes($dataobj)]} { 712 set dashes $_dataobj2dashes($dataobj) 713 } else { 714 set dashes "" 715 } 716 if {([$xv length] <= 1) || ($lwidth == 0)} { 717 set sym square 718 set pixels 2 719 } else { 720 set sym "" 721 set pixels 6 722 } 723 # Compute default bar width for histogram elements. 724 if { [$zv length] == [$xv length] } { 725 foreach x [$xv range 0 end] \ 726 y [$yv range 0 end] \ 727 z [$zv range 0 end] { 728 set elem "elem[incr count]" 729 set _elem2dataobj($elem) $dataobj 730 $g element create $elem -x $x -y $y -barwidth $z \ 684 foreach {mapx mapy} [GetAxes $dataobj] break 685 foreach comp [$dataobj components] { 686 set xv [$dataobj mesh $comp] 687 set yv [$dataobj values $comp] 688 set zv [$dataobj widths $comp] 689 if {$xv eq "" || $yv eq "" || $zv eq ""} { 690 continue 691 } 692 if {[info exists _dataobj2color($dataobj)]} { 693 set color $_dataobj2color($dataobj) 694 } else { 695 set color [$dataobj hints color] 696 if {"" == $color} { 697 set color black 698 } 699 } 700 if {[info exists _dataobj2width($dataobj)]} { 701 set lwidth $_dataobj2width($dataobj) 702 } else { 703 set lwidth 2 704 } 705 if {[info exists _dataobj2dashes($dataobj)]} { 706 set dashes $_dataobj2dashes($dataobj) 707 } else { 708 set dashes "" 709 } 710 if {([$xv length] <= 1) || ($lwidth == 0)} { 711 set sym square 712 set pixels 2 713 } else { 714 set sym "" 715 set pixels 6 716 } 717 # Compute default bar width for histogram elements. 718 if { [$zv length] == [$xv length] } { 719 foreach x [$xv values] y [$yv values] z [$zv values] { 720 set elem "elem[incr count]" 721 set _elem2dataobj($elem) $dataobj 722 $g element create $elem -x $x -y $y -barwidth $z \ 723 -label $label -foreground $color \ 724 -mapx $mapx -mapy $mapy 725 } 726 } else { 727 set r [blt::vector expr {max($xv) - min($xv)}] 728 set z [expr {$r / ([$xv length]-1) * 0.8}] 729 set elem "elem[incr count]" 730 set _elem2dataobj($elem) $dataobj 731 $g element create $elem -x $xv -y $yv -barwidth $z \ 731 732 -label $label -foreground $color \ 732 733 -mapx $mapx -mapy $mapy 733 } 734 } else { 735 set r [blt::vector expr {max($xv) - min($xv)}] 736 set z [expr {$r / ([$xv length]-1) * 0.8}] 737 set elem "elem[incr count]" 738 set _elem2dataobj($elem) $dataobj 739 $g element create $elem -x $xv -y $yv -barwidth $z \ 740 -label $label -foreground $color \ 741 -mapx $mapx -mapy $mapy 742 } 734 } 735 set index 0 736 foreach label [$dataobj xlabels $comp] { 737 if { [string length $label] > 3 } { 738 set invert 1 739 } 740 set _xlabels($index) $label 741 incr index 742 } 743 } 743 744 } 744 745 foreach dataobj $_dlist { 745 746 747 748 749 750 746 set xmin -Inf 747 set ymin -Inf 748 set xmax Inf 749 set ymax Inf 750 # 751 # Create text/line markers for each *axis.marker specified. 751 752 # 752 753 foreach m [$dataobj xmarkers] { … … 754 755 set id [$g marker create line -coords [list $at $ymin $at $ymax]] 755 756 $g marker bind $id <Enter> \ 756 [itcl::code $this _enterMarker $g x-$label $at $ymin $at]757 [itcl::code $this EnterMarker $g x-$label $at $ymin $at] 757 758 $g marker bind $id <Leave> \ 758 [itcl::code $this _leaveMarker $g x-$label]759 set options [ _getLineMarkerOptions $style]759 [itcl::code $this LeaveMarker $g x-$label] 760 set options [GetLineMarkerOptions $style] 760 761 if { $options != "" } { 761 762 eval $g marker configure $id $options … … 764 765 set id [$g marker create text -anchor nw \ 765 766 -text $label -coords [list $at $ymax]] 766 set options [ _getTextMarkerOptions $style]767 set options [GetTextMarkerOptions $style] 767 768 if { $options != "" } { 768 769 eval $g marker configure $id $options … … 774 775 set id [$g marker create line -coords [list $xmin $at $xmax $at]] 775 776 $g marker bind $id <Enter> \ 776 [itcl::code $this _enterMarker $g y-$label $at $xmin $at]777 [itcl::code $this EnterMarker $g y-$label $at $xmin $at] 777 778 $g marker bind $id <Leave> \ 778 [itcl::code $this _leaveMarker $g y-$label]779 set options [ _getLineMarkerOptions $style]779 [itcl::code $this LeaveMarker $g y-$label] 780 set options [GetLineMarkerOptions $style] 780 781 if { $options != "" } { 781 782 eval $g marker configure $id $options … … 784 785 set id [$g marker create text -anchor se \ 785 786 -text $label -coords [list $xmax $at]] 786 set options [ _getTextMarkerOptions $style]787 set options [GetTextMarkerOptions $style] 787 788 if { $options != "" } { 788 789 eval $g marker configure $id $options … … 791 792 } 792 793 } 794 if { [array size _xlabels] > 0 } { 795 set command [itcl::code $this FormatLabels] 796 } else { 797 set command "" 798 } 799 $g axis configure x -command $command 800 $g configure -invertxy $invert 793 801 $itk_component(legend) reset 794 802 } 795 803 796 804 # ---------------------------------------------------------------------- 797 # USAGE: _resetLimits805 # USAGE: ResetLimits 798 806 # 799 807 # Used internally to apply automatic limits to the axes for the 800 808 # current plot. 801 809 # ---------------------------------------------------------------------- 802 itcl::body Rappture::HistogramResult:: _resetLimits {} {810 itcl::body Rappture::HistogramResult::ResetLimits {} { 803 811 set g $itk_component(plot) 804 812 … … 870 878 871 879 # ---------------------------------------------------------------------- 872 # USAGE: _zoom reset880 # USAGE: Zoom reset 873 881 # 874 882 # Called automatically when the user clicks on one of the zoom 875 883 # controls for this widget. Changes the zoom for the current view. 876 884 # ---------------------------------------------------------------------- 877 itcl::body Rappture::HistogramResult:: _zoom {option args} {885 itcl::body Rappture::HistogramResult::Zoom {option args} { 878 886 switch -- $option { 879 887 reset { 880 _resetLimits881 } 882 } 883 } 884 885 # ---------------------------------------------------------------------- 886 # USAGE: _hilite <state> <x> <y>888 ResetLimits 889 } 890 } 891 } 892 893 # ---------------------------------------------------------------------- 894 # USAGE: Hilite <state> <x> <y> 887 895 # 888 896 # Called automatically when the user brushes one of the elements … … 890 898 # pop up with element info. 891 899 # ---------------------------------------------------------------------- 892 itcl::body Rappture::HistogramResult:: _hilite {state x y} {900 itcl::body Rappture::HistogramResult::Hilite {state x y} { 893 901 set g $itk_component(plot) 894 902 set elem "" … … 900 908 } 901 909 set tip "" 910 set index "" 902 911 if {$state == "at"} { 903 set bool [$g element closest $x $y info -interpolate yes] 912 set bool [$g element closest $x $y info -along y -halo 1] 913 # Must be in the element. 904 914 if { $bool } { 905 915 # for dealing with xy line plots … … 911 921 set mapy [$g element cget $elem -mapy] 912 922 if {[info exists _elem2dataobj($elem)]} { 913 foreach {mapx mapy} [ _getAxes $_elem2dataobj($elem)] break923 foreach {mapx mapy} [GetAxes $_elem2dataobj($elem)] break 914 924 } 915 925 916 926 # search again for an exact point -- this time don't interpolate 917 927 set tip "" 918 array unset info 919 set bool [$g element closest $x $y info -interpolate no] 920 if { $bool && $info(name) == $elem} { 928 if { $info(name) == $elem} { 921 929 set x [$g axis transform $mapx $info(x)] 922 930 set y [$g axis transform $mapy $info(y)] 923 931 if { [$g cget -invertxy] } { 932 set tmp $x 933 set x $y 934 set y $tmp 935 } 924 936 if {[info exists _elem2dataobj($elem)]} { 925 937 set dataobj $_elem2dataobj($elem) … … 931 943 } 932 944 set tip [$g element cget $elem -label] 933 set yval [ _axis format y dummy $info(y)]945 set yval [Axis format y dummy $info(y)] 934 946 append tip "\n$yval$yunits" 935 set xval [ _axis format x dummy $info(x)]947 set xval [Axis format x dummy $info(x)] 936 948 append tip " @ $xval$xunits" 937 949 set tip [string trim $tip] 950 set index $info(index) 938 951 } 939 952 set state 1 940 953 } else { 941 set bool [$g element closest $x $y info -interpolate no ]954 set bool [$g element closest $x $y info -interpolate no -along y] 942 955 if { $bool } { 943 956 # for dealing with xy scatter plot … … 948 961 set mapy [$g element cget $elem -mapy] 949 962 if {[info exists _elem2dataobj($elem)]} { 950 foreach {mapx mapy} [ _getAxes $_elem2dataobj($elem)] break963 foreach {mapx mapy} [GetAxes $_elem2dataobj($elem)] break 951 964 } 952 965 set tip "" 953 966 set x [$g axis transform $mapx $info(x)] 954 967 set y [$g axis transform $mapy $info(y)] 955 968 if { [$g cget -invertxy] } { 969 set tmp $x 970 set x $y 971 set y $tmp 972 } 956 973 if {[info exists _elem2dataobj($elem)]} { 957 974 set dataobj $_elem2dataobj($elem) … … 963 980 } 964 981 set tip [$g element cget $elem -label] 965 set yval [ _axis format y dummy $info(y)]982 set yval [Axis format y dummy $info(y)] 966 983 append tip "\n$yval$yunits" 967 set xval [ _axis format x dummy $info(x)]984 set xval [Axis format x dummy $info(x)] 968 985 append tip " @ $xval$xunits" 969 986 set tip [string trim $tip] 987 set index $info(index) 970 988 set state 1 971 989 } else { … … 987 1005 Rappture::Tooltip::tooltip cancel 988 1006 } 989 $g element activate $elem 1007 if { $index != "" } { 1008 $g element activate $elem $index 1009 set _hilite(index) $index 1010 } 990 1011 set _hilite(elem) $elem 991 1012 … … 993 1014 set mapy [$g element cget $elem -mapy] 994 1015 if {[info exists _elem2dataobj($elem)]} { 995 foreach {mapx mapy} [ _getAxes $_elem2dataobj($elem)] break1016 foreach {mapx mapy} [GetAxes $_elem2dataobj($elem)] break 996 1017 } 997 1018 set allx [$g x2axis use] … … 1029 1050 set tipx "-0" 1030 1051 } else { 1031 set tipx "-[expr {$x- 4}]" ;# move tooltip to the left1052 set tipx "-[expr {$x-20}]" ;# move tooltip to the left 1032 1053 } 1033 1054 } else { … … 1035 1056 set tipx "+0" 1036 1057 } else { 1037 set tipx "+[expr {$x+ 4}]" ;# move tooltip to the right1058 set tipx "+[expr {$x+20}]" ;# move tooltip to the right 1038 1059 } 1039 1060 } … … 1042 1063 set tipy "-0" 1043 1064 } else { 1044 set tipy "-[expr {$y- 4}]" ;# move tooltip to the top1065 set tipy "-[expr {$y-20}]" ;# move tooltip to the top 1045 1066 } 1046 1067 } else { … … 1048 1069 set tipy "+0" 1049 1070 } else { 1050 set tipy "+[expr {$y+ 4}]" ;# move tooltip to the bottom1071 set tipy "+[expr {$y+20}]" ;# move tooltip to the bottom 1051 1072 } 1052 1073 } … … 1095 1116 1096 1117 # ---------------------------------------------------------------------- 1097 # USAGE: _axis hilite <axis> <state>1118 # USAGE: Axis hilite <axis> <state> 1098 1119 # 1099 # USAGE: _axis click <axis> <x> <y>1100 # USAGE: _axis drag <axis> <x> <y>1101 # USAGE: _axis release <axis> <x> <y>1120 # USAGE: Axis click <axis> <x> <y> 1121 # USAGE: Axis drag <axis> <x> <y> 1122 # USAGE: Axis release <axis> <x> <y> 1102 1123 # 1103 # USAGE: _axis edit <axis>1104 # USAGE: _axis changed <axis> <what>1105 # USAGE: _axis format <axis> <widget> <value>1106 # USAGE: _axis scale <axis> linear|log1124 # USAGE: Axis edit <axis> 1125 # USAGE: Axis changed <axis> <what> 1126 # USAGE: Axis format <axis> <widget> <value> 1127 # USAGE: Axis scale <axis> linear|log 1107 1128 # 1108 1129 # Used internally to handle editing of the x/y axes. The hilite … … 1111 1132 # changes from the panel. 1112 1133 # ---------------------------------------------------------------------- 1113 itcl::body Rappture::HistogramResult:: _axis {option args} {1134 itcl::body Rappture::HistogramResult::Axis {option args} { 1114 1135 set inner [$itk_component(hull).axes component inner] 1115 1136 … … 1117 1138 hilite { 1118 1139 if {[llength $args] != 2} { 1119 error "wrong # args: should be \" _axis hilite axis state\""1140 error "wrong # args: should be \"Axis hilite axis state\"" 1120 1141 } 1121 1142 set g $itk_component(plot) … … 1127 1148 -color $itk_option(-activecolor) \ 1128 1149 -titlecolor $itk_option(-activecolor) 1129 1130 1150 set x [expr {[winfo pointerx $g]+4}] 1131 1151 set y [expr {[winfo pointery $g]+4}] … … 1140 1160 click { 1141 1161 if {[llength $args] != 3} { 1142 error "wrong # args: should be \"_axis click axis x y\"" 1143 } 1144 set axis [lindex $args 0] 1145 set x [lindex $args 1] 1146 set y [lindex $args 2] 1162 error "wrong # args: should be \"Axis click axis x y\"" 1163 } 1164 foreach { axis x y } $args break 1147 1165 set g $itk_component(plot) 1166 if { [$g cget -invertxy] } { 1167 set tmp $x 1168 set x $y 1169 set y $tmp 1170 } 1148 1171 1149 1172 set _axis(moved) 0 … … 1157 1180 drag { 1158 1181 if {[llength $args] != 3} { 1159 error "wrong # args: should be \" _axis drag axis x y\""1182 error "wrong # args: should be \"Axis drag axis x y\"" 1160 1183 } 1161 1184 if {![info exists _axis(moved)]} { 1162 1185 return ;# must have skipped click event -- ignore 1163 1186 } 1164 set axis [lindex $args 0] 1165 set x [lindex $args 1] 1166 set y [lindex $args 2] 1187 foreach { axis x y } $args break 1167 1188 set g $itk_component(plot) 1189 if { [$g cget -invertxy] } { 1190 set tmp $x 1191 set x $y 1192 set y $tmp 1193 } 1168 1194 1169 1195 if {[info exists _axis(click-x)] && [info exists _axis(click-y)]} { … … 1215 1241 release { 1216 1242 if {[llength $args] != 3} { 1217 error "wrong # args: should be \" _axis release axis x y\""1243 error "wrong # args: should be \"Axis release axis x y\"" 1218 1244 } 1219 1245 if {![info exists _axis(moved)]} { 1220 1246 return ;# must have skipped click event -- ignore 1221 1247 } 1222 set axis [lindex $args 0] 1223 set x [lindex $args 1] 1224 set y [lindex $args 2] 1248 foreach { axis x y } $args break 1249 set g $itk_component(plot) 1250 if { [$g cget -invertxy] } { 1251 set tmp $x 1252 set x $y 1253 set y $tmp 1254 } 1225 1255 1226 1256 if {!$_axis(moved)} { … … 1229 1259 set dy [expr {abs($y-$_axis(click-y))}] 1230 1260 if {$dx < 2 && $dy < 2} { 1231 _axis edit $axis1261 Axis edit $axis 1232 1262 } 1233 1263 } else { 1234 1264 # one last movement 1235 _axis drag $axis $x $y1265 Axis drag $axis $x $y 1236 1266 } 1237 1267 catch {unset _axis} … … 1239 1269 edit { 1240 1270 if {[llength $args] != 1} { 1241 error "wrong # args: should be \" _axis edit axis\""1271 error "wrong # args: should be \"Axis edit axis\"" 1242 1272 } 1243 1273 set axis [lindex $args 0] … … 1246 1276 # apply last value when deactivating 1247 1277 $itk_component(hull).axes configure -deactivatecommand \ 1248 [itcl::code $this _axis changed $axis focus]1278 [itcl::code $this Axis changed $axis focus] 1249 1279 1250 1280 # fix axis label controls... … … 1253 1283 $inner.label insert end $label 1254 1284 bind $inner.label <KeyPress-Return> \ 1255 [itcl::code $this _axis changed $axis label]1285 [itcl::code $this Axis changed $axis label] 1256 1286 bind $inner.label <FocusOut> \ 1257 [itcl::code $this _axis changed $axis label]1287 [itcl::code $this Axis changed $axis label] 1258 1288 1259 1289 # fix min/max controls... … … 1262 1292 $inner.min insert end $min 1263 1293 bind $inner.min <KeyPress-Return> \ 1264 [itcl::code $this _axis changed $axis min]1294 [itcl::code $this Axis changed $axis min] 1265 1295 bind $inner.min <FocusOut> \ 1266 [itcl::code $this _axis changed $axis min]1296 [itcl::code $this Axis changed $axis min] 1267 1297 1268 1298 $inner.max delete 0 end 1269 1299 $inner.max insert end $max 1270 1300 bind $inner.max <KeyPress-Return> \ 1271 [itcl::code $this _axis changed $axis max]1301 [itcl::code $this Axis changed $axis max] 1272 1302 bind $inner.max <FocusOut> \ 1273 [itcl::code $this _axis changed $axis max]1303 [itcl::code $this Axis changed $axis max] 1274 1304 1275 1305 # fix format control... … … 1280 1310 1281 1311 bind $inner.format <<Value>> \ 1282 [itcl::code $this _axis changed $axis format]1312 [itcl::code $this Axis changed $axis format] 1283 1313 1284 1314 # fix scale control... … … 1291 1321 } 1292 1322 $inner.scales.linear configure \ 1293 -command [itcl::code $this _axis changed $axis scale]1323 -command [itcl::code $this Axis changed $axis scale] 1294 1324 $inner.scales.log configure \ 1295 -command [itcl::code $this _axis changed $axis scale]1325 -command [itcl::code $this Axis changed $axis scale] 1296 1326 1297 1327 # … … 1336 1366 changed { 1337 1367 if {[llength $args] != 2} { 1338 error "wrong # args: should be \" _axis changed axis what\""1368 error "wrong # args: should be \"Axis changed axis what\"" 1339 1369 } 1340 1370 set axis [lindex $args 0] … … 1405 1435 } 1406 1436 scale { 1407 _axis scale $axis $_axisPopup(scale)1437 Axis scale $axis $_axisPopup(scale) 1408 1438 1409 1439 if {$_axisPopup(scale) == "log"} { … … 1426 1456 format { 1427 1457 if {[llength $args] != 3} { 1428 error "wrong # args: should be \" _axis format axis widget value\""1458 error "wrong # args: should be \"Axis format axis widget value\"" 1429 1459 } 1430 1460 set axis [lindex $args 0] 1431 1461 set value [lindex $args 2] 1432 1462 if { $axis == "x" } { 1463 return [FormatLabels $itk_component(plot) $value] 1464 } 1433 1465 if {[$itk_component(plot) axis cget $axis -logscale]} { 1434 1466 set fmt "%.6g" … … 1440 1472 scale { 1441 1473 if {[llength $args] != 2} { 1442 error "wrong # args: should be \" _axis scale axis type\""1474 error "wrong # args: should be \"Axis scale axis type\"" 1443 1475 } 1444 1476 set axis [lindex $args 0] … … 1453 1485 # use special formatting for linear mode 1454 1486 $itk_component(plot) axis configure $axis -command \ 1455 [itcl::code $this _axis format $axis]1487 [itcl::code $this Axis format $axis] 1456 1488 } 1457 1489 } … … 1463 1495 1464 1496 # ---------------------------------------------------------------------- 1465 # USAGE: _getLineMarkerOptions <style>1497 # USAGE: GetLineMarkerOptions <style> 1466 1498 # 1467 1499 # Used internally to create a list of configuration options specific to the … … 1469 1501 # are not recognized are ignored. 1470 1502 # ---------------------------------------------------------------------- 1471 itcl::body Rappture::HistogramResult:: _getLineMarkerOptions {style} {1503 itcl::body Rappture::HistogramResult::GetLineMarkerOptions {style} { 1472 1504 array set lineOptions { 1473 1505 "-color" "-outline" … … 1486 1518 1487 1519 # ---------------------------------------------------------------------- 1488 # USAGE: _getTextMarkerOptions <style>1520 # USAGE: GetTextMarkerOptions <style> 1489 1521 # 1490 1522 # Used internally to create a list of configuration options specific to the … … 1492 1524 # are not recognized are ignored. 1493 1525 # ---------------------------------------------------------------------- 1494 itcl::body Rappture::HistogramResult:: _getTextMarkerOptions {style} {1526 itcl::body Rappture::HistogramResult::GetTextMarkerOptions {style} { 1495 1527 array set textOptions { 1496 1528 "-color" "-outline" … … 1512 1544 1513 1545 # ---------------------------------------------------------------------- 1514 # USAGE: _getAxes <dataobj>1546 # USAGE: GetAxes <dataobj> 1515 1547 # 1516 1548 # Used internally to figure out the axes used to plot the given … … 1518 1550 # x-axis name (x, x2, x3, etc.), and y is the y-axis name. 1519 1551 # ---------------------------------------------------------------------- 1520 itcl::body Rappture::HistogramResult:: _getAxes {dataobj} {1552 itcl::body Rappture::HistogramResult::GetAxes {dataobj} { 1521 1553 # rebuild if needed, so we know about the axes 1522 1554 if {[$_dispatcher ispending !rebuild]} { … … 1570 1602 } 1571 1603 1572 itcl::body Rappture::HistogramResult:: _enterMarker { g name x y text } {1573 _leaveMarker $g $name1604 itcl::body Rappture::HistogramResult::EnterMarker { g name x y text } { 1605 LeaveMarker $g $name 1574 1606 set id [$g marker create text \ 1575 1607 -coords [list $x $y] \ … … 1579 1611 } 1580 1612 1581 itcl::body Rappture::HistogramResult:: _leaveMarker { g name } {1613 itcl::body Rappture::HistogramResult::LeaveMarker { g name } { 1582 1614 if { [info exists _markers($name)] } { 1583 1615 set id $_markers($name) … … 1586 1618 } 1587 1619 } 1620 1621 1622 itcl::body Rappture::HistogramResult::FormatLabels { w value } { 1623 # Determine the element name from the value 1624 set index [expr round($value)] 1625 if { [info exists _xlabels($index)] } { 1626 return $_xlabels($index) 1627 } 1628 return " " 1629 } -
trunk/gui/scripts/xyresult.tcl
r2243 r2388 170 170 -outline black -fill red -color black 171 171 172 # 172 173 # Add bindings so you can mouse over points to see values: 173 bind $itk_component(plot) <Motion> \ 174 # 175 $itk_component(plot) element bind all <Enter> \ 174 176 [itcl::code $this Hilite at %x %y] 175 bind $itk_component(plot) <Leave> \ 177 $itk_component(plot) element bind all <Motion> \ 178 [itcl::code $this Hilite at %x %y] 179 $itk_component(plot) element bind all <Leave> \ 176 180 [itcl::code $this Hilite off %x %y] 177 181
Note: See TracChangeset
for help on using the changeset viewer.