Changeset 4007


Ignore:
Timestamp:
Oct 9, 2013 9:28:03 PM (9 years ago)
Author:
gah
Message:

add error bars to curve

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.3/gui/scripts/curve.tcl

    r3330 r4007  
    3232
    3333    public method components {{pattern *}}
    34     public method mesh {{what -overall}}
    35     public method values {{what -overall}}
     34    public method mesh {cname }
     35    public method values { cname }
    3636    public method limits {which}
    3737    public method hints {{key ""}}
    3838    public method xmarkers {}
    3939    public method ymarkers {}
     40    public method xErrorValues { cname }
     41    public method yErrorValues { cname}
    4042
    4143    protected method _build {}
    4244
    43     private variable _xmlobj ""  ;# ref to lib obj with curve data
    44     private variable _curve ""   ;# lib obj representing this curve
    45     private variable _comp2xy    ;# maps component name => x,y vectors
    46     private variable _hints      ;# cache of hints stored in XML
    47 
    48     private variable _xmarkers "";# list of {x,label,options} triplets.
    49     private variable _ymarkers "";# list of {y,label,options} triplets.
    50     private common _counter 0    ;# counter for unique vector names
     45    private variable _xmlobj ""  ;      # ref to lib obj with curve data
     46    private variable _curve ""   ;      # lib obj representing this curve
     47    private variable _comp2xy    ;      # maps component name => x,y vectors
     48    private variable _hints      ;      # cache of hints stored in XML
     49
     50    private variable _xmarkers "";      # list of {x,label,options} triplets.
     51    private variable _ymarkers "";      # list of {y,label,options} triplets.
     52    private common _counter 0    ;      # counter for unique vector names
    5153}
    5254
     
    6062    set _xmlobj $xmlobj
    6163    set _curve [$xmlobj element -as object $path]
    62 
    6364    # build up vectors for various components of the curve
    6465    _build
     
    101102# overall curve (sum of all components).
    102103# ----------------------------------------------------------------------
    103 itcl::body Rappture::Curve::mesh {{what -overall}} {
    104     if {[info exists _comp2xy($what)]} {
    105         return [lindex $_comp2xy($what) 0]  ;# return xv
    106     }
    107     error "bad option \"$what\": should be [join [lsort [array names _comp2xy]] {, }]"
     104itcl::body Rappture::Curve::mesh {cname} {
     105    if {[info exists _comp2xy($cname)]} {
     106        return [lindex $_comp2xy($cname) 0]  ;# return xv
     107    }
     108    error "bad component \"$cname\": should be one of [join [lsort [array names _comp2xy]] {, }]"
    108109}
    109110
     
    115116# overall curve (sum of all components).
    116117# ----------------------------------------------------------------------
    117 itcl::body Rappture::Curve::values {{what -overall}} {
    118     if {[info exists _comp2xy($what)]} {
    119         return [lindex $_comp2xy($what) 1]  ;# return yv
    120     }
    121     error "bad option \"$what\": should be [join [lsort [array names _comp2xy]] {, }]"
     118itcl::body Rappture::Curve::values {cname} {
     119    if {[info exists _comp2xy($cname)]} {
     120        return [lindex $_comp2xy($cname) 1]  ;# return yv
     121    }
     122    error "bad component \"$cname\": should be one of [join [lsort [array names _comp2xy]] {, }]"
     123}
     124
     125# ----------------------------------------------------------------------
     126# USAGE: xErrorValues <name>
     127#
     128# Returns the xvec for the specified curve component <name>.
     129# If the name is not specified, then it returns the vectors for the
     130# overall curve (sum of all components).
     131# ----------------------------------------------------------------------
     132itcl::body Rappture::Curve::xErrorValues { cname } {
     133    if {[info exists _comp2xy($cname)]} {
     134        return [lindex $_comp2xy($cname) 2]  ;# return xev
     135    }
     136    error "unknown component \"$cname\": should be one of [join [lsort [array names _comp2xy]] {, }]"
     137}
     138
     139# ----------------------------------------------------------------------
     140# USAGE: yErrorValues <name>
     141#
     142# Returns the xvec for the specified curve component <name>.
     143# If the name is not specified, then it returns the vectors for the
     144# overall curve (sum of all components).
     145# ----------------------------------------------------------------------
     146itcl::body Rappture::Curve::yErrorValues { cname } {
     147    if {[info exists _comp2xy($cname)]} {
     148        return [lindex $_comp2xy($cname) 3]  ;# return yev
     149    }
     150    error "unknown component \"$cname\": should be one of [join [lsort [array names _comp2xy]] {, }]"
    122151}
    123152
     
    272301        set xv [blt::vector create \#auto]
    273302        set yv [blt::vector create \#auto]
     303        set xev [blt::vector create \#auto]
     304        set yev [blt::vector create \#auto]
    274305
    275306        set xydata [$_curve get $cname.xy]
     
    283314            $yv set [$_curve get $cname.yvector]
    284315        }
    285         if { (([$xv length] == 0) && ([$yv length] == 0))
    286             || ([$xv length] != [$yv length]) } {
     316        if { (([$xv length] == 0) && ([$yv length] == 0)) ||
     317            ([$xv length] != [$yv length]) } {
    287318            # FIXME: need to show an error about improper data.
    288319            blt::vector destroy $xv $yv
    289320            set xv ""; set yv ""
    290         } else {
    291             set _comp2xy($cname) [list $xv $yv]
    292             incr _counter
    293         }
    294     }
     321            continue;
     322        }
     323        $xev set [$_curve get "$cname.xerrorbars"]
     324        $yev set [$_curve get "$cname.yerrorbars"]
     325        set _comp2xy($cname) [list $xv $yv $xev $yev]
     326        incr _counter
     327    }
     328
    295329    # Creates lists of x and y marker data.
    296330    set _xmarkers {}
Note: See TracChangeset for help on using the changeset viewer.