Skip to content

Commit

Permalink
Merge pull request #342 from dmurdoch/altText
Browse files Browse the repository at this point in the history
Add alt text to all rglwidgets.
  • Loading branch information
dmurdoch authored Mar 17, 2023
2 parents 86e0f8f + 5b2c620 commit 15a8bb9
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: rgl
Version: 1.1.3
Version: 1.1.4
Title: 3D Visualization Using OpenGL
Authors@R: c(person("Duncan", "Murdoch", role = c("aut", "cre"),
email = "[email protected]"),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# rgl 1.1.4

* Support for "alt" text has been added to `rglwidget()`, with
partial support for the `fig.alt` setting in `knitr`.

# rgl 1.1.3

## Major changes
Expand Down
3 changes: 2 additions & 1 deletion R/knitr.R
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ fns <- local({
content <- rglwidget(scene,
width = x$width,
height = x$height,
webgl = !doSnapshot)
webgl = !doSnapshot,
altText = c(options$fig.alt, paste("rglwidget in chunk", options$label))[1])
if (inherits(content, "knit_image_paths")) {
# # We've done a snapshot, put it in the right place.
name <- fig_path("-rgl.png", options, rgl_counter())
Expand Down
5 changes: 4 additions & 1 deletion R/rglwidget.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ rglwidget <- local({
minimal = TRUE,
webgl,
snapshot,
shinyBrush = NULL, ...,
shinyBrush = NULL,
altText = "rglwidget", ...,
oldConvertBBox = FALSE) {

if (missing(snapshot)) {
Expand Down Expand Up @@ -352,6 +353,8 @@ rglwidget <- local({
x$players <- upstream$players

x$webGLoptions <- webGLoptions

x$altText <- altText

# create widget
attr(x, "TOJSON_ARGS") <- list(na = "string")
Expand Down
1 change: 1 addition & 0 deletions inst/htmlwidgets/lib/rglClass/init.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,7 @@
this.onContextRestored, false);
newcanvas.addEventListener("webglcontextlost",
this.onContextLost, false);
newcanvas.appendChild(document.createTextNode(this.scene.altText));
while (this.el.firstChild) {
this.el.removeChild(this.el.firstChild);
}
Expand Down
3 changes: 3 additions & 0 deletions man/rglwidget.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rglwidget(x = scene3d(minimal), width = figWidth(), height = figHeight(),
shared = NULL, minimal = TRUE,
webgl, snapshot,
shinyBrush = NULL,
altText = "rglwidget",
...,
oldConvertBBox = FALSE)
}
Expand Down Expand Up @@ -46,6 +47,8 @@ component that will hold the scene.
no effect? See \code{\link{scene3d}}.}
\item{shinyBrush}{The name of a Shiny \code{input} element
to receive information about mouse selections.}
\item{altText}{Text to include for screen-readers or browsers
that don't handle WebGL.}
\item{oldConvertBBox}{See Details below.}
\item{...}{Additional arguments
to pass to \code{htmlwidgets::\link{createWidget}}.}
Expand Down
9 changes: 8 additions & 1 deletion man/setupKnitr.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ where appropriate, according to the \code{fig.keep} chunk option.
By default (\code{fig.keep = "high"}), only high-level plots
are kept, after low-level changes have been merged into them.
See the \pkg{knitr} documentation
\url{https://yihui.org/knitr/options/#plots} for more details. To suppress auto-printing, the RGL calls
\url{https://yihui.org/knitr/options/#plots} for more details.
To suppress auto-printing, the RGL calls
can be wrapped in \code{\link{invisible}()}.
Similarly to \pkg{grid} graphics (used by \pkg{lattice}
and \pkg{ggplot2}), automatic inclusion requires the object
Expand Down Expand Up @@ -106,6 +107,12 @@ display of plots.
\item \code{rgl.keepopen}: no longer used. Ignored
with a warning.
\item \code{fig.alt} is partially supported: \pkg{rgl}
will always use the first entry if \code{fig.alt} is a vector.
Other graphics types match the entries in \code{fig.alt}
to successive plots within the chunk.
(This is due to a limitation in \pkg{knitr}, and may
change in the future.)
}
}
\value{
Expand Down

0 comments on commit 15a8bb9

Please sign in to comment.