s-news
[Top] [All Lists]

Re: Making a Graphsheet Page Active

To: "David L Lorenz" <lorenz@usgs.gov>, "Walter R. Paczkowski" <dataanalytics@earthlink.net>
Subject: Re: Making a Graphsheet Page Active
From: "Thompson, David (MNR)" <David.John.Thompson@ontario.ca>
Date: Thu, 6 Sep 2007 14:19:11 -0400
Cc: <s-news@lists.biostat.wustl.edu>
In-reply-to: <OFAC4528E6.A626E814-ON8625734D.004A1A9A-8625734D.004BA6A2@usgs.gov>
References: <E1IRDpb-0001d0-0u@elasmtp-mealy.atl.sa.earthlink.net> <OFAC4528E6.A626E814-ON8625734D.004A1A9A-8625734D.004BA6A2@usgs.gov>
Thread-index: Acfvw0g7aCeWaqXHTLiJJTwuSvO/mAA7Rb/Q
Thread-topic: [S] Making a Graphsheet Page Active
################################
"Walter R. Paczkowski" <dataanalytics@earthlink.net> 
Sent by: s-news-owner@lists.biostat.wustl.edu 08/31/2007 04:18 PM 
To              s-news@lists.biostat.wustl.edu 
cc      
Subject [S] Making a Graphsheet Page Active

Hi,

I wrote a function that generates 50 graphs at once in one graphsheet
called GSD2.  I often do this and then export the pages to PowerPoint
using the Create PowerPoint option from the graph window menu.  This
time, however, I wanted to export the pages in GSD2 using the
export.graph function inside another function.  The problem that I have
is that the export.graph function only exports the active page, which
certainly may not be the page I want.  How do I activate a page
programmatically inside a function so that repeated calls to
export.graph will export the pages one at a time?

Thanks,

Walt Paczkowski 
_________________________________
Walter R. Paczkowski, Ph.D.
Data Analytics Corp.
44 Hamilton Lane
Plainsboro, NJ  08536
(V) 609-936-8999
(F) 609-936-3733

################################
Walt,

Here are a pair of scripts that may have the functionality you seek:

###
#
gspexport <- function(prefix='', ext='.wmf', extype='WMF'){
        # Export all pages on current graphsheet to individual WMF
files.
        # can't remember why, but need to reassign passed parameters to
local vars
        prefix <- prefix ; ext <- ext ; extype <- extype
        # gsname is graphsheetpage names
        gsname <- list(guiGetObjectNames('GraphSheetPage',
guiGetGSName()))
        # pname is graphsheetpage names trimmed of the leading '$$' (if
memory serves)
        pname <- lapply(gsname, function(i) substring(i,
nchar(guiGetGSName())+2) )
        # fname is output file names
        fname <- lapply(pname, function(i, x, y) paste(x, i, y, sep=''),
x  = prefix, y = ext)
        
        # for each graphsheet name in gsname . . .
        lapply(1:length(gsname[[1]]), function(i, x, y, z){
                # . . . activate desired graphsheetpage . . .
                guiModify('GraphSheet', Name=guiGetGSName(),
CurrentPage=x[[1]][i])
                # . . . and export active graphsheetpage to file with
same name plus extension.
                export.graph(FileName=y[[1]][i], Name=guiGetGSName(),
ExportType=z)
                }, x = pname, y = fname, z = extype)
}       #       gspexport(prefix='', ext='', extype='')
#
###

###
#
gsprename <- function(){
        # Rename all pages on current graphsheet to new graphsheetpage
names hard-coded into pname[[2]].
        gsname <- list(guiGetObjectNames('GraphSheetPage',
guiGetGSName()))
        pname <- lapply(gsname, function(x) substring(x,
nchar(guiGetGSName())+2) )
        # matching length list of arbitrary new graphsheetpage names
hard-coded to suit.
        pname[[2]] <- c('L00', 'L04', 'bd00', 'bd04', 'ht00', 'ht04',
'r00', 'r04', 'rhg00', 'rhg04', 'vol00', 'vol04', 'vph00', 'vph04')

        # change the name of a page
        lapply(1:length(gsname[[1]]), function(i, x)
                guiModify( 'GraphSheetPage', Name = x[[1]][i], NewName =
x[[2]][i])
                , x = pname)
        invisible()
}       #       gsprename()
#
###

This little sequence has been handy for exploring classes available and
their arguments and properties:
###
# list ALL arguments for all gui classes, then property names
        xxx <- guiGetClassNames()
        names(xxx) <- guiGetClassNames()
        lapply(xxx, function(x) {guiGetArgumentNames(x)})
        lapply(xxx, function(x) {guiGetPropertyNames(x)})
#
###

All this I derived from an awesome post by Tony Plate . . .
###
# 
http://www.biostat.wustl.edu/archives/cgi-bin/mesg.cgi?a=s-news&i=438478
6F.8000505%40blackmesacapital.com
Subject:        Re: dev.copy on tabbed graphsheet device
From:           Tony Plate <tplate@blackmesacapital.com>


# The first three functions in this list are what you need to cycle
through the pages in a tabbed graphsheet.
# to get the name of the currently active graphsheet (replace 'GSD2'
below by guiGetGSName())
guiGetGSName()

# to get the names of all the pages in the active graphsheet
guiGetObjectNames('GraphSheetPage', guiGetGSName())

# sets the currently displayed page in a graphsheet
guiModify('GraphSheet', Name=guiGetGSName(), CurrentPage='Page1')

# get the name of a plot (default 1) on a page (default 1) in the
current graphsheet
guiGetPlotName(guiGetGSName(), GraphNum=1, PlotNum=1)

# returns the name of the currently displayed page in the graphsheet
guiGetPropertyValue('GraphSheet', Name=guiGetGSName(), 'CurrentPage')

# set the name of the graphsheet when creating it
graphsheet(Name='FooBar', ...)

# change the name of current graphsheet
guiModify( 'GraphSheet', Name = guiGetGSName(), NewName = 'MyGraph')

# change the name of a page (graphsheet name remains same)
guiModify( 'GraphSheetPage', Name = paste(guiGetGSName(), '1', sep='$'),
NewName = 'MyPage')

# create a new graphsheet page
guiCreate( 'GraphSheetPage', Name = paste(guiGetGSName(), 'Page1',
sep='$'))

# print some pages from a graphsheet (help page says that pages must be
specified as numbers, don't know if this is true)
guiPrint(Name=guiGetGSName(), StartPage=??, EndPage=??)

# saves the whole graphsheet (all pages) in a file
guiSave('GraphSheet', Name=guiGetGSName(), FileName='file.sgr')

# saves the currently active page as an EPS file (many other types are
available)
export.graph(FileName=paste(guiGetGSName(), '.eps', sep='$'),
Name=guiGetGSName(), ExportType='EPS')

# remove the contents of the current page (note that 'Clear' on the
popup-menu on the page tab appears not to work properly)
guiRemoveContents('GraphSheet', Name=guiGetGSName())

# remove a page from the graphsheet (get page names using
guiGetObjectNames('GraphSheetPage', guiGetGSName())). Warning: removing
the last page seems to make the graphsheet non-functional.
guiRemove('GraphSheetPage', Name=page.name)
#
####
###

<Prev in Thread] Current Thread [Next in Thread>