Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve plot_layout_properties: correct slide width/height, add title (closes #577) #580

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ replaced with a hyphen-minus (Unicode character 002D). Closes #573.

#' with different text.

- `plot_layout_properties()` gains a 'title' parameter, which will add the layout name as the plot title. Defaults to `FALSE`, to not alter the old behavior. Also, the slide width and height are now correctly displayed in the plot. Before, a box was drawn around the plot area. However, the plot area var with device size, not slide size.
- `docx_summary()` gains parameter 'detailed' which allows to get a detailed
summary including formatting properties of runs in a paragraph. Formatting
properties are stored in a list column `run`, where each element
Expand Down
42 changes: 25 additions & 17 deletions R/pptx_informations.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,44 +91,52 @@ layout_properties <- function( x, layout = NULL, master = NULL ){
#' @param x an rpptx object
#' @param layout slide layout name to use
#' @param master master layout name where \code{layout} is located
#' @param labels if TRUE, placeholder labels will be printed, if FALSE
#' @param labels if \code{TRUE}, placeholder labels will be printed, if \code{FALSE}
#' placeholder types and identifiers will be printed.
#' @param title if \code{FALSE}, a title with the layout name will be printed.
#' @importFrom graphics plot rect text box
#' @examples
#' x <- read_pptx()
#' plot_layout_properties( x = x, layout = "Title Slide",
#' master = "Office Theme" )
#' plot_layout_properties( x = x, layout = "Two Content" )
#' @family functions for reading presentation informations
plot_layout_properties <- function(x, layout = NULL, master = NULL, labels = TRUE){
plot_layout_properties <- function (x, layout = NULL, master = NULL, labels = TRUE, title = FALSE)
{
old_par <- par(mar = c(2, 2, 1.5, 0))
on.exit(par(old_par))

dat <- layout_properties(x, layout = layout, master = master)
if(length(unique(dat$name)) != 1 ){
if (length(unique(dat$name)) != 1) {
stop("one single layout need to be choosen")
}

w <- slide_size(x)
h <- w$height
w <- w$width

s <- slide_size(x)
h <- s$height
w <- s$width
offx <- dat$offx
offy <- dat$offy
cx <- dat$cx
cy <- dat$cy
if(labels) labels <- dat$ph_label
if (labels)
labels <- dat$ph_label
else {
labels <- dat$type[order(as.integer(dat$id))]
rle_ <- rle(labels)
labels <- sprintf("type: '%s' - id: %.0f", labels,
unlist(lapply(rle_$lengths, seq_len))
)
labels <- sprintf("type: '%s' - id: %.0f", labels, unlist(lapply(rle_$lengths,
seq_len)))
}

plot(x = c(0, w), y = -c(0,h), asp = 1, type = "n", axes = FALSE, xlab = "x (inches)", ylab = "y (inches)")
rect(xleft = offx, xright = offx + cx, ybottom = -offy, ytop = -(offy + cy))
text(x = offx + cx/2, y= -(offy + cy/2), labels = labels, cex = .5, col = "red")
box()
plot(x = c(0, w), y = -c(0, h), asp = 1, type = "n", axes = FALSE, xlab = NA, ylab = NA)
if (title) {
title(main = paste("Layout:", layout))
}
rect(xleft = 0, xright = w, ybottom = 0, ytop = -h, border = "darkgrey")
rect(xleft = offx, xright = offx + cx, ybottom = -offy, ytop = -(offy + cy))
text(x = offx + cx/2, y = -(offy + cy/2), labels = labels, cex = 0.5, col = "red")
mtext("y [inch]", side = 2, line = 0, cex = 1.2, col="darkgrey")
mtext("x [inch]", side = 1, line = 0, cex = 1.2, col="darkgrey")
}


#' @export
#' @title Placeholder parameters annotation
#' @description generates a slide from each layout in the base document to
Expand Down
12 changes: 10 additions & 2 deletions man/plot_layout_properties.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading