From 980986d5e922bafb365ef54aa3788eace11eeefc Mon Sep 17 00:00:00 2001 From: William Joye Date: Tue, 18 Apr 2017 17:34:01 -0400 Subject: enhance graphs --- ds9/library/backup.tcl | 3 + ds9/library/bin.tcl | 1 - ds9/library/ds9.tcl | 2 +- ds9/library/graph.tcl | 227 +++++++++++++++++++++++++++++++++++++++------- ds9/library/layout.tcl | 14 ++- ds9/library/manalysis.tcl | 4 + ds9/library/mview.tcl | 69 ++++++++------ ds9/library/prefs.tcl | 3 + 8 files changed, 252 insertions(+), 71 deletions(-) diff --git a/ds9/library/backup.tcl b/ds9/library/backup.tcl index f27b984..008f2de 100644 --- a/ds9/library/backup.tcl +++ b/ds9/library/backup.tcl @@ -665,6 +665,9 @@ proc BackupGUI {ch} { puts $ch "global pime" puts $ch "array set pime \{ [array get pime] \}" + global graph + puts $ch "global graph" + puts $ch "array set graph \{ [array get graph] \}" global pgraph puts $ch "global pgraph" puts $ch "array set pgraph \{ [array get pgraph] \}" diff --git a/ds9/library/bin.tcl b/ds9/library/bin.tcl index cdcfbe5..11cb5f3 100644 --- a/ds9/library/bin.tcl +++ b/ds9/library/bin.tcl @@ -198,7 +198,6 @@ proc BinDialog {} { global ds9 # see if we already have a window visible - if {[winfo exists $ibin(top)]} { raise $ibin(top) return diff --git a/ds9/library/ds9.tcl b/ds9/library/ds9.tcl index d928e35..40daef3 100755 --- a/ds9/library/ds9.tcl +++ b/ds9/library/ds9.tcl @@ -64,7 +64,7 @@ proc DS9Def {} { } set ds9(menu,size,frame,goto) [expr $ds9(menu,start)+0] set ds9(menu,size,frame,active) [expr $ds9(menu,start)+3] - set ds9(menu,size,analysis) [expr $ds9(menu,start)+35] + set ds9(menu,size,analysis) [expr $ds9(menu,start)+37] set ds9(menu,size,wrap) 20 set ds9(display) single diff --git a/ds9/library/graph.tcl b/ds9/library/graph.tcl index 91ffb62..c94752c 100644 --- a/ds9/library/graph.tcl +++ b/ds9/library/graph.tcl @@ -7,12 +7,17 @@ package provide DS9 1.0 proc GraphDef {} { global igraph global pgraph + global graph + + set igraph(top) .grph + set igraph(mb) .grphmb set igraph(horz,id) 0 set igraph(vert,id) 0 set igraph(size) 150 - set igraph(gap,x) 50 +# set igraph(gap,x) 50 + set igraph(gap,x) 0 set igraph(gap,y) 25 set igraph(x,min) 0 @@ -28,12 +33,16 @@ proc GraphDef {} { blt::vector create graphVertX graphVertY blt::vector create histX histY - # prefs only - set pgraph(horz,grid) 1 - set pgraph(horz,log) false - set pgraph(thick) 1 - set pgraph(vert,grid) 1 - set pgraph(vert,log) false + set graph(horz,grid) 1 + set graph(horz,log) false + set graph(horz,thick) 1 + set graph(horz,method) average + set graph(vert,grid) 1 + set graph(vert,log) false + set graph(vert,thick) 1 + set graph(vert,method) average + + array set pgraph [array get graph] } proc CreateGraphs {} { @@ -48,8 +57,9 @@ proc CreateGraphs {} { -takefocus 0 \ -background $ds9(bg) \ -highlightthickness 0 \ - -plotborderwidth 2 \ - -plotrelief groove \ + -borderwidth 0 \ + -plotborderwidth 1 \ + -plotrelief solid \ -plotbackground $ds9(bg) \ -font [font actual TkDefaultFont] \ ] @@ -63,6 +73,7 @@ proc CreateGraphs {} { $ds9(graph,horz) x2axis configure -hide yes $ds9(graph,horz) yaxis configure -hide yes $ds9(graph,horz) y2axis configure -hide no -bg $ds9(bg) \ + -exterior no \ -tickfont [font actual TkDefaultFont] $ds9(graph,horz) element create line1 -xdata graphHorzX -ydata graphHorzY \ @@ -86,8 +97,9 @@ proc CreateGraphs {} { -takefocus 0 \ -background $ds9(bg) \ -highlightthickness 0 \ - -plotrelief groove \ - -plotborderwidth 2 \ + -borderwidth 0 \ + -plotborderwidth 1 \ + -plotrelief flat \ -plotbackground $ds9(bg) ] $ds9(graph,vert) legend configure -hide yes @@ -125,14 +137,14 @@ proc UpdateGraphFont {} { } proc UpdateGraphGrid {} { - global pgraph + global graph global ds9 - $ds9(graph,horz) xaxis configure -grid $pgraph(horz,grid) -tickdefault 4 - $ds9(graph,horz) y2axis configure -grid $pgraph(horz,grid) + $ds9(graph,horz) xaxis configure -grid $graph(horz,grid) -tickdefault 4 + $ds9(graph,horz) y2axis configure -grid $graph(horz,grid) - $ds9(graph,vert) x2axis configure -grid $pgraph(vert,grid) - $ds9(graph,vert) yaxis configure -grid $pgraph(vert,grid) -tickdefault 4 + $ds9(graph,vert) x2axis configure -grid $graph(vert,grid) + $ds9(graph,vert) yaxis configure -grid $graph(vert,grid) -tickdefault 4 } proc UpdateGraphXAxis {which} { @@ -170,7 +182,7 @@ proc UpdateGraphXAxisHV {which what vectorX} { } proc UpdateGraphYAxis {which} { - global pgraph + global graph global ds9 global view @@ -181,15 +193,17 @@ proc UpdateGraphYAxis {which} { } if {$view(graph,horz)} { - UpdateGraphYAxisHV $which $ds9(graph,horz) graphHorzY $pgraph(horz,log) + UpdateGraphYAxisHV $which $ds9(graph,horz) graphHorzY \ + $graph(horz,log) $graph(horz,thick) $graph(horz,method) } if {$view(graph,vert)} { - UpdateGraphYAxisHV $which $ds9(graph,vert) graphVertY $pgraph(vert,log) + UpdateGraphYAxisHV $which $ds9(graph,vert) graphVertY \ + $graph(vert,log) $graph(vert,thick) $graph(thick,method) } } -proc UpdateGraphYAxisHV {which what vectorY log} { +proc UpdateGraphYAxisHV {which what vectorY log thick method} { global igraph global graphHorzY graphVertY @@ -208,6 +222,13 @@ proc UpdateGraphYAxisHV {which what vectorY log} { set yMax [expr $yMin + 1] } + switch $method { + sum { + set yMax [expr $yMax*$thick] + } + average {} + } + $what yaxis configure -min $yMin -max $yMax -logscale $log -tickdefault 4 $what y2axis configure -min $yMin -max $yMax -logscale $log -tickdefault 4 } else { @@ -258,23 +279,31 @@ proc ClearGraphData {} { proc UpdateGraph {which x y sys} { global ds9 global view - global pgraph + global graph + global dgraph - if {[$which has fits]} { - if {$view(graph,horz)} { - if {![catch {$which get horizontal cut graphHorzX graphHorzY $x $y $sys $pgraph(thick)}]} { - $ds9(graph,horz) element configure line1 -hide no - } else { - $ds9(graph,horz) element configure line1 -hide yes - } + # save for later + set dgraph(frame) $which + set dgraph(x) $x + set dgraph(y) $y + + if {![$which has fits]} { + return + } + + if {$view(graph,horz)} { + if {![catch {$which get horizontal cut graphHorzX graphHorzY $x $y $sys $graph(horz,thick) $graph(horz,method)}]} { + $ds9(graph,horz) element configure line1 -hide no + } else { + $ds9(graph,horz) element configure line1 -hide yes } + } - if {$view(graph,vert)} { - if {![catch {$which get vertical cut graphVertX graphVertY $x $y $sys $pgraph(thick)}]} { - $ds9(graph,vert) element configure line1 -hide no - } else { - $ds9(graph,vert) element configure line1 -hide yes - } + if {$view(graph,vert)} { + if {![catch {$which get vertical cut graphVertX graphVertY $x $y $sys $graph(vert,thick) $graph(vert,method)}]} { + $ds9(graph,vert) element configure line1 -hide no + } else { + $ds9(graph,vert) element configure line1 -hide yes } } } @@ -389,7 +418,6 @@ proc LayoutGraphs {} { set ww [expr $canvas(width)+$igraph(gap,x)] $ds9(graph,horz) configure -width $ww - } else { if {$igraph(horz,id)>0} { $ds9(canvas) delete $igraph(horz,id) @@ -424,3 +452,132 @@ proc LayoutGraphs {} { } } } + +proc GraphDialog {} { + global igraph + global graph + global current + + # see if we already have a window visible + if {[winfo exists $igraph(top)]} { + raise $igraph(top) + return + } + + # create the window + set w $igraph(top) + set mb $igraph(mb) + + Toplevel $w $mb 6 [msgcat::mc {Graph Parameters}] GraphDestroyDialog + $mb add cascade -label [msgcat::mc {File}] -menu $mb.file + $mb add cascade -label [msgcat::mc {Edit}] -menu $mb.edit + + menu $mb.file + $mb.file add command -label [msgcat::mc {Apply}] \ + -command GraphApplyDialog + $mb.file add separator + $mb.file add command -label [msgcat::mc {Close}] \ + -command GraphDestroyDialog + + EditMenu $mb igraph + + # Horizontal + set f [ttk::labelframe $w.horz -text [msgcat::mc {Horizontal}] -padding 2] + + ttk::checkbutton $f.hgrid -text [msgcat::mc {Show Grid}] \ + -variable graph(horz,grid) \ + -command UpdateGraphGrid + ttk::label $f.htaxis -text [msgcat::mc {Axis}] + ttk::radiobutton $f.hlaxis -text [msgcat::mc {Linear}] \ + -variable graph(horz,log) -value false \ + -command [list UpdateGraphYAxis $current(frame)] + ttk::radiobutton $f.hgaxis -text [msgcat::mc {Log}] \ + -variable graph(horz,log) -value true \ + -command [list UpdateGraphYAxis $current(frame)] + ttk::label $f.htthick -text [msgcat::mc {Thickness}] + ttk::entry $f.hthick -textvariable graph(horz,thick) -width 7 + ttk::label $f.htmethod -text [msgcat::mc {Method}] + ttk::radiobutton $f.hamethod -text [msgcat::mc {Average}] \ + -variable graph(horz,method) -value average \ + -command [list UpdateGraphYAxis $current(frame)] + ttk::radiobutton $f.hsmethod -text [msgcat::mc {Sum}] \ + -variable graph(horz,method) -value sum \ + -command [list UpdateGraphYAxis $current(frame)] + + grid $f.hgrid -padx 2 -pady 2 -sticky w + grid $f.htaxis $f.hlaxis $f.hgaxis -padx 2 -pady 2 -sticky w + grid $f.htthick $f.hthick -padx 2 -pady 2 -sticky w + grid $f.htmethod $f.hamethod $f.hsmethod -padx 2 -pady 2 -sticky w + + # Vertical + set f [ttk::labelframe $w.vert -text [msgcat::mc {Vertical}] -padding 2] + + ttk::checkbutton $f.vgrid -text [msgcat::mc {Show Grid}] \ + -variable graph(vert,grid) \ + -command UpdateGraphGrid + ttk::label $f.vtaxis -text [msgcat::mc {Axis}] + ttk::radiobutton $f.vlaxis -text [msgcat::mc {Linear}] \ + -variable graph(vert,log) -value false \ + -command [list UpdateGraphYAxis $current(frame)] + ttk::radiobutton $f.vgaxis -text [msgcat::mc {Log}] \ + -variable graph(vert,log) -value true \ + -command [list UpdateGraphYAxis $current(frame)] + ttk::label $f.vtthick -text [msgcat::mc {Thickness}] + ttk::entry $f.vthick -textvariable graph(vert,thick) -width 7 + ttk::label $f.vtmethod -text [msgcat::mc {Method}] + ttk::radiobutton $f.vamethod -text [msgcat::mc {Average}] \ + -variable graph(vert,method) -value average \ + -command [list UpdateGraphYAxis $current(frame)] + ttk::radiobutton $f.vsmethod -text [msgcat::mc {Sum}] \ + -variable graph(vert,method) -value sum \ + -command [list UpdateGraphYAxis $current(frame)] + + grid $f.vgrid -padx 2 -pady 2 -sticky w + grid $f.vtaxis $f.vlaxis $f.vgaxis -padx 2 -pady 2 -sticky w + grid $f.vtthick $f.vthick -padx 2 -pady 2 -sticky w + grid $f.vtmethod $f.vamethod $f.vsmethod -padx 2 -pady 2 -sticky w + + # Buttons + set f [ttk::frame $w.buttons] + ttk::button $f.apply -text [msgcat::mc {Apply}] -command GraphApplyDialog + ttk::button $f.close -text [msgcat::mc {Close}] -command GraphDestroyDialog + pack $f.apply $f.close -side left -expand true -padx 2 -pady 4 + + # Fini + grid $w.horz -sticky news + grid $w.vert -sticky news + grid $w.buttons - -sticky ew + grid rowconfigure $w 0 -weight 1 + grid columnconfigure $w 1 -weight 1 +} + +proc GraphApplyDialog {} { + global ds9 + global igraph + global graph + global dgraph + + if {[info exists dgraph]} { + if {$dgraph(frame) != {}} { + set ii [lsearch $ds9(active) $dgraph(frame)] + if {$ii>=0} { + UpdateGraph $dgraph(frame) $dgraph(x) $dgraph(y) canvas + } else { + set dgraph(frame) {} + } + } + } +} + +proc GraphDestroyDialog {} { + global igraph + global dgraph + + if {[winfo exists $igraph(top)]} { + destroy $igraph(top) + destroy $igraph(mb) + } + + unset dgraph +} + diff --git a/ds9/library/layout.tcl b/ds9/library/layout.tcl index 5bba029..4282a97 100644 --- a/ds9/library/layout.tcl +++ b/ds9/library/layout.tcl @@ -861,12 +861,14 @@ proc ProcessViewCmd {varname iname} { incr i set item [string tolower [lindex $var $i]] switch -- $item { + horz - horizontal { - set view(layout) $item + set view(layout) horizontal ViewHorzCmd } + vert - vertical { - set view(layout) $item + set view(layout) verical ViewVertCmd } } @@ -875,14 +877,16 @@ proc ProcessViewCmd {varname iname} { incr i set view(info,keyvalue) [lindex $var $i] } + horz - horizontal { # backward compatibility - set view(layout) $item + set view(layout) horizontal ViewHorzCmd } + vert - vertical { # backward compatibility - set view(layout) $item + set view(layout) vertical ViewVertCmd } @@ -917,6 +921,7 @@ proc ProcessViewCmd {varname iname} { incr i set item [string tolower [lindex $var $i]] switch -- $item { + horz - horizontal { set yesno [lindex $var [expr $i+1]] switch -- $yesno { @@ -934,6 +939,7 @@ proc ProcessViewCmd {varname iname} { } set view(graph,horz) [FromYesNo $yesno] } + vert - vertical { set yesno [lindex $var [expr $i+1]] switch -- $yesno { diff --git a/ds9/library/manalysis.tcl b/ds9/library/manalysis.tcl index 8e9b8c2..d634b4a 100644 --- a/ds9/library/manalysis.tcl +++ b/ds9/library/manalysis.tcl @@ -44,6 +44,10 @@ proc AnalysisMainMenu {} { -label "[msgcat::mc {Crosshair Parameters}]..." \ -command CrosshairDialog $ds9(mb).analysis add separator + $ds9(mb).analysis add command \ + -label "[msgcat::mc {Graph Parameters}]..." \ + -command GraphDialog + $ds9(mb).analysis add separator $ds9(mb).analysis add command -label "[msgcat::mc {Name Resolution}]..." \ -command NRESDialog $ds9(mb).analysis add separator diff --git a/ds9/library/mview.tcl b/ds9/library/mview.tcl index 373a05f..64d2def 100644 --- a/ds9/library/mview.tcl +++ b/ds9/library/mview.tcl @@ -138,6 +138,7 @@ proc PrefsDialogGraph {} { global pds9 global pmagnifier global current + global pgraph set w $dprefs(tab) @@ -147,42 +148,50 @@ proc PrefsDialogGraph {} { # Horz set f [ttk::labelframe $w.graph.horz -text [msgcat::mc {Horizontal}]] - ttk::label $f.htitle -text [msgcat::mc {Default}] - ttk::checkbutton $f.hgrid -text [msgcat::mc {Grid}] \ + ttk::checkbutton $f.hgrid -text [msgcat::mc {Show Grid}] \ -variable pgraph(horz,grid) -command UpdateGraphGrid - ttk::radiobutton $f.hlinear -text [msgcat::mc {Linear}] \ - -variable pgraph(horz,log) -value false \ - -command "UpdateGraphYAxis $current(frame)" - ttk::radiobutton $f.hlog -text [msgcat::mc {Log}] \ - -variable pgraph(horz,log) -value true \ - -command "UpdateGraphYAxis $current(frame)" - - grid $f.htitle $f.hgrid $f.hlinear $f.hlog -padx 2 -pady 2 -sticky w + ttk::label $f.htaxis -text [msgcat::mc {Axis}] + ttk::radiobutton $f.hlaxis -text [msgcat::mc {Linear}] \ + -variable pgraph(horz,log) -value false + ttk::radiobutton $f.hgaxis -text [msgcat::mc {Log}] \ + -variable pgraph(horz,log) -value true + ttk::label $f.htthick -text [msgcat::mc {Thickness}] + ttk::entry $f.hthick -textvariable pgraph(horz,thick) -width 7 + ttk::label $f.htmethod -text [msgcat::mc {Method}] + ttk::radiobutton $f.hamethod -text [msgcat::mc {Average}] \ + -variable pgraph(horz,method) -value average + ttk::radiobutton $f.hsmethod -text [msgcat::mc {Sum}] \ + -variable pgraph(horz,method) -value sum + + grid $f.hgrid -padx 2 -pady 2 -sticky w + grid $f.htaxis $f.hlaxis $f.hgaxis -padx 2 -pady 2 -sticky w + grid $f.htthick $f.hthick -padx 2 -pady 2 -sticky w + grid $f.htmethod $f.hamethod $f.hsmethod -padx 2 -pady 2 -sticky w # Vert set f [ttk::labelframe $w.graph.vert -text [msgcat::mc {Vertical}]] - ttk::label $f.vtitle -text [msgcat::mc {Default}] - ttk::checkbutton $f.vgrid -text [msgcat::mc {Grid}] \ + ttk::checkbutton $f.vgrid -text [msgcat::mc {Show Grid}] \ -variable pgraph(vert,grid) -command UpdateGraphGrid - ttk::radiobutton $f.vlinear -text [msgcat::mc {Linear}] \ - -variable pgraph(vert,log) -value false \ - -command "UpdateGraphYAxis $current(frame)" - ttk::radiobutton $f.vlog -text [msgcat::mc {Log}] \ - -variable pgraph(vert,log) -value true \ - -command "UpdateGraphYAxis $current(frame)" - - grid $f.vtitle $f.vgrid $f.vlinear $f.vlog -padx 2 -pady 2 -sticky w - - # Thickness - set f [ttk::labelframe $w.graph.thick -text [msgcat::mc {Thickness}]] - - ttk::entry $f.thick -textvariable pgraph(thick) -width 13 - - grid $f.thick -padx 2 -pady 2 -sticky w - - pack $w.graph.horz $w.graph.vert $w.graph.thick \ - -side top -fill both -expand true + ttk::label $f.vtaxis -text [msgcat::mc {Axis}] + ttk::radiobutton $f.vlaxis -text [msgcat::mc {Linear}] \ + -variable pgraph(vert,log) -value false + ttk::radiobutton $f.vgaxis -text [msgcat::mc {Log}] \ + -variable pgraph(vert,log) -value true + ttk::label $f.vtthick -text [msgcat::mc {Thickness}] + ttk::entry $f.vthick -textvariable pgraph(vert,thick) -width 7 + ttk::label $f.vtmethod -text [msgcat::mc {Method}] + ttk::radiobutton $f.vamethod -text [msgcat::mc {Average}] \ + -variable pgraph(vert,method) -value average + ttk::radiobutton $f.vsmethod -text [msgcat::mc {Sum}] \ + -variable pgraph(vert,method) -value sum + + grid $f.vgrid -padx 2 -pady 2 -sticky w + grid $f.vtaxis $f.vlaxis $f.vgaxis -padx 2 -pady 2 -sticky w + grid $f.vtthick $f.vthick -padx 2 -pady 2 -sticky w + grid $f.vtmethod $f.vamethod $f.vsmethod -padx 2 -pady 2 -sticky w + + pack $w.graph.horz $w.graph.vert -side top -fill both -expand true } # Buttons diff --git a/ds9/library/prefs.tcl b/ds9/library/prefs.tcl index d894965..71a5529 100644 --- a/ds9/library/prefs.tcl +++ b/ds9/library/prefs.tcl @@ -288,9 +288,12 @@ proc SavePrefs {} { puts $ch "array set pime \{ [array get pime] \}" puts $ch {array set ime [array get pime]} + global graph global pgraph + puts $ch "global graph" puts $ch "global pgraph" puts $ch "array set pgraph \{ [array get pgraph] \}" + puts $ch {array set graph [array get pgraph]} global pcoord puts $ch "global pcoord" -- cgit v0.12