Changeset 5560 for branches/1.3


Ignore:
Timestamp:
May 19, 2015 8:15:27 AM (9 years ago)
Author:
mmh
Message:

revert histogram changes

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 
    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 {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        }           
    362365        set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)]
    363366        return
     
    366369    if { $xhwdata != "" } {
    367370        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        }           
    375383        set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)]
    376384        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    }
    384402    set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)]
    385403}
     
    404422    }
    405423    if { [info exists _widths($comp)] } {
    406         blt::vector destroy $_widths($comp)
     424        blt::vector destroy $_widths($comp) 
    407425    }
    408426    if { [info exists _yvalues($comp)] } {
    409         blt::vector destroy $_yvalues($comp)
     427        blt::vector destroy $_yvalues($comp) 
    410428    }
    411429    if { [info exists _xvalues($comp)] } {
    412         blt::vector destroy $_xvalues($comp)
     430        blt::vector destroy $_xvalues($comp) 
    413431    }
    414432    array unset _xvalues $comp
Note: See TracChangeset for help on using the changeset viewer.