Changeset 1342 for trunk/gui/scripts/numberresult.tcl
- Timestamp:
- Mar 18, 2009, 2:59:21 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/numberresult.tcl
r1077 r1342 89 89 90 90 array set _downloadPopup { 91 91 format csv 92 92 } 93 93 … … 96 96 97 97 itk_component add controls { 98 98 frame $itk_interior.cntls 99 99 } { 100 101 100 usual 101 rename -background -controlbackground controlBackground Background 102 102 } 103 103 pack $itk_component(controls) -side right -fill y 104 104 105 105 itk_component add reset { 106 107 108 109 106 button $itk_component(controls).reset \ 107 -borderwidth 1 -padx 1 -pady 1 \ 108 -bitmap [Rappture::icon reset] \ 109 -command [itcl::code $this _zoom reset] 110 110 } { 111 112 113 111 usual 112 ignore -borderwidth 113 rename -highlightbackground -controlbackground controlBackground Background 114 114 } 115 115 pack $itk_component(reset) -padx 4 -pady 4 … … 118 118 119 119 itk_component add plot { 120 121 122 120 blt::graph $itk_interior.plot \ 121 -highlightthickness 0 -plotpadx 0 -plotpady 0 \ 122 -rightmargin 10 123 123 } { 124 124 keep -background -foreground -cursor -font 125 125 } 126 126 pack $itk_component(plot) -expand yes -fill both 127 127 $itk_component(plot) pen configure activeLine \ 128 128 -symbol square -pixels 3 -linewidth 2 -color black 129 129 130 130 # … … 132 132 # 133 133 bind $itk_component(plot) <Motion> \ 134 134 [itcl::code $this _hilite at %x %y] 135 135 bind $itk_component(plot) <Leave> \ 136 136 [itcl::code $this _hilite off %x %y] 137 137 138 138 # … … 160 160 Rappture::Combobox $inner.format -width 15 -editable no 161 161 $inner.format choices insert end \ 162 163 164 165 166 167 168 169 170 171 162 "%.3g" "Auto" \ 163 "%.0f" "X" \ 164 "%.1f" "X.X" \ 165 "%.2f" "X.XX" \ 166 "%.3f" "X.XXX" \ 167 "%.6f" "X.XXXXXX" \ 168 "%.1e" "X.Xe+XX" \ 169 "%.2e" "X.XXe+XX" \ 170 "%.3e" "X.XXXe+XX" \ 171 "%.6e" "X.XXXXXXe+XX" 172 172 grid $inner.formatl -row 4 -column 0 -sticky e 173 173 grid $inner.format -row 4 -column 1 -sticky ew -pady 4 … … 176 176 frame $inner.scales 177 177 radiobutton $inner.scales.linear -text "Linear" \ 178 178 -variable [itcl::scope _axisPopup(scale)] -value "linear" 179 179 pack $inner.scales.linear -side left 180 180 radiobutton $inner.scales.log -text "Logarithmic" \ 181 181 -variable [itcl::scope _axisPopup(scale)] -value "log" 182 182 pack $inner.scales.log -side left 183 183 grid $inner.scalel -row 5 -column 0 -sticky e … … 185 185 186 186 foreach axis {x y} { 187 187 set _axisPopup(format-$axis) "%.3g" 188 188 } 189 189 _axis scale x linear … … 214 214 itcl::body Rappture::NumberResult::add {dataobj {settings ""}} { 215 215 array set params { 216 217 218 219 220 221 222 223 216 -color auto 217 -brightness 0 218 -width 1 219 -type "line" 220 -raise 0 221 -linestyle solid 222 -description "" 223 -param "" 224 224 } 225 225 foreach {opt val} $settings { 226 227 228 229 226 if {![info exists params($opt)]} { 227 error "bad setting \"$opt\": should be [join [lsort [array names params]] {, }]" 228 } 229 set params($opt) $val 230 230 } 231 231 232 232 # if type is set to "scatter", then override the width 233 233 if {"scatter" == $params(-type)} { 234 234 set params(-width) 0 235 235 } 236 236 237 237 if {$params(-color) == "auto" || $params(-color) == "autoreset"} { 238 238 set params(-color) #0000ff 239 239 } 240 240 241 241 # if -brightness is set, then update the color 242 242 if {$params(-brightness) != 0} { 243 244 245 246 247 248 249 250 251 252 253 254 243 set params(-color) [Rappture::color::brightness \ 244 $params(-color) $params(-brightness)] 245 246 set bg [$itk_component(plot) cget -plotbackground] 247 foreach {h s v} [Rappture::color::RGBtoHSV $bg] break 248 if {$v > 0.5} { 249 set params(-color) [Rappture::color::brightness_max \ 250 $params(-color) 0.8] 251 } else { 252 set params(-color) [Rappture::color::brightness_min \ 253 $params(-color) 0.2] 254 } 255 255 } 256 256 257 257 set pos [lsearch -exact $dataobj $_dlist] 258 258 if {$pos < 0} { 259 260 261 262 263 264 265 266 259 lappend _dlist $dataobj 260 set _dobj2color($dataobj) $params(-color) 261 set _dobj2width($dataobj) $params(-width) 262 set _dobj2raise($dataobj) $params(-raise) 263 set _dobj2desc($dataobj) $params(-description) 264 set _dobj2param($dataobj) $params(-param) 265 266 $_dispatcher event -idle !rebuild 267 267 } 268 268 } … … 278 278 set dlist $_dlist 279 279 foreach obj $dlist { 280 281 282 283 284 285 286 280 if {[info exists _dobj2raise($obj)] && $_dobj2raise($obj)} { 281 set i [lsearch -exact $dlist $obj] 282 if {$i >= 0} { 283 set dlist [lreplace $dlist $i $i] 284 lappend dlist $obj 285 } 286 } 287 287 } 288 288 return $dlist … … 297 297 itcl::body Rappture::NumberResult::delete {args} { 298 298 if {[llength $args] == 0} { 299 299 set args $_dlist 300 300 } 301 301 … … 303 303 set changed 0 304 304 foreach dataobj $args { 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 305 set pos [lsearch -exact $_dlist $dataobj] 306 if {$pos >= 0} { 307 set _dlist [lreplace $_dlist $pos $pos] 308 catch {unset _dobj2color($dataobj)} 309 catch {unset _dobj2width($dataobj)} 310 catch {unset _dobj2raise($dataobj)} 311 catch {unset _dobj2desc($dataobj)} 312 catch {unset _dobj2param($dataobj)} 313 foreach elem [array names _elem2dobj] { 314 if {$_elem2dobj($elem) == $dataobj} { 315 unset _elem2dobj($elem) 316 } 317 } 318 set changed 1 319 } 320 320 } 321 321 322 322 # if anything changed, then rebuild the plot 323 323 if {$changed} { 324 324 $_dispatcher event -idle !rebuild 325 325 } 326 326 } … … 339 339 lappend allx x ;# fix main x-axis too 340 340 foreach axis $allx { 341 341 _axis scale $axis linear 342 342 } 343 343 … … 345 345 lappend ally y ;# fix main y-axis too 346 346 foreach axis $ally { 347 347 _axis scale $axis linear 348 348 } 349 349 350 350 catch {unset _limits} 351 351 foreach xydata $args { 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 352 # find the axes for this data object (e.g., {x y2}) 353 foreach {map(x) map(y)} [_getAxes $xydata] break 354 355 foreach axis {x y} { 356 # get defaults for both linear and log scales 357 foreach type {lin log} { 358 # store results -- ex: _limits(x2log-min) 359 set id $map($axis)$type 360 if {$axis == "x"} { 361 set min [set max ""] 362 foreach {xlab xval} [lrange $_params 1 end] { 363 if {$type == "log"} { 364 set xval [expr {abs($xval)}] 365 if {$xval == 0} { 366 continue 367 } 368 } 369 if {"" == $min} { 370 set min [set max $xval] 371 } else { 372 if {$xval < $min} { set min $xval } 373 if {$xval > $max} { set max $xval } 374 } 375 } 376 } else { 377 set min [set max [_getValue $xydata y]] 378 } 379 380 if {"" != $min && "" != $max} { 381 if {![info exists _limits($id-min)]} { 382 set _limits($id-min) $min 383 set _limits($id-max) $max 384 } else { 385 if {$min < $_limits($id-min)} { 386 set _limits($id-min) $min 387 } 388 if {$max > $_limits($id-max)} { 389 set _limits($id-max) $max 390 } 391 } 392 } 393 } 394 } 395 395 } 396 396 _resetLimits … … 412 412 # 413 413 foreach type {lin log} { 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 414 # store results -- ex: _limits(x2log-min) 415 set id x$type 416 417 set min [set max ""] 418 foreach {xlab xval} [lrange $_params 1 end] { 419 if {$type == "log"} { 420 set xval [expr {abs($xval)}] 421 if {$xval == 0} { 422 continue 423 } 424 } 425 if {"" == $min} { 426 set min [set max $xval] 427 } else { 428 if {$xval < $min} { set min $xval } 429 if {$xval > $max} { set max $xval } 430 } 431 } 432 433 if {"" != $min && "" != $max} { 434 set _limits($id-min) $min 435 set _limits($id-max) $max 436 } 437 437 } 438 438 _resetLimits … … 448 448 catch {unset _xval2label} 449 449 foreach {xlab xval} [lrange $_params 1 end] { 450 451 452 453 450 set _xval2label($xval) $xlab 451 if {![string match $xval* $xlab]} { 452 set havenums 0 453 } 454 454 } 455 455 if {$havenums} { 456 457 458 459 460 461 456 set _xlabels 0 457 $itk_component(plot) xaxis configure -command "" -majorticks "" 458 if {![$itk_component(plot) axis cget x -logscale]} { 459 $itk_component(plot) xaxis configure \ 460 -command [itcl::code $this _axis format x] 461 } 462 462 } else { 463 464 465 466 463 set _xlabels 1 464 $itk_component(plot) xaxis configure \ 465 -command [itcl::code $this _axis format x] \ 466 -majorticks [lsort -real [array names _xval2label]] 467 467 } 468 468 … … 482 482 itcl::body Rappture::NumberResult::download {option args} { 483 483 switch $option { 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 484 coming { 485 # nothing to do 486 } 487 controls { 488 set popup .xyresultdownload 489 if {![winfo exists .xyresultdownload]} { 490 # if we haven't created the popup yet, do it now 491 Rappture::Balloon $popup -title "[Rappture::filexfer::label downloadWord] as..." 492 set inner [$popup component inner] 493 label $inner.summary -text "" -anchor w 494 pack $inner.summary -side top 495 radiobutton $inner.csv -text "Data as Comma-Separated Values" \ 496 -variable Rappture::NumberResult::_downloadPopup(format) \ 497 -value csv 498 pack $inner.csv -anchor w 499 radiobutton $inner.pdf -text "Image as PDF/PostScript" \ 500 -variable Rappture::NumberResult::_downloadPopup(format) \ 501 -value pdf 502 pack $inner.pdf -anchor w 503 button $inner.go -text [Rappture::filexfer::label download] \ 504 -command [lindex $args 0] 505 pack $inner.go -pady 4 506 } else { 507 set inner [$popup component inner] 508 } 509 set num [llength [get]] 510 set num [expr {($num == 1) ? "1 result" : "$num results"}] 511 $inner.summary configure -text "[Rappture::filexfer::label downloadWord] $num in the following format:" 512 update idletasks ;# fix initial sizes 513 return $popup 514 } 515 now { 516 set popup .xyresultdownload 517 if {[winfo exists .xyresultdownload]} { 518 $popup deactivate 519 } 520 switch -- $_downloadPopup(format) { 521 csv { 522 # March through the values in order and report 523 # all data points 524 set csvdata "" 525 set xtitle [$itk_component(plot) xaxis cget -title] 526 set ytitle [$itk_component(plot) yaxis cget -title] 527 528 set desc "" 529 set dataobj [lindex [get] end] 530 531 # the "Simulation" axis shows all values 532 # -- no need for assumptions 533 if {$xtitle != "Simulation" 534 && [info exists _dobj2desc($dataobj)]} { 535 foreach line [split $_dobj2desc($dataobj) \n] { 536 # skip the current axis and the Simulation axis 537 # Other values show assumptions about values reported 538 if {[string match "$xtitle =*" $line] 539 || [string match "Simulation =*" $line]} { 540 continue 541 } 542 set indent [expr {("" == $desc) ? "for:" : " "}] 543 append desc " $indent $line\n" 544 } 545 } 546 if {[string length $desc] > 0} { 547 append csvdata "[string repeat - 60]\n" 548 append csvdata $desc 549 append csvdata "[string repeat - 60]\n" 550 } 551 552 append csvdata "$xtitle, $ytitle\n" 553 foreach xval [lsort -real [array names _xval2label]] { 554 set dataobj "" 555 set param [list $_xval2label($xval) $xval] 556 foreach obj $_dlist { 557 if {[info exists _dobj2param($obj)] 558 && [string equal $_dobj2param($obj) $param]} { 559 set dataobj $obj 560 break 561 } 562 } 563 if {"" != $dataobj} { 564 set yval [$dataobj get current] 565 append csvdata "$_xval2label($xval), $yval\n" 566 } 567 } 568 return [list .txt $csvdata] 569 } 570 pdf { 571 set psdata [$itk_component(plot) postscript output -decorations no -maxpect 1] 572 573 set cmds { 574 set fout "xy[pid].pdf" 575 exec ps2pdf - $fout << $psdata 576 577 set fid [open $fout r] 578 fconfigure $fid -translation binary -encoding binary 579 set pdfdata [read $fid] 580 close $fid 581 582 file delete -force $fout 583 } 584 if {[catch $cmds result] == 0} { 585 return [list .pdf $pdfdata] 586 } 587 return [list .ps $psdata] 588 } 589 } 590 } 591 default { 592 error "bad option \"$option\": should be coming, controls, now" 593 } 594 594 } 595 595 } … … 608 608 eval $g element delete [$g element names] 609 609 foreach axis [$g axis names] { 610 610 $g axis configure $axis -hide yes 611 611 } 612 612 catch {unset _label2axis} … … 621 621 set anum(y) 0 622 622 foreach xydata [get] { 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 623 foreach ax {x y} { 624 set label [_getInfo about.label $xydata ${ax}] 625 if {"" != $label} { 626 if {![info exists _label2axis($ax-$label)]} { 627 switch [incr anum($ax)] { 628 1 { set axis $ax } 629 2 { set axis ${ax}2 } 630 default { 631 set axis $ax$anum($ax) 632 catch {$g axis create $axis} 633 } 634 } 635 $g axis configure $axis -title $label -hide no 636 set _label2axis($ax-$label) $axis 637 638 # if this axis has a description, add it as a tooltip 639 set desc [string trim [_getInfo about.description $xydata ${ax}]] 640 Rappture::Tooltip::text $g-$axis $desc 641 } 642 } 643 } 644 644 } 645 645 … … 650 650 set all "" 651 651 foreach ax {x y} { 652 653 654 655 656 657 658 659 660 661 662 652 lappend all $ax 653 654 set extra "" 655 for {set i 2} {$i <= $anum($ax)} {incr i} { 656 lappend extra ${ax}$i 657 } 658 eval lappend all $extra 659 $g ${ax}2axis use $extra 660 if {$ax == "y"} { 661 $g configure -rightmargin [expr {($extra == "") ? 10 : 0}] 662 } 663 663 } 664 664 665 665 foreach axis $all { 666 667 668 669 670 671 672 673 674 675 676 677 678 679 666 set _axisPopup(format-$axis) "%.3g" 667 668 $g axis bind $axis <Enter> \ 669 [itcl::code $this _axis hilite $axis on] 670 $g axis bind $axis <Leave> \ 671 [itcl::code $this _axis hilite $axis off] 672 $g axis bind $axis <ButtonPress> \ 673 [itcl::code $this _axis click $axis %x %y] 674 $g axis bind $axis <B1-Motion> \ 675 [itcl::code $this _axis drag $axis %x %y] 676 $g axis bind $axis <ButtonRelease> \ 677 [itcl::code $this _axis release $axis %x %y] 678 $g axis bind $axis <KeyPress> \ 679 [list ::Rappture::Tooltip::tooltip cancel] 680 680 } 681 681 … … 685 685 set count 0 686 686 foreach xydata $_dlist { 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 687 set label [$xydata get about.label] 688 foreach {mapx mapy} [_getAxes $xydata] break 689 690 foreach {xv yv} [_getValue $xydata] break 691 692 if {[info exists _dobj2color($xydata)]} { 693 set color $_dobj2color($xydata) 694 } else { 695 set color [$xydata get about.color] 696 if {"" == $color} { 697 set color $itk_option(-activecolor) 698 } 699 } 700 701 set sym square 702 set pixels 6 703 704 set elem "elem[incr count]" 705 set _elem2dobj($elem) $xydata 706 707 $g element create $elem -x $xv -y $yv \ 708 -symbol $sym -pixels $pixels -label $label \ 709 -color $color -mapx $mapx -mapy $mapy 710 710 } 711 711 } … … 728 728 # 729 729 foreach axis [$g axis names] { 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 730 if {[info exists _limits(${axis}lin-min)]} { 731 set log [$g axis cget $axis -logscale] 732 if {$log} { 733 set min $_limits(${axis}log-min) 734 if {$min == 0} { set min 1 } 735 set max $_limits(${axis}log-max) 736 if {$max == 0} { set max 1 } 737 738 if {$min == $max} { 739 set logmin [expr {floor(log10(abs(0.9*$min)))}] 740 set logmax [expr {ceil(log10(abs(1.1*$max)))}] 741 } else { 742 set logmin [expr {floor(log10(abs($min)))}] 743 set logmax [expr {ceil(log10(abs($max)))}] 744 if {[string match y* $axis]} { 745 # add a little padding 746 set delta [expr {$logmax-$logmin}] 747 if {$delta == 0} { set delta 1 } 748 set logmin [expr {$logmin-0.05*$delta}] 749 set logmax [expr {$logmax+0.05*$delta}] 750 } 751 } 752 if {$logmin < -300} { 753 set min 1e-300 754 } elseif {$logmin > 300} { 755 set min 1e+300 756 } else { 757 set min [expr {pow(10.0,$logmin)}] 758 } 759 760 if {$logmax < -300} { 761 set max 1e-300 762 } elseif {$logmax > 300} { 763 set max 1e+300 764 } else { 765 set max [expr {pow(10.0,$logmax)}] 766 } 767 } else { 768 set min $_limits(${axis}lin-min) 769 set max $_limits(${axis}lin-max) 770 771 # add a little padding 772 set delta [expr {$max-$min}] 773 set min [expr {$min-0.05*$delta}] 774 set max [expr {$max+0.05*$delta}] 775 } 776 if {$min < $max} { 777 $g axis configure $axis -min $min -max $max 778 } else { 779 $g axis configure $axis -min "" -max "" 780 } 781 } else { 782 $g axis configure $axis -min "" -max "" 783 } 784 784 } 785 785 } … … 793 793 itcl::body Rappture::NumberResult::_zoom {option args} { 794 794 switch -- $option { 795 796 797 795 reset { 796 _resetLimits 797 } 798 798 } 799 799 } … … 810 810 set elem "" 811 811 if {$state == "at"} { 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 812 if {[$g element closest $x $y info -interpolate yes]} { 813 # for dealing with xy line plots 814 set elem $info(name) 815 foreach {mapx mapy} [_getAxes $_elem2dobj($elem)] break 816 817 # search again for an exact point -- this time don't interpolate 818 set tip "" 819 if {[$g element closest $x $y info -interpolate no] 820 && $info(name) == $elem} { 821 set x [$g axis transform $mapx $info(x)] 822 set y [$g axis transform $mapy $info(y)] 823 824 if {[info exists _elem2dobj($elem)]} { 825 set dataobj $_elem2dobj($elem) 826 set tip [_getInfo about.label $dataobj y] 827 if {[info exists info(y)]} { 828 set val [_axis format y dummy $info(y)] 829 set units [_getInfo units $dataobj y] 830 append tip "\n$val$units" 831 832 if {[info exists _dobj2param($dataobj)]} { 833 set val [lindex $_dobj2param($dataobj) 0] 834 append tip " @ $val" 835 } 836 } 837 set tip [string trim $tip] 838 } 839 } 840 set state 1 841 } elseif {[$g element closest $x $y info -interpolate no]} { 842 # for dealing with xy scatter plot 843 set elem $info(name) 844 foreach {mapx mapy} [_getAxes $_elem2dobj($elem)] break 845 846 # search again for an exact point -- this time don't interpolate 847 set tip "" 848 if {$info(name) == $elem} { 849 set x [$g axis transform $mapx $info(x)] 850 set y [$g axis transform $mapy $info(y)] 851 852 if {[info exists _elem2dobj($elem)]} { 853 set dataobj $_elem2dobj($elem) 854 set tip [_getInfo about.label $dataobj y] 855 if {[info exists info(y)]} { 856 set val [_axis format y dummy $info(y)] 857 set units [_getInfo units $dataobj y] 858 append tip "\n$val$units" 859 860 if {[info exists _dobj2param($dataobj)]} { 861 set val [lindex $_dobj2param($dataobj) 0] 862 append tip " @ $val" 863 } 864 } 865 set tip [string trim $tip] 866 } 867 } 868 set state 1 869 } else { 870 set state 0 871 } 872 872 } 873 873 874 874 if {$state} { 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 875 # 876 # Highlight ON: 877 # - activate trace 878 # - multiple axes? dim other axes 879 # - pop up tooltip about data 880 # 881 if {$_hilite(elem) != "" && $_hilite(elem) != $elem} { 882 $g element deactivate $_hilite(elem) 883 $g crosshairs configure -hide yes 884 Rappture::Tooltip::tooltip cancel 885 } 886 $g element activate $elem 887 set _hilite(elem) $elem 888 889 set dlist [$g element show] 890 set i [lsearch -exact $dlist $elem] 891 if {$i >= 0} { 892 set dlist [lreplace $dlist $i $i] 893 lappend dlist $elem 894 $g element show $dlist 895 } 896 897 foreach {mapx mapy} [_getAxes $_elem2dobj($elem)] break 898 899 set allx [$g x2axis use] 900 if {[llength $allx] > 0} { 901 lappend allx x ;# fix main x-axis too 902 foreach axis $allx { 903 if {$axis == $mapx} { 904 $g axis configure $axis -color $itk_option(-foreground) \ 905 -titlecolor $itk_option(-foreground) 906 } else { 907 $g axis configure $axis -color $itk_option(-dimcolor) \ 908 -titlecolor $itk_option(-dimcolor) 909 } 910 } 911 } 912 set ally [$g y2axis use] 913 if {[llength $ally] > 0} { 914 lappend ally y ;# fix main y-axis too 915 foreach axis $ally { 916 if {$axis == $mapy} { 917 $g axis configure $axis -color $itk_option(-foreground) \ 918 -titlecolor $itk_option(-foreground) 919 } else { 920 $g axis configure $axis -color $itk_option(-dimcolor) \ 921 -titlecolor $itk_option(-dimcolor) 922 } 923 } 924 } 925 926 if {"" != $tip} { 927 $g crosshairs configure -hide no -position @$x,$y 928 929 if {$x > 0.5*[winfo width $g]} { 930 if {$x < 4} { 931 set tipx "-0" 932 } else { 933 set tipx "-[expr {$x-4}]" ;# move tooltip to the left 934 } 935 } else { 936 if {$x < -4} { 937 set tipx "+0" 938 } else { 939 set tipx "+[expr {$x+4}]" ;# move tooltip to the right 940 } 941 } 942 if {$y > 0.5*[winfo height $g]} { 943 if {$y < 4} { 944 set tipy "-0" 945 } else { 946 set tipy "-[expr {$y-4}]" ;# move tooltip to the top 947 } 948 } else { 949 if {$y < -4} { 950 set tipy "+0" 951 } else { 952 set tipy "+[expr {$y+4}]" ;# move tooltip to the bottom 953 } 954 } 955 Rappture::Tooltip::text $g $tip 956 Rappture::Tooltip::tooltip show $g $tipx,$tipy 957 } 958 958 } else { 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 959 # 960 # Highlight OFF: 961 # - deactivate (color back to normal) 962 # - put all axes back to normal color 963 # - take down tooltip 964 # 965 if {"" != $_hilite(elem)} { 966 $g element deactivate $_hilite(elem) 967 968 set allx [$g x2axis use] 969 if {[llength $allx] > 0} { 970 lappend allx x ;# fix main x-axis too 971 foreach axis $allx { 972 $g axis configure $axis -color $itk_option(-foreground) \ 973 -titlecolor $itk_option(-foreground) 974 } 975 } 976 977 set ally [$g y2axis use] 978 if {[llength $ally] > 0} { 979 lappend ally y ;# fix main y-axis too 980 foreach axis $ally { 981 $g axis configure $axis -color $itk_option(-foreground) \ 982 -titlecolor $itk_option(-foreground) 983 } 984 } 985 } 986 987 $g crosshairs configure -hide yes 988 989 # only cancel in plotting area or we'll mess up axes 990 if {[$g inside $x $y]} { 991 Rappture::Tooltip::tooltip cancel 992 } 993 994 # there is no currently highlighted element 995 set _hilite(elem) "" 996 996 } 997 997 } … … 1018 1018 1019 1019 switch -- $option { 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1020 hilite { 1021 if {[llength $args] != 2} { 1022 error "wrong # args: should be \"_axis hilite axis state\"" 1023 } 1024 set g $itk_component(plot) 1025 set axis [lindex $args 0] 1026 set state [lindex $args 1] 1027 1028 if {$state} { 1029 $g axis configure $axis \ 1030 -color $itk_option(-activecolor) \ 1031 -titlecolor $itk_option(-activecolor) 1032 1033 set x [expr {[winfo pointerx $g]+4}] 1034 set y [expr {[winfo pointery $g]+4}] 1035 Rappture::Tooltip::tooltip pending $g-$axis @$x,$y 1036 } else { 1037 $g axis configure $axis \ 1038 -color $itk_option(-foreground) \ 1039 -titlecolor $itk_option(-foreground) 1040 Rappture::Tooltip::tooltip cancel 1041 } 1042 } 1043 click { 1044 if {[llength $args] != 3} { 1045 error "wrong # args: should be \"_axis click axis x y\"" 1046 } 1047 set axis [lindex $args 0] 1048 set x [lindex $args 1] 1049 set y [lindex $args 2] 1050 set g $itk_component(plot) 1051 1052 set _axis(moved) 0 1053 set _axis(click-x) $x 1054 set _axis(click-y) $y 1055 foreach {min max} [$g axis limits $axis] break 1056 set _axis(min0) $min 1057 set _axis(max0) $max 1058 Rappture::Tooltip::tooltip cancel 1059 } 1060 drag { 1061 if {[llength $args] != 3} { 1062 error "wrong # args: should be \"_axis drag axis x y\"" 1063 } 1064 if {![info exists _axis(moved)]} { 1065 return ;# must have skipped click event -- ignore 1066 } 1067 set axis [lindex $args 0] 1068 set x [lindex $args 1] 1069 set y [lindex $args 2] 1070 set g $itk_component(plot) 1071 1072 if {[info exists _axis(click-x)] && [info exists _axis(click-y)]} { 1073 foreach {x0 y0 pw ph} [$g extents plotarea] break 1074 switch -glob $axis { 1075 x* { 1076 set pix $x 1077 set pix0 $_axis(click-x) 1078 set pixmin $x0 1079 set pixmax [expr {$x0+$pw}] 1080 } 1081 y* { 1082 set pix $y 1083 set pix0 $_axis(click-y) 1084 set pixmin [expr {$y0+$ph}] 1085 set pixmax $y0 1086 } 1087 } 1088 set log [$g axis cget $axis -logscale] 1089 set min $_axis(min0) 1090 set max $_axis(max0) 1091 set dpix [expr {abs($pix-$pix0)}] 1092 set v0 [$g axis invtransform $axis $pixmin] 1093 set v1 [$g axis invtransform $axis [expr {$pixmin+$dpix}]] 1094 if {$log} { 1095 set v0 [expr {log10($v0)}] 1096 set v1 [expr {log10($v1)}] 1097 set min [expr {log10($min)}] 1098 set max [expr {log10($max)}] 1099 } 1100 1101 if {$pix > $pix0} { 1102 set delta [expr {$v1-$v0}] 1103 } else { 1104 set delta [expr {$v0-$v1}] 1105 } 1106 set min [expr {$min-$delta}] 1107 set max [expr {$max-$delta}] 1108 if {$log} { 1109 set min [expr {pow(10.0,$min)}] 1110 set max [expr {pow(10.0,$max)}] 1111 } 1112 $g axis configure $axis -min $min -max $max 1113 1114 # move axis, don't edit on release 1115 set _axis(move) 1 1116 } 1117 } 1118 release { 1119 if {[llength $args] != 3} { 1120 error "wrong # args: should be \"_axis release axis x y\"" 1121 } 1122 if {![info exists _axis(moved)]} { 1123 return ;# must have skipped click event -- ignore 1124 } 1125 set axis [lindex $args 0] 1126 set x [lindex $args 1] 1127 set y [lindex $args 2] 1128 1129 if {!$_axis(moved)} { 1130 # small movement? then treat as click -- pop up axis editor 1131 set dx [expr {abs($x-$_axis(click-x))}] 1132 set dy [expr {abs($y-$_axis(click-y))}] 1133 if {$dx < 2 && $dy < 2} { 1134 _axis edit $axis 1135 } 1136 } else { 1137 # one last movement 1138 _axis drag $axis $x $y 1139 } 1140 catch {unset _axis} 1141 } 1142 edit { 1143 if {[llength $args] != 1} { 1144 error "wrong # args: should be \"_axis edit axis\"" 1145 } 1146 set axis [lindex $args 0] 1147 set _axisPopup(current) $axis 1148 1149 # apply last value when deactivating 1150 $itk_component(hull).axes configure -deactivatecommand \ 1151 [itcl::code $this _axis changed $axis focus] 1152 1153 # fix axis label controls... 1154 set label [$itk_component(plot) axis cget $axis -title] 1155 $inner.label delete 0 end 1156 $inner.label insert end $label 1157 bind $inner.label <KeyPress-Return> \ 1158 [itcl::code $this _axis changed $axis label] 1159 bind $inner.label <FocusOut> \ 1160 [itcl::code $this _axis changed $axis label] 1161 1162 # fix min/max controls... 1163 foreach {min max} [$itk_component(plot) axis limits $axis] break 1164 $inner.min delete 0 end 1165 $inner.min insert end $min 1166 bind $inner.min <KeyPress-Return> \ 1167 [itcl::code $this _axis changed $axis min] 1168 bind $inner.min <FocusOut> \ 1169 [itcl::code $this _axis changed $axis min] 1170 1171 $inner.max delete 0 end 1172 $inner.max insert end $max 1173 bind $inner.max <KeyPress-Return> \ 1174 [itcl::code $this _axis changed $axis max] 1175 bind $inner.max <FocusOut> \ 1176 [itcl::code $this _axis changed $axis max] 1177 1178 # fix format control... 1179 set fmts [$inner.format choices get -value] 1180 set i [lsearch -exact $fmts $_axisPopup(format-$axis)] 1181 if {$i < 0} { set i 0 } ;# use Auto choice 1182 $inner.format value [$inner.format choices get -label $i] 1183 1184 bind $inner.format <<Value>> \ 1185 [itcl::code $this _axis changed $axis format] 1186 1187 # fix scale control... 1188 if {[$itk_component(plot) axis cget $axis -logscale]} { 1189 set _axisPopup(scale) "log" 1190 $inner.format configure -state disabled 1191 } else { 1192 set _axisPopup(scale) "linear" 1193 $inner.format configure -state normal 1194 } 1195 $inner.scales.linear configure \ 1196 -command [itcl::code $this _axis changed $axis scale] 1197 $inner.scales.log configure \ 1198 -command [itcl::code $this _axis changed $axis scale] 1199 1200 # 1201 # Figure out where the window should pop up. 1202 # 1203 set x [winfo rootx $itk_component(plot)] 1204 set y [winfo rooty $itk_component(plot)] 1205 set w [winfo width $itk_component(plot)] 1206 set h [winfo height $itk_component(plot)] 1207 foreach {x0 y0 pw ph} [$itk_component(plot) extents plotarea] break 1208 switch -glob -- $axis { 1209 x { 1210 set x [expr {round($x + $x0+0.5*$pw)}] 1211 set y [expr {round($y + $y0+$ph + 0.5*($h-$y0-$ph))}] 1212 set dir "above" 1213 } 1214 x* { 1215 set x [expr {round($x + $x0+0.5*$pw)}] 1216 set dir "below" 1217 set allx [$itk_component(plot) x2axis use] 1218 set max [llength $allx] 1219 set i [lsearch -exact $allx $axis] 1220 set y [expr {round($y + ($i+0.5)*$y0/double($max))}] 1221 } 1222 y { 1223 set x [expr {round($x + 0.5*$x0)}] 1224 set y [expr {round($y + $y0+0.5*$ph)}] 1225 set dir "right" 1226 } 1227 y* { 1228 set y [expr {round($y + $y0+0.5*$ph)}] 1229 set dir "left" 1230 set ally [$itk_component(plot) y2axis use] 1231 set max [llength $ally] 1232 set i [lsearch -exact $ally $axis] 1233 set y [expr {round($y + ($i+0.5)*$y0/double($max))}] 1234 set x [expr {round($x+$x0+$pw + ($i+0.5)*($w-$x0-$pw)/double($max))}] 1235 } 1236 } 1237 $itk_component(hull).axes activate @$x,$y $dir 1238 } 1239 changed { 1240 if {[llength $args] != 2} { 1241 error "wrong # args: should be \"_axis changed axis what\"" 1242 } 1243 set axis [lindex $args 0] 1244 set what [lindex $args 1] 1245 if {$what == "focus"} { 1246 set what [focus] 1247 if {[winfo exists $what]} { 1248 set what [winfo name $what] 1249 } 1250 } 1251 1252 switch -- $what { 1253 label { 1254 set val [$inner.label get] 1255 $itk_component(plot) axis configure $axis -title $val 1256 } 1257 min { 1258 set val [$inner.min get] 1259 if {![string is double -strict $val]} { 1260 Rappture::Tooltip::cue $inner.min "Must be a number" 1261 bell 1262 return 1263 } 1264 1265 set max [lindex [$itk_component(plot) axis limits $axis] 1] 1266 if {$val >= $max} { 1267 Rappture::Tooltip::cue $inner.min "Must be <= max ($max)" 1268 bell 1269 return 1270 } 1271 catch { 1272 # can fail in log mode 1273 $itk_component(plot) axis configure $axis -min $val 1274 } 1275 foreach {min max} [$itk_component(plot) axis limits $axis] break 1276 $inner.min delete 0 end 1277 $inner.min insert end $min 1278 } 1279 max { 1280 set val [$inner.max get] 1281 if {![string is double -strict $val]} { 1282 Rappture::Tooltip::cue $inner.max "Should be a number" 1283 bell 1284 return 1285 } 1286 1287 set min [lindex [$itk_component(plot) axis limits $axis] 0] 1288 if {$val <= $min} { 1289 Rappture::Tooltip::cue $inner.max "Must be >= min ($min)" 1290 bell 1291 return 1292 } 1293 catch { 1294 # can fail in log mode 1295 $itk_component(plot) axis configure $axis -max $val 1296 } 1297 foreach {min max} [$itk_component(plot) axis limits $axis] break 1298 $inner.max delete 0 end 1299 $inner.max insert end $max 1300 } 1301 format { 1302 set fmt [$inner.format translate [$inner.format value]] 1303 set _axisPopup(format-$axis) $fmt 1304 1305 # force a refresh 1306 $itk_component(plot) axis configure $axis -min \ 1307 [$itk_component(plot) axis cget $axis -min] 1308 } 1309 scale { 1310 _axis scale $axis $_axisPopup(scale) 1311 1312 if {$_axisPopup(scale) == "log"} { 1313 $inner.format configure -state disabled 1314 } else { 1315 $inner.format configure -state normal 1316 } 1317 1318 foreach {min max} [$itk_component(plot) axis limits $axis] break 1319 $inner.min delete 0 end 1320 $inner.min insert end $min 1321 $inner.max delete 0 end 1322 $inner.max insert end $max 1323 } 1324 default { 1325 # be lenient so we can handle the "focus" case 1326 } 1327 } 1328 } 1329 format { 1330 if {[llength $args] != 3} { 1331 error "wrong # args: should be \"_axis format axis widget value\"" 1332 } 1333 set axis [lindex $args 0] 1334 set value [lindex $args 2] 1335 1336 if {$axis == "x" && $_xlabels 1337 && [info exists _xval2label($value)]} { 1338 return $_xval2label($value) 1339 } 1340 if {[$itk_component(plot) axis cget $axis -logscale]} { 1341 set fmt "%.3g" 1342 } else { 1343 set fmt $_axisPopup(format-$axis) 1344 } 1345 return [format $fmt $value] 1346 } 1347 scale { 1348 if {[llength $args] != 2} { 1349 error "wrong # args: should be \"_axis scale axis type\"" 1350 } 1351 set axis [lindex $args 0] 1352 set type [lindex $args 1] 1353 1354 if {$type == "log"} { 1355 catch {$itk_component(plot) axis configure $axis -logscale 1} 1356 # leave format alone in log mode 1357 $itk_component(plot) axis configure $axis -command "" 1358 } else { 1359 catch {$itk_component(plot) axis configure $axis -logscale 0} 1360 # use special formatting for linear mode 1361 $itk_component(plot) axis configure $axis -command \ 1362 [itcl::code $this _axis format $axis] 1363 } 1364 } 1365 default { 1366 error "bad option \"$option\": should be changed, edit, hilite, or format" 1367 } 1368 1368 } 1369 1369 } … … 1379 1379 # rebuild if needed, so we know about the axes 1380 1380 if {[$_dispatcher ispending !rebuild]} { 1381 1382 1381 $_dispatcher cancel !rebuild 1382 $_dispatcher event -now !rebuild 1383 1383 } 1384 1384 … … 1386 1386 set xlabel "Simulation #" 1387 1387 if {[info exists _label2axis(x-$xlabel)]} { 1388 1388 set mapx $_label2axis(x-$xlabel) 1389 1389 } else { 1390 1390 set mapx "x" 1391 1391 } 1392 1392 … … 1394 1394 set ylabel [$xydata get about.label] 1395 1395 if {[info exists _label2axis(y-$ylabel)]} { 1396 1396 set mapy $_label2axis(y-$ylabel) 1397 1397 } else { 1398 1398 set mapy "y" 1399 1399 } 1400 1400 … … 1410 1410 itcl::body Rappture::NumberResult::_getValue {xydata {which both}} { 1411 1411 if {[info exists _dobj2param($xydata)]} { 1412 1412 set x [lindex $_dobj2param($xydata) 1] 1413 1413 } else { 1414 1414 set x 0 1415 1415 } 1416 1416 … … 1418 1418 set units [$xydata get units] 1419 1419 if {$units != ""} { 1420 1420 set y [Rappture::Units::convert $y -context $units -to $units -units off] 1421 1421 } 1422 1422 if {![string is double -strict $y]} { 1423 1423 set y 0 1424 1424 } 1425 1425 1426 1426 switch -- $which { 1427 1428 1429 1430 1427 x { return $x } 1428 y { return $y } 1429 both { return [list $x $y] } 1430 default { error "bad value \"$which\": should be x, y, both" } 1431 1431 } 1432 1432 } … … 1442 1442 set y [$xydata get $what] 1443 1443 if {$what == "about.label"} { 1444 1445 1446 1447 1444 set units [$xydata get units] 1445 if {"" != $units} { 1446 append y " ($units)" 1447 } 1448 1448 } 1449 1449 1450 1450 switch -- $which { 1451 1452 1453 1454 1451 x { return $x } 1452 y { return $y } 1453 both { return [list $x $y] } 1454 default { error "bad value \"$which\": should be x, y, both" } 1455 1455 } 1456 1456 } … … 1461 1461 itcl::configbody Rappture::NumberResult::gridcolor { 1462 1462 if {"" == $itk_option(-gridcolor)} { 1463 1463 $itk_component(plot) grid off 1464 1464 } else { 1465 1466 1467 } 1468 } 1465 $itk_component(plot) grid configure -color $itk_option(-gridcolor) 1466 $itk_component(plot) grid on 1467 } 1468 }
Note: See TracChangeset
for help on using the changeset viewer.