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

Logging visual outcomes from base graphics calls #75

Open
nzgwynn opened this issue Aug 30, 2023 · 15 comments
Open

Logging visual outcomes from base graphics calls #75

nzgwynn opened this issue Aug 30, 2023 · 15 comments
Assignees
Labels
Accessibility Issue motivated by accessibility concerns

Comments

@nzgwynn
Copy link

nzgwynn commented Aug 30, 2023

No description provided.

@ajrgodfrey
Copy link

ajrgodfrey commented Aug 30, 2023 via email

@nzgwynn nzgwynn changed the title Describe traditional for BrailleR package Describe traditional plots for BrailleR package Aug 30, 2023
@nzgwynn nzgwynn changed the title Describe traditional plots for BrailleR package Logging visual outcomes from base graphics calls Aug 30, 2023
@nzgwynn
Copy link
Author

nzgwynn commented Aug 30, 2023

Github for grid graphics: https://github.com/pmur002/gridgraphics

@deepayan
Copy link

This gives a list of calls stored on the display list:

summarizeDL <- function()
{
    p <- recordPlot()
    lapply(p[[1]], \(x) x[[2]][[1]][[1]])
}

@nzgwynn
Copy link
Author

nzgwynn commented Aug 30, 2023

x <- runif(30, 1, 50)
y <- rnorm(30, 0, 1)

Draw a plot

plot(x, y)

p <- recordPlot()
p[[1]]

@deepayan
Copy link

Version with argument list along with the function calls:

summarizeDL <- function()
{
	 getCall <- function(x) {
     	structure(list(x[[2]][-1]), 
        	      names = x[[2]][1][[1]]$name)
	 }
    p <- recordPlot()
    lapply(p[[1]], getCall) |> do.call(what = c)
}

@nzgwynn
Copy link
Author

nzgwynn commented Aug 30, 2023

We'll start with these:

plot(), points(), lines(), abline(), curve()

@deepayan
Copy link

Initial list of functions that get recorded on the display list, along with a potential list of arguments. The argument list may not be complete or correct in all cases, and will need to be verified.

There are other functions that may be called (that definitely happens for grid-based plots), so this should only be considered as a starting point.

plotc_arglist1 <- 
    list(C_plot_new = c(""),
         C_plot_window = c(""),
         C_axis = c("side, at, labels, tick, line, pos, outer, font, lty, lwd, lwd.ticks, col, col.ticks, hadj, padj, gap.axis, ..."),
         C_plotXY = c("x, y, type, pch, lty, col, bg, cex, lwd, ..."),
         C_segments = c("x0, y0, x1, y1, col, lty, lwd, ..."),
         C_rect = c("xl, yb, xr, yt, col, border, lty, ..."),
         C_path = c("x, y, col, border, lty, ..."),
         C_raster = c("image, xl, yb, xr, yt, angle, interpolate, ..."),
         C_arrows = c("x0, y0, x1, y1, length, angle, code, col, lty, lwd, ..."),
         C_polygon = c("x, y, col, border, lty, ..."),
         C_text = c("xy, labels, adj, pos, offset, vfont, cex, col, font, ..."),
         C_mtext = c("text, side, line, outer, at, adj, padj, cex, col, font, ..."),
         C_title = c("main, sub, xlab, ylab, line, outer, ..."),
         C_abline = c("a, b, h, v, col, lty, lwd, ..."),
         C_box = c("which, lty, ..."),
         C_locator = c("x, y, nobs, ans, saveans, stype"),
         C_identify = c("ans, x, y, l, ind, pos, order, Offset, draw, saveans"),
         C_strHeight = c("?"),
         C_dend = c("?"),
         C_dendwindow = c("?"),
         C_erase = c("?"),
         C_symbols = c("x, y, type, data, inches, bg, fg, ..."),
         C_xspline = c("sx, sy, ss, col, border, res"),
         C_clip = c("x1, x2, y1, y2"),
         C_convertX = c("from, to"),
         C_convertY = c("from, to"))

## split on comma to get a vector of argument names
plotc_arglist2 <- lapply(plotc_arglist1, \(x) trimws(strsplit(x, ",")[[1]]))

@ajrgodfrey
Copy link

ajrgodfrey commented Aug 30, 2023 via email

@pmur002
Copy link
Contributor

pmur002 commented Aug 31, 2023

I was going to suggest a 'gridGraphics'-based approach, but all 'gridGraphics' is doing is traversing the display list and looking at the information stored there, which is what it looks like Deepayan has suggested you do.

One complication you might want to consider is that a call to plot() may generate more than one plot on the page, e.g., plot.lm(). To allow for this, 'gridGraphics' generates a hierarchy of viewports and has an explicit naming scheme (see the "Naming Schemes" section in the R Journal article) so that we can differentiate between separate plots. You may have to do something analogous.

@deepayan
Copy link

Longer term, we may want to add a summary.recordedplot() function in base R that extracts a minimal set of information from the display list in a non-scary format (one that doesn't involve dotted pair lists and external pointers). This would provide BrailleR and other add-on packages a predictable and documented API to work with.

@MichaelChirico
Copy link

+1 to Deepayan's comment. I had the same thought during the chat re: possible regression tests for #74. Getting a nicer object would facilitate some basic regression tests for plots.

@nzgwynn
Copy link
Author

nzgwynn commented Aug 31, 2023

I'm interested in working on that.

@ajrgodfrey
Copy link

ajrgodfrey commented Aug 31, 2023 via email

@deepayan
Copy link

Some potentially useful help pages:

?dev.control
?setHook
?plot.new

@deepayan
Copy link

Task callbacks:
For recording what has happened in the last call:

?taskCallbackManager

Reference: https://developer.r-project.org/TaskHandlers.pdf

@MichaelChirico MichaelChirico added the Accessibility Issue motivated by accessibility concerns label Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accessibility Issue motivated by accessibility concerns
Projects
None yet
Development

No branches or pull requests

5 participants