5 |
pdel |
1 |
### bdopen
|
|
|
2 |
### Used to open a graphics driver with BDplot.
|
|
|
3 |
|
13 |
pdel |
4 |
### In X11, height and width are scaled to get a nicer window on the screen.
|
7 |
pdel |
5 |
### This hack is ugly. At least there should be a scaling factor in stead so that all measures are scaled (fonts, etc).
|
|
|
6 |
|
68 |
pdel |
7 |
bdopen <- function(file=bdp()$file,paper=bdp()$paper,mfrow=bdp()$mfrow,scale=TRUE,quality=NULL,scaleheight=1,height=NULL)
|
5 |
pdel |
8 |
{
|
67 |
pdel |
9 |
.bdcalcsizes(paper=paper,mfrow=mfrow,scaleheight=scaleheight,height=height)
|
5 |
pdel |
10 |
prm <- .bdgetpars()
|
68 |
pdel |
11 |
if(!is.null(height)){
|
|
|
12 |
prm$height <- height
|
|
|
13 |
}
|
53 |
pdel |
14 |
if(prm$debug)
|
|
|
15 |
print(prm$height)
|
23 |
pdel |
16 |
if( !is.na(file) )
|
5 |
pdel |
17 |
{
|
71 |
pdel |
18 |
## If figdir is supplied, prepending it to filename. It would be great only to do this if the path given in file is not absolute, ie starting by eather / or ~.
|
|
|
19 |
if(!is.null(prm$figdir)&&!is.na(prm$figdir) && (substring(bdp()$figdir,1,1)!="~"&&substring(bdp()$figdir,1,1)!="/") )
|
5 |
pdel |
20 |
{
|
34 |
pdel |
21 |
file <- paste(prm$figdir,file,sep="/")
|
5 |
pdel |
22 |
}
|
66 |
pdel |
23 |
cat("Writing to",file,"\n")
|
5 |
pdel |
24 |
## determining device driver from filename
|
23 |
pdel |
25 |
nchars <- nchar(file)
|
61 |
pdel |
26 |
##### should switch be used here?
|
23 |
pdel |
27 |
if( any( substr(file,nchars-2,nchars)==".ps",substr(file,nchars-3,nchars)==".eps")){
|
5 |
pdel |
28 |
m <- {
|
|
|
29 |
cat("B/D plotting writing to postscript file\n")
|
23 |
pdel |
30 |
postscript(file=file, width=prm$width, height=prm$height, paper="special", family = "Helvetica", horizontal=FALSE)
|
5 |
pdel |
31 |
}
|
23 |
pdel |
32 |
} else if ( substr(file,nchars-3,nchars)==".pdf")
|
5 |
pdel |
33 |
{
|
23 |
pdel |
34 |
pdf(file=file, width=prm$width, height=prm$height, paper="special",family = "Helvetica")
|
|
|
35 |
} else if (any(substr(file,nchars-3,nchars)==".jpg", substr(file,nchars-4,nchars)==".jpeg")) {
|
5 |
pdel |
36 |
cat("Writing to jpeg file\n")
|
29 |
pdel |
37 |
if(is.null(quality))
|
|
|
38 |
quality=prm$jpeg.quality
|
|
|
39 |
jpeg(filename=file,width=prm$width,height=prm$height,units=prm$size.unit,quality=quality,res=prm$jpeg.res,type="cairo")
|
23 |
pdel |
40 |
### bitmap(file=file,type="jpeg",width=prm$width,height=prm$height,units=prm$size.unit,res=prm$jpeg.res,pointsize=.3)
|
61 |
pdel |
41 |
} else if ( substr(file,nchars-3,nchars)==".tex"){
|
|
|
42 |
require(tikzDevice)
|
|
|
43 |
cat("Writing to tikz file\n")
|
|
|
44 |
tikz(file=file)
|
5 |
pdel |
45 |
}
|
61 |
pdel |
46 |
} else {
|
27 |
pdel |
47 |
|
|
|
48 |
if(scale){
|
|
|
49 |
prm$height <- prm$height*2
|
|
|
50 |
prm$width <- prm$width*2
|
|
|
51 |
}
|
5 |
pdel |
52 |
## to X. Note that this doesn't work on win and osx.
|
27 |
pdel |
53 |
X11(height=prm$height,width=prm$width)
|
|
|
54 |
}
|
5 |
pdel |
55 |
|
|
|
56 |
par(mfrow=mfrow)
|
27 |
pdel |
57 |
}
|
15 |
pdel |
58 |
|