Changeset 3800 for branches/1.3/gui/scripts/xyresult.tcl
- Timestamp:
- Jul 15, 2013, 9:29:39 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3/gui/scripts/xyresult.tcl
r3785 r3800 71 71 itk_option define -autocolors autoColors AutoColors "" 72 72 73 private variable _viewable ""; # Display list for widget. 73 private variable _viewable ""; # Display list for widget. 74 private variable _dispatcher ""; # Dispatcher for !events 75 private variable _dlist ""; # List of dataobj objects 76 private variable _dataobj2raise; # Maps dataobj => raise flag 0/1 77 private variable _dataobj2desc; # Maps dataobj => description of data 78 private variable _dataobj2sim; # Maps dataobj => type of graph element 79 private variable _elem2comp; # Maps graph element => dataobj 80 private variable _comp2elem; # Maps graph element => dataobj 81 private variable _label2axis; # Maps axis label => axis ID 82 private variable _limits; # Axis limits: x-min, x-max, etc. 83 private variable _nextColorIndex 0; # Index for next "-color auto" 84 private variable _hilite; # Info for element currently highlighted 85 private variable _axis; # Info for axis manipulations 86 private variable _axisPopup; # Info for axis being edited in popup 87 common _downloadPopup; # Download options from popup 88 private variable _markers 89 private variable _nextElement 0 90 74 91 constructor {args} { 75 92 # defined below … … 99 116 protected method LeaveMarker { g name } 100 117 101 private variable _dispatcher "" ;# dispatcher for !events 102 private variable _dlist "" ;# list of dataobj objects 103 private variable _dataobj2color ;# maps dataobj => plotting color 104 private variable _dataobj2width ;# maps dataobj => line width 105 private variable _dataobj2dashes ;# maps dataobj => BLT -dashes list 106 private variable _dataobj2raise ;# maps dataobj => raise flag 0/1 107 private variable _dataobj2desc ;# maps dataobj => description of data 108 private variable _dataobj2type ;# maps dataobj => type of graph element 109 private variable _dataobj2barwidth ;# maps dataobj => type of graph element 110 private variable _elem2comp ;# maps graph element => dataobj 111 private variable _comp2elem ;# maps graph element => dataobj 112 private variable _label2axis ;# maps axis label => axis ID 113 private variable _limits ;# axis limits: x-min, x-max, etc. 114 private variable _autoColorI 0 ;# index for next "-color auto" 115 private variable _hilite ;# info for element currently highlighted 116 private variable _axis ;# info for axis manipulations 117 private variable _axisPopup ;# info for axis being edited in popup 118 common _downloadPopup ;# download options from popup 119 private variable _markers 120 private variable _nextElement 0 121 122 private method BuildElements { dlist } 118 119 private method BuildGraph { dlist } 123 120 private method BuildMarkers { dataobj elem } 124 121 private method FormatAxis { axis w value } … … 127 124 private method ShowAxisPopup { axis } 128 125 private method SetAxis { setting } 126 private method SetElements { dataobj {settings ""} } 129 127 private method SetAxisRangeState { axis } 130 128 } … … 232 230 # ---------------------------------------------------------------------- 233 231 itcl::body Rappture::XyResult::add {dataobj {settings ""}} { 234 #puts stderr "XyResult::add dataobj=$dataobj settings=$settings" 235 array set params { 236 -color auto 237 -brightness 0 238 -width 1 239 -barwidth 1 240 -raise 0 241 -type "line" 242 -linestyle solid 243 -description "" 244 -param "" 245 } 246 # Override the defaults with first the <style> specified and then the 247 # settings list passed into this routoue. 248 array set params [$dataobj hints style] 249 set type [$dataobj hints type] 250 if { $type == "" } { 251 set type "line" 252 } 253 foreach {opt val} $settings { 254 if {![info exists params($opt)]} { 255 error "bad setting \"$opt\": should be [join [lsort [array names params]] {, }]" 256 } 257 set params($opt) $val 258 } 259 260 # if type is set to "scatter", then override the width 261 if { $type == "scatter" } { 262 set params(-width) 0 263 } 264 # if the color is "auto", then select a color from -autocolors 265 if { $params(-color) == "auto" || $params(-color) == "autoreset" } { 266 if {$params(-color) == "autoreset"} { 267 set _autoColorI 0 268 } 269 set color [lindex $itk_option(-autocolors) $_autoColorI] 232 #puts stderr "add: dataobj=$dataobj settings=$settings" 233 set g $itk_component(plot) 234 SetElements $dataobj $settings 235 236 array set attrs $settings 237 238 # Colors have to be set/reset here because of "-brightness" and "auto". 239 # Colors can't be overriden by the user. 240 241 # If the color is "auto", then select a color from -autocolors 242 if { ![info exists attrs(-color)] } { 243 set color "auto" 244 } else { 245 set color $attrs(-color) 246 } 247 if { $color == "auto" || $color == "autoreset" } { 248 if { $color == "autoreset" } { 249 set _nextColorIndex 0 250 } 251 set color [lindex $itk_option(-autocolors) $_nextColorIndex] 270 252 if { "" == $color} { 271 253 set color black 272 254 } 273 set params(-color) $color 274 # set up for next auto color 275 if {[incr _autoColorI] >= [llength $itk_option(-autocolors)]} { 276 set _autoColorI 0 277 } 278 } 279 280 # convert -linestyle to BLT -dashes 281 switch -- $params(-linestyle) { 282 dashed { set params(-linestyle) {4 4} } 283 dotted { set params(-linestyle) {2 4} } 284 default { set params(-linestyle) {} } 285 } 286 287 # if -brightness is set, then update the color 288 if {$params(-brightness) != 0} { 289 set params(-color) [Rappture::color::brightness \ 290 $params(-color) $params(-brightness)] 255 # Set up for next auto color 256 incr _nextColorIndex 257 if { $_nextColorIndex >= [llength $itk_option(-autocolors)] } { 258 set _nextColorIndex 0 259 } 260 } 261 # If -brightness is set, then update the color. 262 if { [info exists attrs(-brightness)] } { 263 set brightness $attrs(-brightness) 264 set color [Rappture::color::brightness $color $brightness] 291 265 set bg [$itk_component(plot) cget -plotbackground] 292 266 foreach {h s v} [Rappture::color::RGBtoHSV $bg] break 293 267 if {$v > 0.5} { 294 set params(-color) [Rappture::color::brightness_max \ 295 $params(-color) 0.8] 268 set color [Rappture::color::brightness_max $color 0.8] 296 269 } else { 297 set params(-color) [Rappture::color::brightness_min \ 298 $params(-color) 0.2] 299 } 300 } 301 302 set _dataobj2raise($dataobj) $params(-raise) 303 304 set g $itk_component(plot) 305 set color $params(-color) 306 set lwidth $params(-width) 307 set dashes $params(-linestyle) 308 set raise $params(-raise) 309 set desc $params(-description) 310 set barwidth $params(-barwidth) 311 foreach {mapx mapy} [GetAxes $dataobj] break 312 foreach comp [$dataobj components] { 313 set tag $dataobj-$comp 314 if { [info exists _comp2elem($tag)] } { 315 set elem $_comp2elem($tag) 316 # Ignore -type, it's already been set 317 switch -- [$g element type $elem] { 318 "line" - "scatter" { 319 $g line configure $elem \ 320 -linewidth $lwidth \ 321 -dashes $dashes -hide no 322 } "bar" { 323 $g bar configure $elem \ 324 -barwidth $barwidth \ 325 -hide no 326 } 327 } 270 set color [Rappture::color::brightness_min $color 0.2] 271 } 272 } 273 set type [$dataobj hints type] 274 foreach cname [$dataobj components] { 275 set tag $dataobj-$cname 276 set elem $_comp2elem($tag) 277 if { $type == "bar" } { 278 $g bar configure $elem -foreground $color -background $color \ 279 -hide no 328 280 } else { 329 set elem "$type[incr _nextElement]" 330 set label [$dataobj hints label] 331 set _elem2comp($elem) $tag 332 set _comp2elem($tag) $elem 333 lappend label2elem($label) $elem 334 set xv [$dataobj mesh $comp] 335 set yv [$dataobj values $comp] 336 switch -- $type { 337 "line" { 338 if {([$xv length] <= 1) || ($lwidth == 0)} { 339 set sym square 340 set pixels 2 341 } else { 342 set sym "" 343 set pixels 6 344 } 345 $g element create $elem -x $xv -y $yv \ 346 -symbol $sym -pixels $pixels -linewidth $lwidth \ 347 -label $label \ 348 -color $color -dashes $dashes \ 349 -mapx $mapx -mapy $mapy -hide no 350 } 351 "scatter" { 352 $g element create $elem -x $xv -y $yv \ 353 -symbol square -pixels 2 -linewidth $lwidth \ 354 -label $label \ 355 -color $color -dashes $dashes \ 356 -mapx $mapx -mapy $mapy -hide no 357 } 358 "bar" { 359 $g bar create $elem -x $xv -y $yv \ 360 -barwidth $barwidth \ 361 -label $label \ 362 -color $color \ 363 -mapx $mapx -mapy $mapy 364 } 365 } 281 $g line configure $elem -color $color -hide no 366 282 } 367 283 if { [lsearch $_viewable $elem] < 0 } { … … 442 358 #puts stderr "XyResult::scale args=$args" 443 359 set _dlist $args 444 Build Elements$args360 BuildGraph $args 445 361 } 446 362 … … 653 569 # Fix duplicate labels by appending the simulation number 654 570 # Collect the labels from all the viewable elements. 571 set above {} 572 set below {} 655 573 foreach elem $_viewable { 656 574 foreach {dataobj cname} [split $_elem2comp($elem) -] break … … 669 587 } 670 588 foreach {dataobj cname} [split $_elem2comp($elem) -] break 671 regexp {^::curve(?:Value)?([0-9]+)$} $dataobj match suffix 672 incr suffix 673 set elabel [format "%s \#%d" $label $suffix] 589 set sim $_dataobj2sim($dataobj) 590 set elabel [format "%s \#%d" $label $sim] 674 591 $g element configure $elem -label $elabel 675 592 } … … 1163 1080 } 1164 1081 } 1165 if {$_ autoColorI>= [llength $itk_option(-autocolors)]} {1166 set _ autoColorI01082 if {$_nextColorIndex >= [llength $itk_option(-autocolors)]} { 1083 set _nextColorIndex 0 1167 1084 } 1168 1085 } … … 1519 1436 1520 1437 # 1521 # Build Elements--1438 # BuildGraph -- 1522 1439 # 1523 1440 # This procedure loads each data objects specified into the … … 1527 1444 # for all datasets, even those not currently being displayed. 1528 1445 # 1529 itcl::body Rappture::XyResult::Build Elements{ dlist } {1446 itcl::body Rappture::XyResult::BuildGraph { dlist } { 1530 1447 set g $itk_component(plot) 1531 1448 … … 1622 1539 } 1623 1540 1624 # Create data elements and markers, but mark them as hidden.1625 # The "add" method will un-hide them.1626 set count 01627 1541 foreach dataobj $dlist { 1628 set label [$dataobj hints label] 1629 array set params [$dataobj hints style] 1630 set type [$dataobj hints type] 1631 # Default 1632 if {[info exists params(-color)]} { 1633 set color params(-color) 1542 SetElements $dataobj 1543 } 1544 ResetLegend 1545 } 1546 1547 # 1548 # SetElements -- 1549 # 1550 # This procedure loads each data objects specified into the 1551 # graph. The data object may already be loaded (from the "add" 1552 # method which gets called first). The graph elements that 1553 # are created, are hidden. This allows the graph to account 1554 # for all datasets, even those not currently being displayed. 1555 # 1556 itcl::body Rappture::XyResult::SetElements { dataobj {settings ""} } { 1557 set g $itk_component(plot) 1558 1559 array set attrs [$dataobj hints style] 1560 array set attrs $settings 1561 set type [$dataobj hints type] 1562 if { $type == "" } { 1563 set type "line" 1564 } 1565 1566 # Now fix attributes to a more usable form for the graph. 1567 1568 # Convert -linestyle to BLT -dashes 1569 if { ![info exists attrs(-linestyle)] } { 1570 set dashes {} 1571 } else { 1572 switch -- $attrs(-linestyle) { 1573 dashed { set dashes {4 4} } 1574 dotted { set dashes {2 4} } 1575 default { set dashes {} } 1576 } 1577 } 1578 if { ![info exists attrs(-barwidth)] } { 1579 set barwidth 1.0 1580 } else { 1581 set barwidth $attrs(-barwidth) 1582 } 1583 if { ![info exists attrs(-width)] } { 1584 set linewidth 1 1585 } else { 1586 set linewidth $attrs(-width) 1587 } 1588 if { ![info exists attrs(-raise)] } { 1589 set raise 0 1590 } else { 1591 set raise $attrs(-raise) 1592 } 1593 if { ![info exists attrs(-simulation)] } { 1594 set sim 0 1595 } else { 1596 set sim $attrs(-simulation) 1597 } 1598 1599 foreach {mapx mapy} [GetAxes $dataobj] break 1600 set label [$dataobj hints label] 1601 1602 foreach cname [$dataobj components] { 1603 set tag $dataobj-$cname 1604 set xv [$dataobj mesh $cname] 1605 set yv [$dataobj values $cname] 1606 1607 if {([$xv length] <= 1) || ($linewidth == 0)} { 1608 set sym square 1609 set pixels 2 1634 1610 } else { 1635 set color black 1636 } 1637 if { $type == "" } { 1638 set type "line" 1639 } 1640 if {[info exists parmas(-barwidth)]} { 1641 set barwidth $params(-barwidth) 1642 } else { 1643 set barwidth 1.0 1644 } 1645 if {[info exists params(-width)]} { 1646 set lwidth $params(-width) 1647 } else { 1648 set lwidth 2 1649 } 1650 if {[info exists params(-linestyle)]} { 1651 set dashes $parmas(-linestyle) 1652 } else { 1653 set dashes "" 1654 } 1655 foreach {mapx mapy} [GetAxes $dataobj] break 1656 foreach comp [$dataobj components] { 1657 set tag $dataobj-$comp 1658 if { [info exists _comp2elem($tag)] } { 1659 set found($_comp2elem($tag)) 1 1660 lappend label2elem($label) $_comp2elem($tag) 1661 # Element already created for data object/component. 1662 continue 1663 } 1664 set xv [$dataobj mesh $comp] 1665 set yv [$dataobj values $comp] 1666 1667 if {([$xv length] <= 1) || ($lwidth == 0)} { 1668 set sym square 1669 set pixels 2 1670 } else { 1671 set sym "" 1672 set pixels 6 1673 } 1611 set sym "" 1612 set pixels 6 1613 } 1614 if { ![info exists _comp2elem($tag)] } { 1674 1615 set elem "$type[incr _nextElement]" 1675 1616 set _elem2comp($elem) $tag … … 1678 1619 lappend label2elem($label) $elem 1679 1620 switch -- $type { 1680 "line" - "scatter"{1621 "line" { 1681 1622 $g line create $elem \ 1682 1623 -x $xv -y $yv \ 1683 1624 -symbol $sym \ 1684 1625 -pixels $pixels \ 1685 -linewidth $l width \1626 -linewidth $linewidth \ 1686 1627 -label $label \ 1687 -color $color \1688 1628 -dashes $dashes \ 1689 1629 -mapx $mapx \ 1690 1630 -mapy $mapy \ 1691 1631 -hide yes 1692 } "bar" { 1632 } 1633 "scatter" { 1634 $g line create $elem \ 1635 -x $xv -y $yv \ 1636 -symbol square \ 1637 -pixels 2 \ 1638 -linewidth 0 \ 1639 -label $label \ 1640 -dashes $dashes \ 1641 -mapx $mapx \ 1642 -mapy $mapy \ 1643 -hide yes 1644 } 1645 "bar" { 1693 1646 $g bar create $elem \ 1694 1647 -x $xv -y $yv \ 1695 1648 -barwidth $barwidth \ 1696 1649 -label $label \ 1697 -foreground $color \1698 -background $color \1699 1650 -mapx $mapx \ 1700 1651 -mapy $mapy \ … … 1702 1653 } 1703 1654 } 1704 if { [$dataobj info class] == "Rappture::Curve" } { 1705 BuildMarkers $dataobj $elem 1706 } 1707 } 1708 } 1709 foreach elem [$g element names] { 1710 if { ![info exists found($elem)] } { 1711 $g element delete $elem 1712 } 1713 } 1714 ResetLegend 1715 } 1655 } else { 1656 set elem $_comp2elem($tag) 1657 switch -- $type { 1658 "line" { 1659 $g line configure $elem \ 1660 -symbol $sym \ 1661 -pixels $pixels \ 1662 -linewidth $linewidth \ 1663 -dashes $dashes 1664 } 1665 "bar" { 1666 $g bar configure $elem \ 1667 -barwidth $barwidth \ 1668 -label $label 1669 } 1670 } 1671 } 1672 set _dataobj2raise($dataobj) $raise 1673 set _dataobj2sim($dataobj) $sim 1674 } 1675 }
Note: See TracChangeset
for help on using the changeset viewer.