From 72cee7539e883903b6bfec4fd03738753457b992 Mon Sep 17 00:00:00 2001 From: William Joye Date: Fri, 7 Jun 2019 11:44:38 -0400 Subject: support multiple graphs per plot --- ds9/library/catplot.tcl | 2 +- ds9/library/markeranalysispanda.tcl | 2 +- ds9/library/plot.tcl | 96 +-------------------------- ds9/library/plotdata.tcl | 128 +++++++++++++++++++++++++++++++++++- ds9/library/plotdialog.tcl | 23 ++++--- ds9/library/plotline.tcl | 2 +- ds9/parsers/plotparser.tac | 6 +- ds9/parsers/plotparser.tcl | 6 +- 8 files changed, 152 insertions(+), 113 deletions(-) diff --git a/ds9/library/catplot.tcl b/ds9/library/catplot.tcl index 567da52..d8040dd 100644 --- a/ds9/library/catplot.tcl +++ b/ds9/library/catplot.tcl @@ -86,7 +86,7 @@ proc CATPlotGenerate {varname} { set var(plot,var) $vvarname } - PlotDeleteData $vvarname + PlotDeleteAllDataSet $vvarname PlotDataSet $vvarname $dim $rr PlotTitle $vvarname $var(title) $xtitle $ytitle $vvar(proc,updategraph) $vvarname diff --git a/ds9/library/markeranalysispanda.tcl b/ds9/library/markeranalysispanda.tcl index 619fb96..b99a0c4 100644 --- a/ds9/library/markeranalysispanda.tcl +++ b/ds9/library/markeranalysispanda.tcl @@ -103,7 +103,7 @@ proc MarkerAnalysisPandaCB {frame id} { MarkerAnalysisPandaAxisTitle $vvarname } - PlotDeleteData $vvarname + PlotDeleteAllDataSet $vvarname PlotDataSet $vvarname 3 [$frame get marker $id analysis panda $sys] $vvar(proc,updategraph) $vvarname PlotStats $vvarname diff --git a/ds9/library/plot.tcl b/ds9/library/plot.tcl index f488be6..880d18a 100644 --- a/ds9/library/plot.tcl +++ b/ds9/library/plot.tcl @@ -91,11 +91,6 @@ proc PlotAddData {varname} { set cc $var(graph,current) set nn $var($cc,data,current) - # warning: uses current vars - if {$var($cc,data,total) == 0} { - return - } - # delete current elements foreach el [$var(graph) element names] { set f [split $el -] @@ -121,87 +116,6 @@ proc PlotAddData {varname} { } } -proc PlotDeleteData {varname} { - upvar #0 $varname var - global $varname - - global ds9 - - set cc $var(graph,current) - - if {$var($cc,data,total) == 0} { - return - } - - # first set can be external - set clear $var($cc,1,manage) - - for {set nn 1} {$nn<=$var($cc,data,total)} {incr nn} { - if {$var($cc,$nn,manage)} { - # delete elements - foreach el [$var(graph) element names] { - set f [split $el -] - if {[lindex $f 1] == $nn} { - $var(graph) element delete $el - } - } - - # destroy vectors - blt::vector destroy \ - $var($cc,$nn,xdata) $var($cc,$nn,ydata) - switch $var($cc,$nn,dim) { - xy {} - xyex {blt::vector destroy $var($cc,$nn,xedata)} - xyey {blt::vector destroy $var($cc,$nn,yedata)} - xyexey {blt::vector destroy \ - $var($cc,$nn,xedata) $var($cc,$nn,yedata)} - } - - foreach x [array names $varname] { - set f [split $x ,] - if {([lindex $f 0] == $nn)} { - unset ${varname}($x) - } - } - } - } - - if {$clear} { - set var($cc,data,total) 0 - set var($cc,data,current) 0 - - set var(graph,ds,name) {} - set var(graph,ds,xdata) {} - set var(graph,ds,ydata) {} - set var(graph,ds,xedata) {} - set var(graph,ds,yedata) {} - - # reset other variables - set var($cc,axis,x,auto) 1 - set var($cc,axis,x,min) {} - set var($cc,axis,x,max) {} - set var($cc,axis,x,format) {} - - set var($cc,axis,y,auto) 1 - set var($cc,axis,y,min) {} - set var($cc,axis,y,max) {} - set var($cc,axis,y,format) {} - - $var(mb).graph.select delete $ds9(menu,start) end - - $var(proc,updategraph) $varname - PlotStats $varname - PlotList $varname - } else { - set var($cc,data,total) 1 - set var($cc,data,current) 1 - - $var(mb).graph.select delete [expr $ds9(menu,start)+1] end - PlotCurrentData $varname - $var(proc,updategraph) $varname - } -} - proc PlotCurrentGraph {varname} { upvar #0 $varname var global $varname @@ -533,16 +447,10 @@ proc PlotUpdateGraph {varname} { # Menus if {$var(graph,ds,xdata) != {}} { $var(mb).file entryconfig "[msgcat::mc {Save Data}]..." -state normal - $var(mb).file entryconfig [msgcat::mc {Clear Data}] -state normal - $var(mb).file entryconfig [msgcat::mc {Duplicate Data}] -state normal - $var(mb).file entryconfig [msgcat::mc {Statistics}] -state normal - $var(mb).file entryconfig [msgcat::mc {List Data}] -state normal + $var(mb).file entryconfig [msgcat::mc {Clear All Data}] -state normal } else { $var(mb).file entryconfig "[msgcat::mc {Save Data}]..." -state disabled - $var(mb).file entryconfig [msgcat::mc {Clear Data}] -state disabled - $var(mb).file entryconfig [msgcat::mc {Duplicate Data}] -state disabled - $var(mb).file entryconfig [msgcat::mc {Statistics}] -state disabled - $var(mb).file entryconfig [msgcat::mc {List Data}] -state disabled + $var(mb).file entryconfig [msgcat::mc {Clear All Data}] -state disabled } # Graph diff --git a/ds9/library/plotdata.tcl b/ds9/library/plotdata.tcl index 5ab66e7..fc2e7dd 100644 --- a/ds9/library/plotdata.tcl +++ b/ds9/library/plotdata.tcl @@ -244,7 +244,7 @@ proc PlotDataSetOne {varname dim data} { $var(proc,updateelement) $varname } -proc PlotDupData {varname mm} { +proc PlotDupDataSet {varname mm} { upvar #0 $varname var global $varname @@ -420,3 +420,129 @@ proc PlotSaveDataFile {varname filename} { PlotRaise $varname } +proc PlotDeleteDataSet {varname} { + upvar #0 $varname var + global $varname + + global ds9 + + set cc $var(graph,current) + set nn $var(graph,data,current) + + if {$var($cc,data,total) == 0} { + return + } + + if {$var($cc,$nn,manage)} { + # delete elements + foreach el [$var(graph) element names] { + set f [split $el -] + if {[lindex $f 1] == $nn} { + $var(graph) element delete $el + } + } + + # destroy vectors + blt::vector destroy $var($cc,$nn,xdata) $var($cc,$nn,ydata) + switch $var($cc,$nn,dim) { + xy {} + xyex {blt::vector destroy $var($cc,$nn,xedata)} + xyey {blt::vector destroy $var($cc,$nn,yedata)} + xyexey {blt::vector destroy \ + $var($cc,$nn,xedata) $var($cc,$nn,yedata)} + } + + foreach vv [array names $varname] { + set ds [split $vv ,] + if {([lindex $ds 1] == $nn)} { + unset ${varname}($ds) + } + } + + incr ${varname}($cc,data,total) -1 + set ${varname}($cc,data,current) 0 + } +} + +proc PlotDeleteAllDataSet {varname} { + upvar #0 $varname var + global $varname + + global ds9 + + set cc $var(graph,current) + + if {$var($cc,data,total) == 0} { + return + } + + # first set can be external + set clear $var($cc,1,manage) + + for {set nn 1} {$nn<=$var($cc,data,total)} {incr nn} { + if {$var($cc,$nn,manage)} { + # delete elements + foreach el [$var(graph) element names] { + set f [split $el -] + if {[lindex $f 1] == $nn} { + $var(graph) element delete $el + } + } + + # destroy vectors + blt::vector destroy \ + $var($cc,$nn,xdata) $var($cc,$nn,ydata) + switch $var($cc,$nn,dim) { + xy {} + xyex {blt::vector destroy $var($cc,$nn,xedata)} + xyey {blt::vector destroy $var($cc,$nn,yedata)} + xyexey {blt::vector destroy \ + $var($cc,$nn,xedata) $var($cc,$nn,yedata)} + } + + foreach x [array names $varname] { + set f [split $x ,] + if {([lindex $f 0] == $nn)} { + unset ${varname}($x) + } + } + } + } + + if {$clear} { + set var($cc,data,total) 0 + set var($cc,data,current) 0 + + set var(graph,ds,name) {} + set var(graph,ds,xdata) {} + set var(graph,ds,ydata) {} + set var(graph,ds,xedata) {} + set var(graph,ds,yedata) {} + + # reset other variables + set var($cc,axis,x,auto) 1 + set var($cc,axis,x,min) {} + set var($cc,axis,x,max) {} + set var($cc,axis,x,format) {} + + set var($cc,axis,y,auto) 1 + set var($cc,axis,y,min) {} + set var($cc,axis,y,max) {} + set var($cc,axis,y,format) {} + + $var(mb).graph.select delete $ds9(menu,start) end + + $var(proc,updategraph) $varname + PlotStats $varname + PlotList $varname + } else { + set var($cc,data,total) 1 + set var($cc,data,current) 1 + + $var(mb).graph.select delete [expr $ds9(menu,start)+1] end + PlotCurrentData $varname + $var(proc,updategraph) $varname + } +} + + diff --git a/ds9/library/plotdialog.tcl b/ds9/library/plotdialog.tcl index 558925b..3ef4dd9 100644 --- a/ds9/library/plotdialog.tcl +++ b/ds9/library/plotdialog.tcl @@ -49,19 +49,13 @@ proc PlotDialog {varname wtt title xaxis yaxis} { -command [list PlotLoadData $varname] $var(mb).file add command -label "[msgcat::mc {Save Data}]..." \ -command [list PlotSaveData $varname] - $var(mb).file add command -label [msgcat::mc {Clear Data}] \ - -command [list PlotDeleteData $varname] - $var(mb).file add command -label [msgcat::mc {Duplicate Data}] \ - -command [list PlotDupData $varname 1] + $var(mb).file add separator + $var(mb).file add command -label [msgcat::mc {Clear All Data}] \ + -command [list PlotDeleteAllData $varname] $var(mb).file add separator $var(mb).file add cascade -label [msgcat::mc {Export}] \ -menu $var(mb).file.export $var(mb).file add separator - $var(mb).file add command -label [msgcat::mc {Statistics}] \ - -command "set ${varname}(stats) 1; PlotStats $varname" - $var(mb).file add command -label [msgcat::mc {List Data}] \ - -command "set ${varname}(list) 1; PlotList $varname" - $var(mb).file add separator $var(mb).file add command -label "[msgcat::mc {Load Configuration}]..." \ -command [list PlotLoadConfig $varname] $var(mb).file add command -label "[msgcat::mc {Save Configuration}]..." \ @@ -171,6 +165,17 @@ proc PlotDialog {varname wtt title xaxis yaxis} { $var(mb).graph add cascade -label [msgcat::mc {Select Dataset}] \ -menu $var(mb).graph.select $var(mb).graph add separator + $var(mb).graph add command -label [msgcat::mc {Delete Dataset}] \ + -command [list PlotDeleteDataSet $varname] + $var(mb).graph add command -label [msgcat::mc {Duplicate Dataset}] \ + -command [list PlotDupDataSet $varname 1] + $var(mb).graph add separator + $var(mb).graph add command -label [msgcat::mc {Statistics}] \ + -command "set ${varname}(stats) 1; PlotStats $varname" + $var(mb).graph add command -label [msgcat::mc {List Data}] \ + -command "set ${varname}(list) 1; PlotList $varname" + $var(mb).graph add separator + menu $var(mb).graph.select $var(mb).graph add cascade -label [msgcat::mc {Axes}] \ diff --git a/ds9/library/plotline.tcl b/ds9/library/plotline.tcl index 9960805..6516d71 100644 --- a/ds9/library/plotline.tcl +++ b/ds9/library/plotline.tcl @@ -135,7 +135,7 @@ proc PlotLineDialog {varname wtt title xaxis yaxis} { $var(mb).data.fill add cascade -label [msgcat::mc {Color}] \ -menu $var(mb).data.fill.color - PlotColorMenu $var(mb).data.fill.color $varname graph,fill,color \ + PlotColorMenu $var(mb).data.fill.color $varname graph,ds,fill,color \ [list PlotLineUpdateElement $varname] # Error diff --git a/ds9/parsers/plotparser.tac b/ds9/parsers/plotparser.tac index 8a9c559..80bc957 100644 --- a/ds9/parsers/plotparser.tac +++ b/ds9/parsers/plotparser.tac @@ -230,7 +230,7 @@ plotCmd : LOAD_ load | SAVE_ STRING_ {PlotCmdSave $2} # xpa/samp only | DATA_ dim {PlotCmdData $2} - | CLEAR_ {ProcessCmdCVAR0 PlotDeleteData} + | CLEAR_ {ProcessCmdCVAR0 PlotDeleteAllDataSet} | EXPORT_ export | DUPLICATE_ duplicate # backward compatibility @@ -303,8 +303,8 @@ load : STRING_ {PlotCmdLoad $1 xy} | STRING_ dim {PlotCmdLoad $1 $2} ; -duplicate : {global cvarname; PlotDupData $cvarname 1} - | INT_ {global cvarname; PlotDupData $cvarname $1} +duplicate : {global cvarname; PlotDupDataSet $cvarname 1} + | INT_ {global cvarname; PlotDupDataSet $cvarname $1} ; pagesetup : ORIENT_ pageOrient {ProcessCmdSet ps orient $2} diff --git a/ds9/parsers/plotparser.tcl b/ds9/parsers/plotparser.tcl index 93d01c5..3dc471e 100644 --- a/ds9/parsers/plotparser.tcl +++ b/ds9/parsers/plotparser.tcl @@ -5420,7 +5420,7 @@ proc plot::yyparse {} { 62 { set _ xyexey } 64 { PlotCmdSave $2 } 65 { PlotCmdData $2 } - 66 { ProcessCmdCVAR0 PlotDeleteData } + 66 { ProcessCmdCVAR0 PlotDeleteAllDataSet } 70 { ProcessCmdCVAR stats $2 PlotStats } 71 { ProcessCmdCVAR stats $2 PlotStats } 72 { ProcessCmdCVAR list $2 PlotList } @@ -5455,8 +5455,8 @@ proc plot::yyparse {} { 114 { ProcessCmdSet iap jpeg,quality $1 } 115 { PlotCmdLoad $1 xy } 116 { PlotCmdLoad $1 $2 } - 117 { global cvarname; PlotDupData $cvarname 1 } - 118 { global cvarname; PlotDupData $cvarname $1 } + 117 { global cvarname; PlotDupDataSet $cvarname 1 } + 118 { global cvarname; PlotDupDataSet $cvarname $1 } 119 { ProcessCmdSet ps orient $2 } 120 { ProcessCmdSet ps orient $2 } 121 { ProcessCmdSet ps size $2 } -- cgit v0.12