Changeset 5560 for branches/1.3
- Timestamp:
- May 19, 2015, 8:15:27 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3/gui/scripts/histogram.tcl
r5559 r5560 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 3 3 # ---------------------------------------------------------------------- 4 4 # COMPONENT: histogram - extracts data from an XML description of a field … … 37 37 protected method Build {} 38 38 private method Clear { {comp ""} } 39 private method ParseData { comp } 39 private method ParseData { comp } 40 40 41 41 private variable _xmlobj "" ;# ref to lib obj with histogram data 42 42 private variable _hist "" ;# lib obj representing this histogram 43 private variable _widths ;# array of vectors of bin widths 44 private variable _yvalues ;# array of vectors of bin heights along 43 private variable _widths ;# array of vectors of bin widths 44 private variable _yvalues ;# array of vectors of bin heights along 45 45 ;# y-axis. 46 private variable _xvalues ;# array of vectors of bin locations along 46 private variable _xvalues ;# array of vectors of bin locations along 47 47 ;# x-axis. 48 48 private variable _xlabels ;# array of labels … … 74 74 # don't destroy the _xmlobj! we don't own it! 75 75 itcl::delete object $_hist 76 Clear 77 } 78 79 # ---------------------------------------------------------------------- 80 # USAGE: mesh 76 Clear 77 } 78 79 # ---------------------------------------------------------------------- 80 # USAGE: mesh 81 81 # 82 82 # Returns the vector for the histogram bin locations along the … … 91 91 92 92 # ---------------------------------------------------------------------- 93 # USAGE: heights 93 # USAGE: heights 94 94 # 95 95 # Returns the vector for the histogram bin heights along the y-axis. … … 103 103 104 104 # ---------------------------------------------------------------------- 105 # USAGE: widths 105 # USAGE: widths 106 106 # 107 107 # Returns the vector for the specified histogram component <name>. … … 117 117 118 118 # ---------------------------------------------------------------------- 119 # USAGE: xlabels 119 # USAGE: xlabels 120 120 # 121 121 # Returns the vector for the specified histogram component <name>. … … 188 188 } 189 189 190 blt::vector create tmp 190 blt::vector create tmp 191 191 blt::vector create zero 192 192 foreach comp [array names _comphist] { … … 257 257 xdesc xaxis.description 258 258 xunits xaxis.units 259 xorient xaxis.orientation 259 xorient xaxis.orientation 260 260 xscale xaxis.scale 261 261 xmin xaxis.min … … 342 342 # Parse the components data representations. The following 343 343 # elements may be used <xy>, <xhw>, <namevalue>, <xvector>, 344 # <yvector>. Only one element is used for data. 344 # <yvector>. Only one element is used for data. 345 345 # 346 346 itcl::body Rappture::Histogram::ParseData { comp } { … … 354 354 if { $xydata != "" } { 355 355 set count 0 356 foreach {name value} [regexp -all -inline {\S+} $xydata] { 357 $_yvalues($comp) append $value 358 $_xvalues($comp) append $count 359 lappend _xlabels($comp) $name 360 incr count 361 } 356 foreach line [split $xydata \n] { 357 if {[llength $line] == 2} { 358 foreach {name value} $line break 359 $_yvalues($comp) append $value 360 $_xvalues($comp) append $count 361 lappend _xlabels($comp) $name 362 incr count 363 } 364 } 362 365 set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)] 363 366 return … … 366 369 if { $xhwdata != "" } { 367 370 set count 0 368 foreach {name h w} [regexp -all -inline {\S+} $xhwdata] { 369 lappend _xlabels($comp) $name 370 $_xvalues($comp) append $count 371 $_yvalues($comp) append $h 372 $_widths($comp) append $w 373 incr count 374 } 371 foreach line [split $xhwdata \n] { 372 set n [scan $line {%s %s %s} name h w] 373 if {$n >= 2} { 374 lappend _xlabels($comp) $name 375 $_xvalues($comp) append $count 376 $_yvalues($comp) append $h 377 if { $n == 3 } { 378 $_widths($comp) append $w 379 } 380 incr count 381 } 382 } 375 383 set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)] 376 384 return 377 } 378 379 # If we reached here, must be <yvector> 380 $_yvalues($comp) set [$_hist get ${comp}.yvector] 381 $_xvalues($comp) length [$_yvalues($comp) length] 382 $_xvalues($comp) seq 1 [$_yvalues($comp) length] 383 set _xlabels($comp) [$_hist get ${comp}.xvector] 385 386 # FIXME: There must be a width specified for each bin location. 387 # If this isn't true, we default to uniform widths 388 # (zero-length _widths vector == uniform). 389 if { [$_xvalues($comp) length] != [$_widths($comp) length] } { 390 $_widths($comp) set {} 391 } 392 set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)] 393 return 394 } 395 set xv [$_hist get $comp.xvector] 396 set yv [$_hist get $comp.yvector] 397 if { $xv != "" && $yv != "" } { 398 $_yvalues($comp) set $yv 399 $_xvalues($comp) seq 0 [$yv length] 400 set _xlabels($comp) 401 } 384 402 set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)] 385 403 } … … 404 422 } 405 423 if { [info exists _widths($comp)] } { 406 blt::vector destroy $_widths($comp) 424 blt::vector destroy $_widths($comp) 407 425 } 408 426 if { [info exists _yvalues($comp)] } { 409 blt::vector destroy $_yvalues($comp) 427 blt::vector destroy $_yvalues($comp) 410 428 } 411 429 if { [info exists _xvalues($comp)] } { 412 blt::vector destroy $_xvalues($comp) 430 blt::vector destroy $_xvalues($comp) 413 431 } 414 432 array unset _xvalues $comp
Note: See TracChangeset
for help on using the changeset viewer.