Changeset 1804 for branches/blt4/gui/scripts/xyresult.tcl
- Timestamp:
- Jul 13, 2010 9:52:29 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/blt4/gui/scripts/xyresult.tcl
r1793 r1804 4 4 # This widget is an X/Y plot, meant to view line graphs produced 5 5 # as output from the run of a Rappture tool. Use the "add" and 6 # "delete" methods to control the curves showing on the plot.6 # "delete" methods to control the dataobjs showing on the plot. 7 7 # ====================================================================== 8 8 # AUTHOR: Michael McLennan, Purdue University … … 76 76 itk_option define -autocolors autoColors AutoColors "" 77 77 78 constructor {args} { # defined below } 79 destructor { # defined below } 80 81 public method add {curve {settings ""}} 78 constructor {args} { 79 # defined below 80 } 81 destructor { 82 # defined below 83 } 84 public method add {dataobj {settings ""}} 82 85 public method get {} 83 86 public method delete {args} 84 87 public method scale {args} 85 88 public method snap { w h } 86 public method parameters {title args} { # do nothing } 89 public method parameters {title args} { 90 # do nothing 91 } 87 92 public method download {option args} 88 93 … … 92 97 protected method _hilite {state x y} 93 98 protected method _axis {option args} 94 protected method _getAxes { curve}99 protected method _getAxes {dataobj} 95 100 protected method _getLineMarkerOptions { style } 96 101 protected method _getTextMarkerOptions { style } … … 99 104 100 105 private variable _dispatcher "" ;# dispatcher for !events 101 private variable _ clist "" ;# list of curveobjects102 private variable _ curve2color ;# maps curve=> plotting color103 private variable _ curve2width ;# maps curve=> line width104 private variable _ curve2dashes ;# maps curve=> BLT -dashes list105 private variable _ curve2raise ;# maps curve=> raise flag 0/1106 private variable _ curve2desc ;# maps curve=> description of data107 private variable _elem2 curve ;# maps graph element => curve106 private variable _dlist "" ;# list of dataobj objects 107 private variable _dataobj2color ;# maps dataobj => plotting color 108 private variable _dataobj2width ;# maps dataobj => line width 109 private variable _dataobj2dashes ;# maps dataobj => BLT -dashes list 110 private variable _dataobj2raise ;# maps dataobj => raise flag 0/1 111 private variable _dataobj2desc ;# maps dataobj => description of data 112 private variable _elem2dataobj ;# maps graph element => dataobj 108 113 private variable _label2axis ;# maps axis label => axis ID 109 114 private variable _limits ;# axis limits: x-min, x-max, etc. … … 115 120 common _downloadPopup ;# download options from popup 116 121 private variable _markers 117 private variable cur_ ""118 private variable initialized_ 0119 122 } 120 123 … … 164 167 itk_component add plot { 165 168 blt::graph $f.plot \ 166 -highlightthickness 0 -plotpadx 0 -plotpady 4 \ 167 -rightmargin 10 169 -highlightthickness 0 -plotpadx 0 -plotpady 4 168 170 } { 169 171 keep -foreground -cursor -font … … 175 177 -outline black -fill red -color black 176 178 177 #178 179 # Add bindings so you can mouse over points to see values: 179 #180 180 bind $itk_component(plot) <Motion> \ 181 181 [itcl::code $this _hilite at %x %y] … … 183 183 [itcl::code $this _hilite off %x %y] 184 184 185 #186 185 # Add support for editing axes: 187 #188 186 Rappture::Balloon $itk_component(hull).axes -title "Axis Options" 189 187 set inner [$itk_component(hull).axes component inner] … … 270 268 271 269 # ---------------------------------------------------------------------- 272 # USAGE: add < curve> ?<settings>?270 # USAGE: add <dataobj> ?<settings>? 273 271 # 274 # Clients use this to add a curveto the plot. The optional <settings>272 # Clients use this to add a dataobj to the plot. The optional <settings> 275 273 # are used to configure the plot. Allowed settings are -color, 276 274 # -brightness, -width, -linestyle and -raise. 277 275 # ---------------------------------------------------------------------- 278 itcl::body Rappture::XyResult::add { curve{settings ""}} {276 itcl::body Rappture::XyResult::add {dataobj {settings ""}} { 279 277 array set params { 280 281 282 283 -type "line"284 285 286 287 278 -color auto 279 -brightness 0 280 -width 1 281 -type "histogram" 282 -raise 0 283 -linestyle solid 284 -description "" 285 -param "" 288 286 } 289 287 foreach {opt val} $settings { … … 337 335 } 338 336 339 set pos [lsearch -exact $ curve $_clist]337 set pos [lsearch -exact $dataobj $_dlist] 340 338 if {$pos < 0} { 341 lappend _ clist $curve342 set _ curve2color($curve) $params(-color)343 set _ curve2width($curve) $params(-width)344 set _ curve2dashes($curve) $params(-linestyle)345 set _ curve2raise($curve) $params(-raise)346 set _ curve2desc($curve) $params(-description)339 lappend _dlist $dataobj 340 set _dataobj2color($dataobj) $params(-color) 341 set _dataobj2width($dataobj) $params(-width) 342 set _dataobj2dashes($dataobj) $params(-linestyle) 343 set _dataobj2raise($dataobj) $params(-raise) 344 set _dataobj2desc($dataobj) $params(-description) 347 345 348 346 $_dispatcher event -idle !rebuild … … 358 356 itcl::body Rappture::XyResult::get {} { 359 357 # put the dataobj list in order according to -raise options 360 set clist $_ clist358 set clist $_dlist 361 359 foreach obj $clist { 362 if {[info exists _ curve2raise($obj)] && $_curve2raise($obj)} {360 if {[info exists _dataobj2raise($obj)] && $_dataobj2raise($obj)} { 363 361 set i [lsearch -exact $clist $obj] 364 362 if {$i >= 0} { … … 372 370 373 371 # ---------------------------------------------------------------------- 374 # USAGE: delete ?< curve1> <curve2> ...?372 # USAGE: delete ?<dataobj1> <dataobj2> ...? 375 373 # 376 # Clients use this to delete a curve from the plot. If no curves377 # are specified, then all curves are deleted.374 # Clients use this to delete a dataobj from the plot. If no dataobjs 375 # are specified, then all dataobjs are deleted. 378 376 # ---------------------------------------------------------------------- 379 377 itcl::body Rappture::XyResult::delete {args} { 380 378 if {[llength $args] == 0} { 381 set args $_ clist382 } 383 384 # delete all specified curves379 set args $_dlist 380 } 381 382 # delete all specified dataobjs 385 383 set changed 0 386 foreach curve$args {387 set pos [lsearch -exact $_ clist $curve]384 foreach dataobj $args { 385 set pos [lsearch -exact $_dlist $dataobj] 388 386 if {$pos >= 0} { 389 set _ clist [lreplace $_clist $pos $pos]390 catch {unset _ curve2color($curve)}391 catch {unset _ curve2width($curve)}392 catch {unset _ curve2dashes($curve)}393 catch {unset _ curve2raise($curve)}394 foreach elem [array names _elem2 curve] {395 if {$_elem2 curve($elem) == $curve} {396 unset _elem2 curve($elem)387 set _dlist [lreplace $_dlist $pos $pos] 388 catch {unset _dataobj2color($dataobj)} 389 catch {unset _dataobj2width($dataobj)} 390 catch {unset _dataobj2dashes($dataobj)} 391 catch {unset _dataobj2raise($dataobj)} 392 foreach elem [array names _elem2dataobj] { 393 if {$_elem2dataobj($elem) == $dataobj} { 394 unset _elem2dataobj($elem) 397 395 } 398 396 } … … 407 405 408 406 # Nothing left? then start over with auto colors 409 if {[llength $_ clist] == 0} {407 if {[llength $_dlist] == 0} { 410 408 set _autoColorI 0 411 409 } … … 413 411 414 412 # ---------------------------------------------------------------------- 415 # USAGE: scale ?< curve1> <curve2> ...?413 # USAGE: scale ?<dataobj1> <dataobj2> ...? 416 414 # 417 415 # Sets the default limits for the overall plot according to the 418 # limits of the data for all of the given < curve> objects. This419 # accounts for all curves--even those not showing on the screen.420 # Because of this, the limits are appropriate for all curves as416 # limits of the data for all of the given <dataobj> objects. This 417 # accounts for all dataobjs--even those not showing on the screen. 418 # Because of this, the limits are appropriate for all dataobjs as 421 419 # the user scans through data in the ResultSet viewer. 422 420 # ---------------------------------------------------------------------- … … 435 433 436 434 catch {unset _limits} 437 foreach curve$args {438 # find the axes for this curve(e.g., {x y2})439 foreach {map(x) map(y)} [_getAxes $ curve] break435 foreach dataobj $args { 436 # find the axes for this dataobj (e.g., {x y2}) 437 foreach {map(x) map(y)} [_getAxes $dataobj] break 440 438 441 439 foreach axis {x y} { … … 444 442 # store results -- ex: _limits(x2log-min) 445 443 set id $map($axis)$type 446 foreach {min max} [$ curvelimits $axis$type] break444 foreach {min max} [$dataobj limits $axis$type] break 447 445 if {"" != $min && "" != $max} { 448 446 if {![info exists _limits($id-min)]} { … … 460 458 } 461 459 462 if {[$ curvehints ${axis}scale] == "log"} {460 if {[$dataobj hints ${axis}scale] == "log"} { 463 461 _axis scale $map($axis) log 464 462 } … … 530 528 append csvdata "[string repeat - 60]\n" 531 529 append csvdata " [$dataobj hints label]\n" 532 if {[info exists _ curve2desc($dataobj)]533 && [llength [split $_ curve2desc($dataobj) \n]] > 1} {530 if {[info exists _dataobj2desc($dataobj)] 531 && [llength [split $_dataobj2desc($dataobj) \n]] > 1} { 534 532 set indent "for:" 535 foreach line [split $_ curve2desc($dataobj) \n] {533 foreach line [split $_dataobj2desc($dataobj) \n] { 536 534 append csvdata " $indent $line\n" 537 535 set indent " " … … 549 547 set xv [$dataobj mesh $comp] 550 548 set yv [$dataobj values $comp] 551 foreach x [$xv range 0 end] y [$yv range 0 end] {549 foreach x [$xv values] y [$yv values] { 552 550 append csvdata [format "%20.15g, %20.15g\n" $x $y] 553 551 } … … 599 597 set g $itk_component(plot) 600 598 601 # first clear out the widget599 # First clear out the widget 602 600 eval $g element delete [$g element names] 601 eval $g marker delete [$g marker names] 603 602 foreach axis [$g axis names] { 604 603 $g axis configure $axis -hide yes -checklimits no \ … … 608 607 $g xaxis configure -hide no 609 608 $g yaxis configure -hide no 610 catch {unset _label2axis}609 array unset _label2axis 611 610 612 611 # … … 618 617 set anum(x) 0 619 618 set anum(y) 0 620 foreach curve[get] {619 foreach dataobj [get] { 621 620 foreach ax {x y} { 622 set label [$ curvehints ${ax}label]621 set label [$dataobj hints ${ax}label] 623 622 if {"" != $label} { 624 623 if {![info exists _label2axis($ax-$label)]} { … … 636 635 637 636 # if this axis has a description, add it as a tooltip 638 set desc [string trim [$ curvehints ${ax}desc]]637 set desc [string trim [$dataobj hints ${ax}desc]] 639 638 Rappture::Tooltip::text $g-$axis $desc 640 639 } … … 680 679 681 680 # 682 # Plot all of the curves.681 # Plot all of the dataobjs. 683 682 # 684 683 set count 0 685 foreach curve $_clist {686 set label [$ curvehints label]687 foreach {mapx mapy} [_getAxes $ curve] break688 689 foreach comp [$ curvecomponents] {690 set xv [$ curvemesh $comp]691 set yv [$ curvevalues $comp]692 693 if {[info exists _ curve2color($curve)]} {694 set color $_ curve2color($curve)684 foreach dataobj $_dlist { 685 set label [$dataobj hints label] 686 foreach {mapx mapy} [_getAxes $dataobj] break 687 688 foreach comp [$dataobj components] { 689 set xv [$dataobj mesh $comp] 690 set yv [$dataobj values $comp] 691 692 if {[info exists _dataobj2color($dataobj)]} { 693 set color $_dataobj2color($dataobj) 695 694 } else { 696 set color [$ curvehints color]695 set color [$dataobj hints color] 697 696 if {"" == $color} { 698 697 set color black … … 700 699 } 701 700 702 if {[info exists _ curve2width($curve)]} {703 set lwidth $_ curve2width($curve)701 if {[info exists _dataobj2width($dataobj)]} { 702 set lwidth $_dataobj2width($dataobj) 704 703 } else { 705 704 set lwidth 2 706 705 } 707 706 708 if {[info exists _ curve2dashes($curve)]} {709 set dashes $_ curve2dashes($curve)707 if {[info exists _dataobj2dashes($dataobj)]} { 708 set dashes $_dataobj2dashes($dataobj) 710 709 } else { 711 710 set dashes "" … … 721 720 722 721 set elem "elem[incr count]" 723 set _elem2 curve($elem) $curve722 set _elem2dataobj($elem) $dataobj 724 723 lappend label2elem($label) $elem 725 724 $g element create $elem -x $xv -y $yv \ … … 737 736 } 738 737 foreach elem $label2elem($label) { 739 set curve $_elem2curve($elem)740 scan [$ curvehints xmlobj] "::libraryObj%d" suffix738 set dataobj $_elem2dataobj($elem) 739 scan [$dataobj hints xmlobj] "::libraryObj%d" suffix 741 740 incr suffix 742 741 set elabel [format "%s \#%d" $label $suffix] … … 745 744 } 746 745 747 foreach curve $_clist {746 foreach dataobj $_dlist { 748 747 set xmin -Inf 749 748 set ymin -Inf … … 753 752 # Create text/line markers for each *axis.marker specified. 754 753 # 755 foreach m [$ curvexmarkers] {754 foreach m [$dataobj xmarkers] { 756 755 foreach {at label style} $m break 757 756 set id [$g marker create line -coords [list $at $ymin $at $ymax]] … … 769 768 set options [_getTextMarkerOptions $style] 770 769 if { $options != "" } { 771 puts stderr "$g marker configure $id $options"772 773 770 eval $g marker configure $id $options 774 771 } 775 772 } 776 773 } 777 foreach m [$ curveymarkers] {774 foreach m [$dataobj ymarkers] { 778 775 foreach {at label style} $m break 779 776 set id [$g marker create line -coords [list $xmin $at $xmax $at]] … … 792 789 if { $options != "" } { 793 790 eval $g marker configure $id $options 794 puts stderr [$g marker configure $id]795 791 } 796 792 } … … 919 915 920 916 # Some elements are generated dynamically and therefore will 921 # not have a curveobject associated with them.917 # not have a dataobj object associated with them. 922 918 set mapx [$g element cget $elem -mapx] 923 919 set mapy [$g element cget $elem -mapy] 924 if {[info exists _elem2 curve($elem)]} {925 foreach {mapx mapy} [_getAxes $_elem2 curve($elem)] break920 if {[info exists _elem2dataobj($elem)]} { 921 foreach {mapx mapy} [_getAxes $_elem2dataobj($elem)] break 926 922 } 927 923 … … 936 932 set y [$g axis transform $mapy $info(y)] 937 933 938 if {[info exists _elem2 curve($elem)]} {939 set curve $_elem2curve($elem)940 set yunits [$ curvehints yunits]941 set xunits [$ curvehints xunits]934 if {[info exists _elem2dataobj($elem)]} { 935 set dataobj $_elem2dataobj($elem) 936 set yunits [$dataobj hints yunits] 937 set xunits [$dataobj hints xunits] 942 938 } else { 943 939 set xunits "" … … 961 957 962 958 # Some elements are generated dynamically and therefore will 963 # not have a curveobject associated with them.959 # not have a dataobj object associated with them. 964 960 set mapx [$g element cget $elem -mapx] 965 961 set mapy [$g element cget $elem -mapy] 966 if {[info exists _elem2 curve($elem)]} {967 foreach {mapx mapy} [_getAxes $_elem2 curve($elem)] break962 if {[info exists _elem2dataobj($elem)]} { 963 foreach {mapx mapy} [_getAxes $_elem2dataobj($elem)] break 968 964 } 969 965 … … 972 968 set y [$g axis transform $mapy $info(y)] 973 969 974 if {[info exists _elem2 curve($elem)]} {975 set curve $_elem2curve($elem)976 set yunits [$ curvehints yunits]977 set xunits [$ curvehints xunits]970 if {[info exists _elem2dataobj($elem)]} { 971 set dataobj $_elem2dataobj($elem) 972 set yunits [$dataobj hints yunits] 973 set xunits [$dataobj hints xunits] 978 974 } else { 979 975 set xunits "" … … 1010 1006 set mapx [$g element cget $elem -mapx] 1011 1007 set mapy [$g element cget $elem -mapy] 1012 if {[info exists _elem2 curve($elem)]} {1013 foreach {mapx mapy} [_getAxes $_elem2 curve($elem)] break1008 if {[info exists _elem2dataobj($elem)]} { 1009 foreach {mapx mapy} [_getAxes $_elem2dataobj($elem)] break 1014 1010 } 1015 1011 set allx [$g x2axis use] … … 1527 1523 1528 1524 # ---------------------------------------------------------------------- 1529 # USAGE: _getAxes < curveObj>1525 # USAGE: _getAxes <dataobj> 1530 1526 # 1531 1527 # Used internally to figure out the axes used to plot the given 1532 # < curveObj>. Returns a list of the form {x y}, where x is the1528 # <dataobj>. Returns a list of the form {x y}, where x is the 1533 1529 # x-axis name (x, x2, x3, etc.), and y is the y-axis name. 1534 1530 # ---------------------------------------------------------------------- 1535 itcl::body Rappture::XyResult::_getAxes { curve} {1531 itcl::body Rappture::XyResult::_getAxes {dataobj} { 1536 1532 # rebuild if needed, so we know about the axes 1537 1533 if {[$_dispatcher ispending !rebuild]} { … … 1541 1537 1542 1538 # what is the x axis? x? x2? x3? ... 1543 set xlabel [$ curvehints xlabel]1539 set xlabel [$dataobj hints xlabel] 1544 1540 if {[info exists _label2axis(x-$xlabel)]} { 1545 1541 set mapx $_label2axis(x-$xlabel) … … 1549 1545 1550 1546 # what is the y axis? y? y2? y3? ... 1551 set ylabel [$ curvehints ylabel]1547 set ylabel [$dataobj hints ylabel] 1552 1548 if {[info exists _label2axis(y-$ylabel)]} { 1553 1549 set mapy $_label2axis(y-$ylabel)
Note: See TracChangeset
for help on using the changeset viewer.