From 59d7227509fd4c110bc78be98dc485c6ac939d05 Mon Sep 17 00:00:00 2001 From: William Joye Date: Fri, 2 Aug 2019 16:01:55 -0400 Subject: support multiple graphs per plot --- ds9/library/plot.tcl | 110 ++++++++++++++++++++++++++++++++++---------- ds9/library/plotdialog.tcl | 5 +- ds9/library/plotprocess.tcl | 9 ---- ds9/parsers/plotparser.tac | 2 +- ds9/parsers/plotparser.tcl | 2 +- 5 files changed, 88 insertions(+), 40 deletions(-) diff --git a/ds9/library/plot.tcl b/ds9/library/plot.tcl index efd0c03..d0b905e 100644 --- a/ds9/library/plot.tcl +++ b/ds9/library/plot.tcl @@ -652,6 +652,63 @@ proc PlotLayoutCanvas {varname} { update idletasks } +proc PlotCalcMargins {varname rpixname lpixname} { + upvar $rpixname rpix + upvar $lpixname lpix + upvar #0 $varname var + global $varname + + set rpix 0 + set lpix 0 + + set lchar 0 + set rchar 0 + set ytitle 0 + foreach cc $var(graphs) { + # y axis title + if {$var($cc,axis,y,title) !={}} { + set ytitle 1 + } + + # legend + if {$var($cc,legend)} { + # find max legend dataset name width + set nc 0 + foreach nn $var($cc,dss) { + set nr [string length $var($cc,$nn,name)] + if {$nr > $nc} { + set nc $nr + } + } + switch $var($cc,legend,position) { + top {} + bottom {} + right { + if {$nc > $rchar} { + set rchar $nc + } + } + left { + if {$nc > $lchar} { + set lchar $nc + } + } + plotarea {} + } + } + } + if {$rchar>0} { + set rpix [expr $rpix + int(($var(legend,title,size)*4 + $var(legend,font,size)*$rchar)*.75)] + } + if {$lchar>0} { + set lpix [expr $lpix + int(($var(legend,title,size)*4 + $var(legend,font,size)*$lchar)*.75)] + } + + set rpix [expr 10 + $rpix] + set lpix [expr 8*$var(axis,font,size) + $ytitle*$var(axis,title,size) + $lpix] +} + + # procs # used by backup proc PlotUpdateCanvas {varname} { @@ -697,7 +754,18 @@ proc PlotUpdateCanvas {varname} { set var(layout,axis,x,flip) $var($first,axis,x,flip) } } - + + set right 0 + set left 0 + switch $var(layout) { + grid - + row - + column {} + strip { + PlotCalcMargins $varname right left + } + } + foreach cc $var(graphs) { $var($cc,graph) configure -plotpadx 0 -plotpady 0 \ -font "{$ds9($var(graph,title,family))} $var(graph,title,size) $var(graph,title,weight) $var(graph,title,slant)" \ @@ -739,30 +807,6 @@ proc PlotUpdateCanvas {varname} { set var($cc,axis,x,manage) 0 } -# set left [expr 8*$var(axis,font,size) + $var(axis,title,size)] -# set right 10 - set left 100 - set right 100 - - if {$var($first,legend) &&0} { - # find max legend dataset name width - set nc 0 - foreach nn $var($first,dss) { - set nr [string length $var($first,$nn,name)] - if {$nr > $nc} { - set nc $nr - } - } - set ll [expr $var(legend,title,size)*4 + $var(legend,font,size)*$nc] - switch $var($first,legend,position) { - top {} - bottom {} - right {set right [expr $right + $ll]} - left {set left [expr $left + $ll]} - plotarea {} - } - } - $var($cc,graph) configure \ -leftmargin $left -rightmargin $right \ -borderwidth 0 \ @@ -970,6 +1014,22 @@ proc PlotTitle {varname title xaxis yaxis} { PlotChangeTitle $varname } +proc PlotDataSetName {varname name} { + upvar #0 $varname var + global $varname + + $var(mb).graph.select entryconfig "$var(graph,ds,name)" -label "$name" + set var(graph,ds,name) $name + $var(graph,proc,updateelement) $varname + + switch $var(layout) { + grid - + row - + column {} + strip {PlotUpdateCanvas $varname} + } +} + proc PlotBackup {ch dir} { global iap diff --git a/ds9/library/plotdialog.tcl b/ds9/library/plotdialog.tcl index 4a2fd3b..a9ff09a 100644 --- a/ds9/library/plotdialog.tcl +++ b/ds9/library/plotdialog.tcl @@ -567,10 +567,7 @@ proc DatasetNameDialog {varname} { DialogDismiss $w if {$ed(ok)} { - $var(mb).graph.select entryconfig "$var(graph,ds,name)" \ - -label "$ed(name)" - set var(graph,ds,name) $ed(name) - $var(graph,proc,updateelement) $varname + PlotDataSetName $varname $ed(name) } set rr $ed(ok) diff --git a/ds9/library/plotprocess.tcl b/ds9/library/plotprocess.tcl index 3497de2..a09efa2 100644 --- a/ds9/library/plotprocess.tcl +++ b/ds9/library/plotprocess.tcl @@ -314,15 +314,6 @@ proc PlotCmdExport {format fn} { PlotExport $cvarname $fn $format } -proc PlotCmdDataSetName {name} { - global cvarname - upvar #0 $cvarname cvar - - $cvar(mb).graph.select entryconfig "$cvar(graph,ds,name)" -label "$name" - set cvar(graph,ds,name) $name - $cvar(graph,proc,updateelement) $cvarname -} - proc ProcessSendPlotCmd {proc id param {sock {}} {fn {}}} { global iap global parse diff --git a/ds9/parsers/plotparser.tac b/ds9/parsers/plotparser.tac index fd1138a..7de1f2c 100644 --- a/ds9/parsers/plotparser.tac +++ b/ds9/parsers/plotparser.tac @@ -293,7 +293,7 @@ plotCmd : LOAD_ load # backward compatibility | ERRORBAR_ errorr | RELIEF_ relief {PlotCmdUpdateElement graph,ds,bar,relief $2} - | NAME_ STRING_ {PlotCmdDataSetName $2} + | NAME_ STRING_ {ProcessCmdCVAROpt PlotDataSetName $2} # backward compatibility | GRAPH_ oldGraph diff --git a/ds9/parsers/plotparser.tcl b/ds9/parsers/plotparser.tcl index c78fdf0..8ed6c63 100644 --- a/ds9/parsers/plotparser.tcl +++ b/ds9/parsers/plotparser.tcl @@ -5704,7 +5704,7 @@ proc plot::yyparse {} { 101 { PlotCmdUpdateElement graph,ds,fill $2 } 102 { PlotCmdUpdateElement graph,ds,fill,color $2 } 105 { PlotCmdUpdateElement graph,ds,bar,relief $2 } - 106 { PlotCmdDataSetName $2 } + 106 { ProcessCmdCVAROpt PlotDataSetName $2 } 109 { PlotCmdLoad $1 xy } 110 { PlotCmdLoad $1 $2 } 111 { PlotCmdExport [ExtToFormat $1] $1 } -- cgit v0.12