Changeset 2300 for branches


Ignore:
Timestamp:
Jul 8, 2011, 6:09:04 PM (13 years ago)
Author:
gah
Message:

add histogram example

File:
1 edited

Legend:

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

    r2297 r2300  
    3535
    3636    protected method Build {}
    37     private method Clear {}
     37    private method Clear { {comp ""} }
    3838    private method ParseData { comp }
    3939
     
    335335}
    336336
     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#
    337344itcl::body Rappture::Histogram::ParseData { comp } {
    338345    # Create new vectors or discard any existing data
     
    344351    set xydata [$_hist get ${comp}.xy]
    345352    if { $xydata != "" } {
     353        # Fast way of parsing x/y pairs.  Set a temporary vector using the
     354        # entire as a list of values (newlines treated as whitespace). 
     355        # Then split the vector into the x and y vectors required.
    346356        set tmp [blt::vector create \#auto]
    347357        $tmp set $xydata
     
    354364    set xhwdata [$_hist get ${comp}.xhw]
    355365    if { $xhwdata != "" } {
     366        # Slow way of parsing x, h, and w values.  The third value is
     367        # optional to can't simply load the values into a vector.
    356368        foreach line [split $xhwdata \n] {
    357369            set n [scan $line {%s %s %s} x h w]
     
    396408}
    397409
    398 itcl::body Rappture::Histogram::Clear {} {
    399     foreach name [array names _widths] {
    400         blt::vector destroy $_widths($name)
    401     }
    402     array unset _widths
    403     foreach name [array names _yvalues] {
    404         blt::vector destroy $_yvalues($name)
    405     }
    406     array unset _yvalues
    407     foreach name [array names _xvalues] {
    408         blt::vector destroy $_xvalues($name)
    409     }
    410     array unset _xvalues
    411     array unset _xlabels
    412     array unset _comp2hist
    413 }
    414 
     410itcl::body Rappture::Histogram::Clear { {comp ""} } {
     411    if { $comp == "" } {
     412        foreach name [array names _widths] {
     413            blt::vector destroy $_widths($name)
     414        }
     415        array unset _widths
     416        foreach name [array names _yvalues] {
     417            blt::vector destroy $_yvalues($name)
     418        }
     419        array unset _yvalues
     420        foreach name [array names _xvalues] {
     421            blt::vector destroy $_xvalues($name)
     422        }
     423        array unset _xvalues
     424        array unset _xlabels
     425        array unset _comp2hist
     426        return
     427    }
     428    if { [info exists _widths($comp)] } {
     429        blt::vector destroy $_widths($comp)
     430    }
     431    if { [info exists _yvalues($comp)] } {
     432        blt::vector destroy $_yvalues($comp)
     433    }
     434    if { [info exists _xvalues($comp)] } {
     435        blt::vector destroy $_xvalues($comp)
     436    }
     437    array unset _xvalues $comp
     438    array unset _yvalues $comp
     439    array unset _widths $comp
     440    array unset _xlabels $comp
     441    array unset _comp2hist $comp
     442}
     443
Note: See TracChangeset for help on using the changeset viewer.