Changeset 3765 for branches/1.3/gui/scripts
- Timestamp:
- Jul 10, 2013 12:43:48 PM (11 years ago)
- Location:
- branches/1.3/gui/scripts
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3/gui/scripts/barchartresult.tcl
r3454 r3765 108 108 protected method _leaveMarker { g name } 109 109 private method _formatTickLabel { w value } 110 private method ResetLegend {} 110 111 111 112 private variable _dispatcher "" ;# dispatcher for !events … … 256 257 } 257 258 pack $itk_component(legend) -expand yes -fill both 258 after idle [subst { 259 update idletasks 260 $itk_component(legend) reset 261 }] 259 after idle [itcl::code $this ResetLegend] 262 260 263 261 # quick-and-dirty zoom functionality, for now... … … 798 796 } 799 797 } 800 $itk_component(legend) reset798 ResetLegend 801 799 } 802 800 … … 1627 1625 return $label 1628 1626 } 1627 1628 # 1629 # ResetLegend -- 1630 # 1631 itcl::body Rappture::BarchartResult::ResetLegend {} { 1632 set g $itk_component(plot) 1633 update idletasks 1634 $itk_component(legend) reset [$g element show] 1635 } -
branches/1.3/gui/scripts/drawingentry.tcl
r3739 r3765 323 323 set _xOffset 0 324 324 set _yOffset 0 325 # By default, the screen coordinates are 0 to 1 326 ParseScreenCoordinates "0 0 1 1" 325 327 ParseDescription 326 328 } -
branches/1.3/gui/scripts/field.tcl
r3707 r3765 73 73 74 74 itcl::class Rappture::Field { 75 pr ivate variable _dim 0;# Dimension of the mesh75 protected variable _dim 0; # Dimension of the mesh 76 76 private variable _xmlobj ""; # ref to XML obj with field data 77 77 private variable _limits; # maps axis name => {z0 z1} limits … … 1334 1334 # DX: Convert DX to VTK 1335 1335 if {[info exists _comp2dx($cname)]} { 1336 return [Rappture::DxToVtk $_comp2dx($cname)] 1336 set data $_comp2dx($cname) 1337 set data [Rappture::encoding::decode $data] 1338 return [Rappture::DxToVtk $data] 1337 1339 } 1338 1340 # Unirect3d: isosurface -
branches/1.3/gui/scripts/histogramresult.tcl
r3454 r3765 106 106 protected method LeaveMarker { g name } 107 107 protected method FormatLabels { g value } 108 private method ResetLegend {} 108 109 109 110 private variable _dispatcher "" ;# dispatcher for !events … … 252 253 } 253 254 pack $itk_component(legend) -expand yes -fill both 254 after idle [subst { 255 update idletasks 256 $itk_component(legend) reset 257 }] 255 after idle [itcl::code $this ResetLegend] 258 256 259 257 # quick-and-dirty zoom functionality, for now... … … 822 820 } 823 821 $g configure -invertxy $invert 824 $itk_component(legend) reset822 ResetLegend 825 823 } 826 824 … … 1610 1608 return " " 1611 1609 } 1610 1611 # 1612 # ResetLegend -- 1613 # 1614 itcl::body Rappture::HistogramResult::ResetLegend {} { 1615 set g $itk_component(plot) 1616 update idletasks 1617 $itk_component(legend) reset [$g element show] 1618 } -
branches/1.3/gui/scripts/numberresult.tcl
r3454 r3765 95 95 protected method GetValue {dataobj {which both}} 96 96 protected method GetInfo {what dataobj {which both}} 97 private method ResetLegend {} 97 98 98 99 private variable _dispatcher "" ;# dispatcher for !events … … 243 244 } 244 245 pack $itk_component(legend) -expand yes -fill both 245 after idle [subst { 246 update idletasks 247 $itk_component(legend) reset 248 }] 246 after idle [itcl::code $this ResetLegend] 247 249 248 # quick-and-dirty zoom functionality, for now... 250 249 Blt_ZoomStack $itk_component(plot) … … 1564 1563 } 1565 1564 } 1565 1566 # 1567 # ResetLegend -- 1568 # 1569 itcl::body Rappture::NumberResult::ResetLegend {} { 1570 set g $itk_component(plot) 1571 update idletasks 1572 $itk_component(legend) reset [$g element show] 1573 } -
branches/1.3/gui/scripts/vtkglyphviewer.tcl
r3739 r3765 1392 1392 if { $color == "none" } { 1393 1393 if { $_settings(colormapVisible) } { 1394 SendCmd "glyphs surface 0"1394 SendCmd "glyphs colormode ccolor {}" 1395 1395 set _settings(colormapVisible) 0 1396 1396 } 1397 1397 } else { 1398 1398 if { !$_settings(colormapVisible) } { 1399 SendCmd "glyphs surface 1"1399 SendCmd "glyphs colormode $_colorMode $_curFldName" 1400 1400 set _settings(colormapVisible) 1 1401 1401 } … … 1455 1455 return 1456 1456 } 1457 SendCmd "dataset vector $_curFldName" 1458 SendCmd "dataset maprange explicit $_limits($_curFldName) $_curFldName" 1457 #SendCmd "dataset maprange explicit $_limits($_curFldName) $_curFldName" 1459 1458 #SendCmd "cutplane colormode $_colorMode $_curFldName" 1460 1459 SendCmd "glyphs colormode $_colorMode $_curFldName" 1461 SendCmd "camera reset"1462 1460 DrawLegend 1463 1461 } … … 1521 1519 if { $_currentColormap != "" } { 1522 1520 set cmap $_currentColormap 1523 SendCmdNoWait "legend $cmap vmag$_curFldName {} $w $h 0"1521 SendCmdNoWait "legend $cmap $_colorMode $_curFldName {} $w $h 0" 1524 1522 } 1525 1523 } … … 1628 1626 1629 1627 itk_component add field_l { 1630 label $inner.field_l -text " Field" -font "Arial 9"1628 label $inner.field_l -text "Color By" -font "Arial 9" 1631 1629 } { 1632 1630 ignore -font -
branches/1.3/gui/scripts/vtkstreamlinesviewer.tcl
r3592 r3765 87 87 private method BuildStreamsTab {} 88 88 private method BuildVolumeTab {} 89 private method ConvertToVtkData { dataobj comp }90 89 private method DrawLegend {} 91 90 private method Combo { option } … … 2031 2030 $itk_component(zCutScale) set 50 2032 2031 $itk_component(zCutScale) configure -state disabled 2033 #$itk_component(zCutScale) configure -state disabled2034 2032 Rappture::Tooltip::for $itk_component(zCutScale) \ 2035 2033 "@[itcl::code $this Slice tooltip z]" … … 2052 2050 } 2053 2051 2054 2055 2056 2052 # 2057 2053 # camera -- … … 2093 2089 } 2094 2090 2095 itcl::body Rappture::VtkStreamlinesViewer::ConvertToVtkData { dataobj comp } {2096 foreach { x1 x2 xN y1 y2 yN } [$dataobj mesh $comp] break2097 set values [$dataobj values $comp]2098 append out "# vtk DataFile Version 2.0 \n"2099 append out "Test data \n"2100 append out "ASCII \n"2101 append out "DATASET STRUCTURED_POINTS \n"2102 append out "DIMENSIONS $xN $yN 1 \n"2103 append out "ORIGIN 0 0 0 \n"2104 append out "SPACING 1 1 1 \n"2105 append out "POINT_DATA [expr $xN * $yN] \n"2106 append out "SCALARS field double 1 \n"2107 append out "LOOKUP_TABLE default \n"2108 append out [join $values "\n"]2109 append out "\n"2110 return $out2111 }2112 2113 2114 2091 itcl::body Rappture::VtkStreamlinesViewer::GetVtkData { args } { 2115 2092 set bytes "" … … 2117 2094 foreach comp [$dataobj components] { 2118 2095 set tag $dataobj-$comp 2119 #set contents [ConvertToVtkData $dataobj $comp] 2120 set contents [$dataobj blob $comp] 2121 append bytes "$contents\n\n" 2096 set contents [$dataobj vtkdata $comp] 2097 append bytes "$contents\n" 2122 2098 } 2123 2099 } … … 2207 2183 SendCmd "cutplane add $tag" 2208 2184 SendCmd "polydata add $tag" 2185 #SendCmd "polydata colormode ccolor {} $tag" 2209 2186 set _settings(volumeEdges) $settings(-edges) 2210 2187 set _settings(volumeLighting) $settings(-lighting) … … 2387 2364 } 2388 2365 2389 2390 2366 # ---------------------------------------------------------------------- 2391 2367 # USAGE: Slice move x|y|z <newval> … … 2418 2394 } 2419 2395 } 2420 2421 2396 2422 2397 # ---------------------------------------------------------------------- … … 2477 2452 set _view(zoom) 1.0 2478 2453 } 2479 -
branches/1.3/gui/scripts/vtkvolumeviewer.tcl
r3592 r3765 87 87 private method BuildDownloadPopup { widget command } 88 88 private method BuildVolumeTab {} 89 private method ConvertToVtkData { dataobj comp }90 89 private method DrawLegend {} 91 90 private method Combo { option } … … 1957 1956 } 1958 1957 1959 itcl::body Rappture::VtkVolumeViewer::ConvertToVtkData { dataobj comp } {1960 foreach { x1 x2 xN y1 y2 yN } [$dataobj mesh $comp] break1961 set values [$dataobj values $comp]1962 append out "# vtk DataFile Version 2.0 \n"1963 append out "Test data \n"1964 append out "ASCII \n"1965 append out "DATASET STRUCTURED_POINTS \n"1966 append out "DIMENSIONS $xN $yN 1 \n"1967 append out "ORIGIN 0 0 0 \n"1968 append out "SPACING 1 1 1 \n"1969 append out "POINT_DATA [expr $xN * $yN] \n"1970 append out "SCALARS field double 1\n"1971 append out "LOOKUP_TABLE default \n"1972 append out [join $values "\n"]1973 append out "\n"1974 return $out1975 }1976 1977 1978 1958 itcl::body Rappture::VtkVolumeViewer::GetVtkData { args } { 1979 1959 set bytes "" … … 1981 1961 foreach comp [$dataobj components] { 1982 1962 set tag $dataobj-$comp 1983 #set contents [ConvertToVtkData $dataobj $comp] 1984 set contents [$dataobj blob $comp] 1985 append bytes "$contents\n\n" 1963 set contents [$dataobj vtkdata $comp] 1964 append bytes "$contents\n" 1986 1965 } 1987 1966 } -
branches/1.3/gui/scripts/xylegend.tcl
r3330 r3765 72 72 destructor {} 73 73 74 public method reset { }74 public method reset { list } 75 75 76 76 private method Add { elem label {flags ""}} … … 239 239 240 240 # ---------------------------------------------------------------------- 241 # USAGE: reset <curve> ?<settings>?241 # USAGE: reset 242 242 # 243 243 # Clients use this to add a curve to the plot. The optional <settings> … … 245 245 # -brightness, -width, -linestyle and -raise. 246 246 # ---------------------------------------------------------------------- 247 itcl::body Rappture::XyLegend::reset { } {247 itcl::body Rappture::XyLegend::reset { list } { 248 248 foreach node [$_tree children root] { 249 249 $_tree delete $node 250 250 } 251 foreach elem [$_graph element show]{251 foreach elem $list { 252 252 if {[catch {$_graph element cget $elem -label} label] == 0} { 253 253 if {$label eq ""} { -
branches/1.3/gui/scripts/xyresult.tcl
r3726 r3765 71 71 itk_option define -autocolors autoColors AutoColors "" 72 72 73 private variable _viewable ""; # Display list for widget. 73 74 constructor {args} { 74 75 # defined below … … 88 89 protected method Rebuild {} 89 90 protected method ResetLimits {} 91 protected method ResetLegend {} 90 92 protected method Zoom {option args} 91 93 protected method Hilite {state x y} … … 106 108 private variable _dataobj2type ;# maps dataobj => type of graph element 107 109 private variable _dataobj2barwidth ;# maps dataobj => type of graph element 108 private variable _elem2dataobj ;# maps graph element => dataobj 110 private variable _elem2comp ;# maps graph element => dataobj 111 private variable _comp2elem ;# maps graph element => dataobj 109 112 private variable _label2axis ;# maps axis label => axis ID 110 113 private variable _limits ;# axis limits: x-min, x-max, etc. … … 117 120 private variable _nextElement 0 118 121 122 private method BuildElements { dlist } 123 private method BuildMarkers { dataobj elem } 119 124 private method FormatAxis { axis w value } 120 125 private method GetFormattedValue { axis g value } … … 204 209 } 205 210 pack $itk_component(legend) -expand yes -fill both 206 after idle [subst { 207 update idletasks 208 $itk_component(legend) reset 209 }] 211 after idle [itcl::code $this ResetLegend] 210 212 211 213 # quick-and-dirty zoom functionality, for now... … … 230 232 # ---------------------------------------------------------------------- 231 233 itcl::body Rappture::XyResult::add {dataobj {settings ""}} { 234 #puts stderr "XyResult::add dataobj=$dataobj settings=$settings" 232 235 array set params { 233 236 -color auto … … 293 296 } 294 297 295 set pos [lsearch -exact $dataobj $_dlist] 296 if {$pos < 0} { 297 lappend _dlist $dataobj 298 set _dataobj2color($dataobj) $params(-color) 299 set _dataobj2width($dataobj) $params(-width) 300 set _dataobj2dashes($dataobj) $params(-linestyle) 301 set _dataobj2raise($dataobj) $params(-raise) 302 set _dataobj2desc($dataobj) $params(-description) 303 set _dataobj2type($dataobj) $params(-type) 304 set _dataobj2barwidth($dataobj) $params(-barwidth) 305 $_dispatcher event -idle !rebuild 306 } 298 set dataobj2raise($dataobj) $params(-raise) 299 300 set g $itk_component(plot) 301 set color $params(-color) 302 set lwidth $params(-width) 303 set dashes $params(-linestyle) 304 set raise $params(-raise) 305 set desc $params(-description) 306 set type $params(-type) 307 set barwidth $params(-barwidth) 308 foreach {mapx mapy} [GetAxes $dataobj] break 309 foreach comp [$dataobj components] { 310 set tag $dataobj-$comp 311 if { [info exists _comp2elem($tag)] } { 312 set elem $_comp2elem($tag) 313 switch -- $type { 314 "line" - "scatter" { 315 $g element configure $elem \ 316 -linewidth $lwidth \ 317 -dashes $dashes -hide no 318 } "bar" { 319 $g bar configure $elem \ 320 -barwidth $barwidth \ 321 -hide no 322 } 323 } 324 } else { 325 set elem "$type[incr _nextElement]" 326 set label [$dataobj hints label] 327 set _elem2comp($elem) $tag 328 set _comp2elem($tag) $elem 329 lappend label2elem($label) $elem 330 set xv [$dataobj mesh $comp] 331 set yv [$dataobj values $comp] 332 switch -- $type { 333 "line" { 334 if {([$xv length] <= 1) || ($lwidth == 0)} { 335 set sym square 336 set pixels 2 337 } else { 338 set sym "" 339 set pixels 6 340 } 341 $g element create $elem -x $xv -y $yv \ 342 -symbol $sym -pixels $pixels -linewidth $lwidth \ 343 -label $label \ 344 -color $color -dashes $dashes \ 345 -mapx $mapx -mapy $mapy -hide no 346 } 347 "scatter" { 348 $g element create $elem -x $xv -y $yv \ 349 -symbol square -pixels 2 -linewidth $lwidth \ 350 -label $label \ 351 -color $color -dashes $dashes \ 352 -mapx $mapx -mapy $mapy -hide no 353 } 354 "bar" { 355 $g bar create $elem -x $xv -y $yv \ 356 -barwidth $barwidth \ 357 -label $label \ 358 -color $color \ 359 -mapx $mapx -mapy $mapy 360 } 361 } 362 } 363 if { [lsearch $_viewable $elem] < 0 } { 364 lappend _viewable $elem 365 } 366 } 367 if { [$dataobj info class] == "Rappture::Curve" } { 368 BuildMarkers $dataobj $elem 369 } 370 $_dispatcher event -idle !rebuild 307 371 } 308 372 … … 335 399 # ---------------------------------------------------------------------- 336 400 itcl::body Rappture::XyResult::delete {args} { 337 if {[llength $args] == 0} { 338 set args $_dlist 339 } 340 341 # delete all specified dataobjs 342 set changed 0 401 #puts stderr "XyResult::delete args=$args" 402 set g $itk_component(plot) 403 404 # First try to create list of elements from the dataobjs specified 405 set elemlist {} 343 406 foreach dataobj $args { 344 set pos [lsearch -exact $_dlist $dataobj] 345 if {$pos >= 0} { 346 set _dlist [lreplace $_dlist $pos $pos] 347 array unset _dataobj2color $dataobj 348 array unset _dataobj2width $dataobj 349 array unset _dataobj2dashes $dataobj 350 array unset _dataobj2raise $dataobj 351 array unset _dataobj2type $dataobj 352 array unset _dataobj2barwidth $dataobj 353 foreach elem [array names _elem2dataobj] { 354 if {$_elem2dataobj($elem) == $dataobj} { 355 array unset _elem2dataobj $elem 356 } 357 } 358 set changed 1 359 } 360 } 361 362 # If anything changed, then rebuild the plot 363 if {$changed} { 364 $_dispatcher event -idle !rebuild 365 } 366 367 # Nothing left? then start over with auto colors 368 if {[llength $_dlist] == 0} { 369 set _autoColorI 0 407 foreach cname [$dataobj components] { 408 set tag $dataobj-$cname 409 if { [info exists _comp2elem($tag)] } { 410 lappend elemlist $_comp2elem($tag) 411 } 412 } 413 } 414 # If no dataobjs were specified then hide all elements. 415 if { [llength $elemlist] == 0 } { 416 set elemlist [$g element names] 417 } 418 # Hide all elements specified by their dataobjs 419 foreach elem $elemlist { 420 $g element configure $elem -hide yes 421 set i [lsearch $_viewable $elem] 422 if { $i >= 0 } { 423 set _viewable [lreplace $_viewable $i $i] 424 } 370 425 } 371 426 } … … 381 436 # ---------------------------------------------------------------------- 382 437 itcl::body Rappture::XyResult::scale {args} { 383 set allx [$itk_component(plot) x2axis use] 384 lappend allx x ;# fix main x-axis too 385 386 set ally [$itk_component(plot) y2axis use] 387 lappend ally y ;# fix main y-axis too 388 catch {unset _limits} 389 foreach dataobj $args { 390 # Find the axes for this dataobj (e.g., {x y2}) 391 foreach {map(x) map(y)} [GetAxes $dataobj] break 392 foreach axis {x y} { 393 if {[$dataobj hints ${axis}scale] == "log"} { 394 set _limits(${axis}log) 1 395 } 396 # Get defaults for both linear and log scales 397 foreach type {lin log} { 398 # store results -- ex: _limits(x2log-min) 399 set id $map($axis)$type 400 set min [$dataobj hints ${axis}min] 401 set max [$dataobj hints ${axis}max] 402 if {"" != $min && "" != $max} { 403 if {![info exists _limits($id-min)]} { 404 set _limits($id-min) $min 405 set _limits($id-max) $max 406 } else { 407 if {$min < $_limits($id-min)} { 408 set _limits($id-min) $min 409 } 410 if {$max > $_limits($id-max)} { 411 set _limits($id-max) $max 412 } 413 } 414 } 415 } 416 } 417 } 418 ResetLimits 438 #puts stderr "XyResult::scale args=$args" 439 set _dlist $args 440 BuildElements $args 419 441 } 420 442 … … 540 562 } 541 563 564 itcl::body Rappture::XyResult::BuildMarkers { dataobj elem } { 565 set g $itk_component(plot) 566 567 foreach m [$dataobj xmarkers] { 568 foreach {at label style} $m break 569 set id [$g marker create line -coords [list $at $ymin $at $ymax]] 570 $g marker bind $id <Enter> \ 571 [itcl::code $this EnterMarker $g x-$label $at $ymin $at] 572 $g marker bind $id <Leave> \ 573 [itcl::code $this LeaveMarker $g x-$label] 574 set options [GetLineMarkerOptions $style] 575 $g marker configure $id -element $elem 576 if { $options != "" } { 577 eval $g marker configure $id $options 578 } 579 if { $label != "" } { 580 set id [$g marker create text -anchor nw \ 581 -text $label -coords [list $at $ymax]] 582 $g marker configure $id -element $elem 583 set options [GetTextMarkerOptions $style] 584 if { $options != "" } { 585 eval $g marker configure $id $options 586 } 587 } 588 } 589 foreach m [$dataobj ymarkers] { 590 foreach {at label style} $m break 591 set id [$g marker create line -coords [list $xmin $at $xmax $at]] 592 $g marker configure $id -element $elem 593 $g marker bind $id <Enter> \ 594 [itcl::code $this EnterMarker $g y-$label $at $xmin $at] 595 $g marker bind $id <Leave> \ 596 [itcl::code $this LeaveMarker $g y-$label] 597 set options [GetLineMarkerOptions $style] 598 if { $options != "" } { 599 eval $g marker configure $id $options 600 } 601 if { $label != "" } { 602 set id [$g marker create text -anchor se \ 603 -text $label -coords [list $xmax $at]] 604 $g marker configure $id -element $elem 605 set options [GetTextMarkerOptions $style] 606 if { $options != "" } { 607 eval $g marker configure $id $options 608 } 609 } 610 } 611 } 612 542 613 # ---------------------------------------------------------------------- 543 614 # USAGE: Rebuild 544 615 # 545 # Called automatically whenever something changes that affects the616 # Called automatically whenever something changes that affects the 546 617 # data in the widget. Clears any existing data and rebuilds the 547 618 # widget to display new data. 548 619 # ---------------------------------------------------------------------- 549 620 itcl::body Rappture::XyResult::Rebuild {} { 621 ResetLegend 622 # Fix raise/lower elements 623 } 624 625 # ---------------------------------------------------------------------- 626 # USAGE: ResetLimits 627 # 628 # Used internally to apply automatic limits to the axes for the 629 # current plot. 630 # ---------------------------------------------------------------------- 631 itcl::body Rappture::XyResult::ResetLimits {} { 550 632 set g $itk_component(plot) 551 633 552 # First clear out the widget553 eval $g element delete [$g element names]554 eval $g marker delete [$g marker names]555 556 634 foreach axis [$g axis names] { 557 if { [info exist _limits(${axis}log)] } { 558 set type "log" 559 set logscale 1 560 } else { 561 set type "lin" 562 set logscale 0 563 } 564 set amin "" 565 if { [info exists _limits(${axis}${type}-min)] } { 566 set amin $_limits(${axis}${type}-min) 567 } 568 set amax "" 569 if { [info exists _limits(${axis}${type}-max)] } { 570 set amax $_limits(${axis}${type}-max) 571 } 572 $g axis configure $axis \ 573 -hide yes -checklimits no \ 574 -command [itcl::code $this GetFormattedValue $axis] \ 575 -min $amin -max $amax -logscale $logscale 576 } 577 # Presumably you want at least an X-axis and Y-axis displayed. 578 $g xaxis configure -hide no 579 $g yaxis configure -hide no 580 array unset _label2axis 581 582 # 583 # Scan through all objects and create a list of all axes. 584 # The first x-axis gets mapped to "x". The second, to "x2". 585 # Beyond that, we must create new axes "x3", "x4", etc. 586 # We do the same for y. 587 # 588 set anum(x) 0 589 set anum(y) 0 590 foreach dataobj [get] { 591 foreach ax {x y} { 592 set label [$dataobj hints ${ax}label] 593 if {"" != $label} { 594 if {![info exists _label2axis($ax-$label)]} { 595 switch [incr anum($ax)] { 596 1 { set axis $ax } 597 2 { set axis ${ax}2 } 598 default { 599 set axis $ax$anum($ax) 600 catch {$g axis create $axis} 601 } 602 } 603 $g axis configure $axis -title $label -hide no \ 604 -checklimits no 605 set _label2axis($ax-$label) $axis 606 607 # if this axis has a description, add it as a tooltip 608 set desc [string trim [$dataobj hints ${ax}desc]] 609 Rappture::Tooltip::text $g-$axis $desc 610 } 611 } 612 } 613 } 614 615 # 616 # All of the extra axes get mapped to the x2/y2 (top/right) 617 # position. 618 # 619 set all "" 620 foreach ax {x y} { 621 lappend all $ax 622 623 set extra "" 624 for {set i 2} {$i <= $anum($ax)} {incr i} { 625 lappend extra ${ax}$i 626 } 627 eval lappend all $extra 628 $g ${ax}2axis use $extra 629 if {$ax == "y"} { 630 $g configure -rightmargin [expr {($extra == "") ? 10 : 0}] 631 } 632 } 633 634 foreach axis $all { 635 $g axis bind $axis <Enter> \ 636 [itcl::code $this Axis hilite $axis on] 637 $g axis bind $axis <Leave> \ 638 [itcl::code $this Axis hilite $axis off] 639 $g axis bind $axis <ButtonPress-1> \ 640 [itcl::code $this Axis click $axis %x %y] 641 $g axis bind $axis <B1-Motion> \ 642 [itcl::code $this Axis drag $axis %x %y] 643 $g axis bind $axis <ButtonRelease-1> \ 644 [itcl::code $this Axis release $axis %x %y] 645 $g axis bind $axis <KeyPress> \ 646 [list ::Rappture::Tooltip::tooltip cancel] 647 } 648 649 # 650 # Plot all of the dataobjs. 651 # 652 set count 0 653 foreach dataobj $_dlist { 635 $g axis configure $axis -min "" -max "" 636 } 637 } 638 639 # ---------------------------------------------------------------------- 640 # USAGE: ResetLegend 641 # 642 # Used internally to apply automatic limits to the axes for the 643 # current plot. 644 # ---------------------------------------------------------------------- 645 itcl::body Rappture::XyResult::ResetLegend {} { 646 update idletasks 647 648 set g $itk_component(plot) 649 # Fix duplicate labels by appending the simulation number 650 # Collect the labels from all the viewable elements. 651 foreach elem $_viewable { 652 foreach {dataobj cname} [split $_elem2comp($elem) -] break 654 653 set label [$dataobj hints label] 655 foreach {mapx mapy} [GetAxes $dataobj] break 656 foreach comp [$dataobj components] { 657 set xv [$dataobj mesh $comp] 658 set yv [$dataobj values $comp] 659 660 if {[info exists _dataobj2color($dataobj)]} { 661 set color $_dataobj2color($dataobj) 662 } else { 663 set color black 664 } 665 if {[info exists _dataobj2type($dataobj)]} { 666 set type $_dataobj2type($dataobj) 667 } else { 668 set type "line" 669 } 670 if {[info exists _dataobj2barwidth($dataobj)]} { 671 set barwidth $_dataobj2barwidth($dataobj) 672 } else { 673 set barwidth 1.0 674 } 675 if {[info exists _dataobj2width($dataobj)]} { 676 set lwidth $_dataobj2width($dataobj) 677 } else { 678 set lwidth 2 679 } 680 if {[info exists _dataobj2dashes($dataobj)]} { 681 set dashes $_dataobj2dashes($dataobj) 682 } else { 683 set dashes "" 684 } 685 if {([$xv length] <= 1) || ($lwidth == 0)} { 686 set sym square 687 set pixels 2 688 } else { 689 set sym "" 690 set pixels 6 691 } 692 693 set elem "elem[incr _nextElement]" 694 set _elem2dataobj($elem) $dataobj 695 lappend label2elem($label) $elem 696 switch -- $type { 697 "line" - "scatter" { 698 $g element create $elem -x $xv -y $yv \ 699 -symbol $sym -pixels $pixels -linewidth $lwidth \ 700 -label $label \ 701 -color $color -dashes $dashes \ 702 -mapx $mapx -mapy $mapy 703 } "bar" { 704 $g bar create $elem -x $xv -y $yv \ 705 -barwidth $barwidth \ 706 -label $label \ 707 -color $color \ 708 -mapx $mapx -mapy $mapy 709 } 710 } 711 } 712 } 713 714 # Fix duplicate labels by appending the simulation number 654 lappend label2elem($label) $elem 655 } 656 # Then relabel elements with the same label, using the simulation number. 715 657 foreach label [array names label2elem] { 716 if { [llength $label2elem($label)] == 1 } {717 continue718 }719 658 foreach elem $label2elem($label) { 720 set dataobj $_elem2dataobj($elem) 659 if { [llength $label2elem($label)] == 1 } { 660 $g element configure $elem -label $label 661 continue 662 } 663 foreach {dataobj cname} [split $_elem2comp($elem) -] break 721 664 regexp {^::curve(?:Value)?([0-9]+)$} $dataobj match suffix 722 665 incr suffix … … 725 668 } 726 669 } 727 728 foreach dataobj $_dlist { 729 set xmin -Inf 730 set ymin -Inf 731 set xmax Inf 732 set ymax Inf 733 # 734 # Create text/line markers for each *axis.marker specified. 735 # 736 if { [$dataobj info class] == "Rappture::Curve" } { 737 foreach m [$dataobj xmarkers] { 738 foreach {at label style} $m break 739 set id [$g marker create line \ 740 -coords [list $at $ymin $at $ymax]] 741 $g marker bind $id <Enter> \ 742 [itcl::code $this EnterMarker $g x-$label $at $ymin $at] 743 $g marker bind $id <Leave> \ 744 [itcl::code $this LeaveMarker $g x-$label] 745 set options [GetLineMarkerOptions $style] 746 if { $options != "" } { 747 eval $g marker configure $id $options 748 } 749 if { $label != "" } { 750 set id [$g marker create text -anchor nw \ 751 -text $label -coords [list $at $ymax]] 752 set options [GetTextMarkerOptions $style] 753 if { $options != "" } { 754 eval $g marker configure $id $options 755 } 756 } 757 } 758 foreach m [$dataobj ymarkers] { 759 foreach {at label style} $m break 760 set id [$g marker create line \ 761 -coords [list $xmin $at $xmax $at]] 762 $g marker bind $id <Enter> \ 763 [itcl::code $this EnterMarker $g y-$label $at $xmin $at] 764 $g marker bind $id <Leave> \ 765 [itcl::code $this LeaveMarker $g y-$label] 766 set options [GetLineMarkerOptions $style] 767 if { $options != "" } { 768 eval $g marker configure $id $options 769 } 770 if { $label != "" } { 771 set id [$g marker create text -anchor se \ 772 -text $label -coords [list $xmax $at]] 773 set options [GetTextMarkerOptions $style] 774 if { $options != "" } { 775 eval $g marker configure $id $options 776 } 777 } 778 } 779 } 780 } 781 $itk_component(legend) reset 782 } 783 784 # ---------------------------------------------------------------------- 785 # USAGE: ResetLimits 786 # 787 # Used internally to apply automatic limits to the axes for the 788 # current plot. 789 # ---------------------------------------------------------------------- 790 itcl::body Rappture::XyResult::ResetLimits {} { 791 set g $itk_component(plot) 792 793 foreach axis [$g axis names] { 794 $g axis configure $axis -min "" -max "" 795 } 796 } 670 $itk_component(legend) reset $_viewable 671 } 672 797 673 798 674 # ---------------------------------------------------------------------- … … 837 713 set mapx [$g element cget $elem -mapx] 838 714 set mapy [$g element cget $elem -mapy] 839 if {[info exists _elem2dataobj($elem)]} { 840 foreach {mapx mapy} [GetAxes $_elem2dataobj($elem)] break 715 if {[info exists _elem2comp($elem)]} { 716 foreach {dataobj cname} [split $_elem2comp($elem) -] break 717 foreach {mapx mapy} [GetAxes $dataobj] break 841 718 } 842 719 … … 850 727 set y [$g axis transform $mapy $info(y)] 851 728 852 if {[info exists _elem2 dataobj($elem)]} {853 set dataobj $_elem2dataobj($elem)729 if {[info exists _elem2comp($elem)]} { 730 foreach {dataobj cname} [split $_elem2comp($elem) -] break 854 731 set yunits [$dataobj hints yunits] 855 732 set xunits [$dataobj hints xunits] … … 874 751 set mapx [$g element cget $elem -mapx] 875 752 set mapy [$g element cget $elem -mapy] 876 if {[info exists _elem2dataobj($elem)]} { 877 foreach {mapx mapy} [GetAxes $_elem2dataobj($elem)] break 753 if {[info exists _elem2comp($elem)]} { 754 foreach {dataobj cname} [split $_elem2comp($elem) -] break 755 foreach {mapx mapy} [GetAxes $dataobj] break 878 756 } 879 757 … … 882 760 set y [$g axis transform $mapy $info(y)] 883 761 884 if {[info exists _elem2 dataobj($elem)]} {885 set dataobj $_elem2dataobj($elem)762 if {[info exists _elem2comp($elem)]} { 763 foreach {dataobj cname} [split $_elem2comp($elem) -] break 886 764 set yunits [$dataobj hints yunits] 887 765 set xunits [$dataobj hints xunits] … … 919 797 set mapx [$g element cget $elem -mapx] 920 798 set mapy [$g element cget $elem -mapy] 921 if {[info exists _elem2dataobj($elem)]} { 922 foreach {mapx mapy} [GetAxes $_elem2dataobj($elem)] break 799 if {[info exists _elem2comp($elem)]} { 800 foreach {dataobj cname} [split $_elem2comp($elem) -] break 801 foreach {mapx mapy} [GetAxes $dataobj] break 923 802 } 924 803 set allx [$g x2axis use] … … 1630 1509 return [format $fmt $value] 1631 1510 } 1511 1512 1513 # 1514 # BuildElements -- 1515 # 1516 # This procedure loads each data objects specified into the 1517 # graph. The data object may already be loaded (from the "add" 1518 # method which gets called first). The graph elements that 1519 # are created, are hidden. This allows the graph to account 1520 # for all datasets, even those not currently being displayed. 1521 # 1522 itcl::body Rappture::XyResult::BuildElements { dlist } { 1523 set g $itk_component(plot) 1524 1525 foreach label [array names _label2axis] { 1526 set axis $_label2axis($label) 1527 switch -- $axis { 1528 "x" - "x2" - "y" - "y2" { 1529 $g axis configure $axis -hide yes 1530 } 1531 default { 1532 $g axis delete $axis 1533 } 1534 } 1535 } 1536 array unset _label2axis 1537 array unset _limits 1538 1539 # Scan through all objects and create a list of all axes. 1540 # The first x-axis gets mapped to "x". The second, to "x2". 1541 # Beyond that, we must create new axes "x3", "x4", etc. 1542 # We do the same for y. 1543 1544 set anum(x) 0 1545 set anum(y) 0 1546 foreach dataobj $dlist { 1547 foreach axis {x y} { 1548 set label [$dataobj hints ${axis}label] 1549 if { $label == "" } { 1550 continue 1551 } 1552 # Collect the limits (if set for the axis) 1553 set min [$dataobj hints ${axis}min] 1554 set max [$dataobj hints ${axis}max] 1555 set tag ${label}-min 1556 if { $min != "" && ( ![info exists _limits($tag)] || 1557 $_limits($tag) > $min ) } { 1558 set _limits(tag) $min 1559 } 1560 set tag ${label}-max 1561 if { $max != "" && (![info exists _limits($tag)] || 1562 $_limits($tag) < $max) } { 1563 set _limits($tag) $max 1564 } 1565 if { [$dataobj hints ${axis}scale] == "log" } { 1566 set _limits(${axis}log) 1 1567 } 1568 if { ![info exists _label2axis($label)] } { 1569 switch [incr anum($axis)] { 1570 1 { set axisName $axis } 1571 2 { set axisName ${axis}2 } 1572 default { 1573 set axis $axis$anum($axis) 1574 catch {$g axis create $axisName} 1575 } 1576 } 1577 $g axis configure $axisName -title $label -hide no \ 1578 -checklimits no 1579 set _label2axis($label) $axisName 1580 1581 # If this axis has a description, add it as a tooltip 1582 set desc [string trim [$dataobj hints ${axis}desc]] 1583 Rappture::Tooltip::text $g-$axisName $desc 1584 } 1585 } 1586 } 1587 # Next set the axes based on what we've found. 1588 foreach label [array names _label2axis] { 1589 set logscale [info exists _limits(${label}log)] 1590 set amin "" 1591 if { [info exists _limits(${label}-min)] } { 1592 set amin $_limits(${label}-min) 1593 } 1594 set amax "" 1595 if { [info exists _limits(${label}-max)] } { 1596 set amax $_limits(${label}-max) 1597 } 1598 set axis $_label2axis($label) 1599 $g axis configure $axis \ 1600 -hide no -checklimits no \ 1601 -command [itcl::code $this GetFormattedValue $axis] \ 1602 -min $amin -max $amax -logscale $logscale 1603 $g axis bind $axis <Enter> \ 1604 [itcl::code $this Axis hilite $axis on] 1605 $g axis bind $axis <Leave> \ 1606 [itcl::code $this Axis hilite $axis off] 1607 $g axis bind $axis <ButtonPress-1> \ 1608 [itcl::code $this Axis click $axis %x %y] 1609 $g axis bind $axis <B1-Motion> \ 1610 [itcl::code $this Axis drag $axis %x %y] 1611 $g axis bind $axis <ButtonRelease-1> \ 1612 [itcl::code $this Axis release $axis %x %y] 1613 $g axis bind $axis <KeyPress> \ 1614 [list ::Rappture::Tooltip::tooltip cancel] 1615 } 1616 1617 # Create data elements and markers, but mark them as hidden. 1618 # The "add" method will un-hide them. 1619 set count 0 1620 foreach dataobj $dlist { 1621 set label [$dataobj hints label] 1622 array set params [$dataobj hints style] 1623 # Default 1624 if {[info exists params(-color)]} { 1625 set color params(-color) 1626 } else { 1627 set color black 1628 } 1629 if {[info exists parmas(-type)]} { 1630 set type $params(-type) 1631 } else { 1632 set type "line" 1633 } 1634 if {[info exists parmas(-barwidth)]} { 1635 set barwidth $params(-barwidth) 1636 } else { 1637 set barwidth 1.0 1638 } 1639 if {[info exists params(-width)]} { 1640 set lwidth $params(-width) 1641 } else { 1642 set lwidth 2 1643 } 1644 if {[info exists params(-linestyle)]} { 1645 set dashes $parmas(-linestyle) 1646 } else { 1647 set dashes "" 1648 } 1649 foreach {mapx mapy} [GetAxes $dataobj] break 1650 foreach comp [$dataobj components] { 1651 set tag $dataobj-$comp 1652 if { [info exists _comp2elem($tag)] } { 1653 set found($_comp2elem($tag)) 1 1654 lappend label2elem($label) $_comp2elem($tag) 1655 # Element already created for data object/component. 1656 continue 1657 } 1658 set xv [$dataobj mesh $comp] 1659 set yv [$dataobj values $comp] 1660 1661 if {([$xv length] <= 1) || ($lwidth == 0)} { 1662 set sym square 1663 set pixels 2 1664 } else { 1665 set sym "" 1666 set pixels 6 1667 } 1668 set elem "elem[incr _nextElement]" 1669 set _elem2comp($elem) $tag 1670 set _comp2elem($tag) $elem 1671 set found($_comp2elem($tag)) 1 1672 lappend label2elem($label) $elem 1673 switch -- $type { 1674 "line" - "scatter" { 1675 $g element create $elem \ 1676 -x $xv -y $yv \ 1677 -symbol $sym \ 1678 -pixels $pixels \ 1679 -linewidth $lwidth \ 1680 -label $label \ 1681 -color $color \ 1682 -dashes $dashes \ 1683 -mapx $mapx \ 1684 -mapy $mapy \ 1685 -hide yes 1686 } "bar" { 1687 $g bar create $elem \ 1688 -x $xv -y $yv \ 1689 -barwidth $barwidth \ 1690 -label $label \ 1691 -color $color \ 1692 -mapx $mapx \ 1693 -mapy $mapy \ 1694 -hide yes 1695 } 1696 } 1697 if { [$dataobj info class] == "Rappture::Curve" } { 1698 BuildMarkers $dataobj $elem 1699 } 1700 } 1701 } 1702 foreach elem [$g element names] { 1703 if { ![info exists found($elem)] } { 1704 $g element delete $elem 1705 } 1706 } 1707 ResetLegend 1708 }
Note: See TracChangeset
for help on using the changeset viewer.