Changeset 5418 for branches


Ignore:
Timestamp:
May 4, 2015 5:22:33 AM (9 years ago)
Author:
mmh
Message:

Fix parsing of xy and xhw data to be more flexible about whitespace and not require newlines. Make xvector and yvector work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/uq/gui/scripts/histogram.tcl

    r3330 r5418  
    1 # -*- mode: tcl; indent-tabs-mode: nil -*- 
    2  
     1# -*- mode: tcl; indent-tabs-mode: nil -*-
     2
    33# ----------------------------------------------------------------------
    44#  COMPONENT: histogram - extracts data from an XML description of a field
     
    3737    protected method Build {}
    3838    private method Clear { {comp ""} }
    39     private method ParseData { comp } 
     39    private method ParseData { comp }
    4040
    4141    private variable _xmlobj ""  ;# ref to lib obj with histogram data
    4242    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
    4545                                 ;# y-axis.
    46     private variable _xvalues    ;# array of vectors of bin locations along 
     46    private variable _xvalues    ;# array of vectors of bin locations along
    4747                                 ;# x-axis.
    4848    private variable _xlabels    ;# array of labels
     
    7474    # don't destroy the _xmlobj! we don't own it!
    7575    itcl::delete object $_hist
    76     Clear 
    77 }
    78 
    79 # ----------------------------------------------------------------------
    80 # USAGE: mesh 
     76    Clear
     77}
     78
     79# ----------------------------------------------------------------------
     80# USAGE: mesh
    8181#
    8282# Returns the vector for the histogram bin locations along the
     
    9191
    9292# ----------------------------------------------------------------------
    93 # USAGE: heights 
     93# USAGE: heights
    9494#
    9595# Returns the vector for the histogram bin heights along the y-axis.
     
    103103
    104104# ----------------------------------------------------------------------
    105 # USAGE: widths 
     105# USAGE: widths
    106106#
    107107# Returns the vector for the specified histogram component <name>.
     
    117117
    118118# ----------------------------------------------------------------------
    119 # USAGE: xlabels 
     119# USAGE: xlabels
    120120#
    121121# Returns the vector for the specified histogram component <name>.
     
    188188    }
    189189
    190     blt::vector create tmp 
     190    blt::vector create tmp
    191191    blt::vector create zero
    192192    foreach comp [array names _comphist] {
     
    257257            xdesc   xaxis.description
    258258            xunits  xaxis.units
    259             xorient xaxis.orientation 
     259            xorient xaxis.orientation
    260260            xscale  xaxis.scale
    261261            xmin    xaxis.min
     
    342342#       Parse the components data representations.  The following
    343343#       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.
    345345#
    346346itcl::body Rappture::Histogram::ParseData { comp } {
     
    354354    if { $xydata != "" } {
    355355        set count 0
    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         }           
     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        }
    365362        set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)]
    366363        return
     
    369366    if { $xhwdata != "" } {
    370367        set count 0
    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         }           
    383         set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)]
    384         return
    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 {}
     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
    391374        }
    392375        set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)]
     
    397380    if { $xv != "" && $yv != "" } {
    398381        $_yvalues($comp) set $yv
    399         $_xvalues($comp) seq 0 [$yv length]
    400         set _xlabels($comp)
     382        $_xvalues($comp) set $xv
    401383    }
    402384    set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)]
     
    422404    }
    423405    if { [info exists _widths($comp)] } {
    424         blt::vector destroy $_widths($comp) 
     406        blt::vector destroy $_widths($comp)
    425407    }
    426408    if { [info exists _yvalues($comp)] } {
    427         blt::vector destroy $_yvalues($comp) 
     409        blt::vector destroy $_yvalues($comp)
    428410    }
    429411    if { [info exists _xvalues($comp)] } {
    430         blt::vector destroy $_xvalues($comp) 
     412        blt::vector destroy $_xvalues($comp)
    431413    }
    432414    array unset _xvalues $comp
Note: See TracChangeset for help on using the changeset viewer.