Skip to content

Commit

Permalink
docs: Tweak R API documentation
Browse files Browse the repository at this point in the history
* Minor changes to titles/description of exported R functions in
  the file canvas.R.
* Add links to `Message`, `type` and `data` in the webr::canvas() function
  documentation.
  • Loading branch information
georgestagg committed Jul 25, 2023
1 parent 90eae55 commit 4fe8725
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
27 changes: 18 additions & 9 deletions packages/webr/R/canvas.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
#' Graphics device for webR HTML canvas element
#' Graphics device for drawing to a HTML canvas element
#'
#' A graphics device that generates HTML canvas API calls and executes them on
#' the worker thread using a JavaScript `OffscreenCanvas`. Once drawing has
#' finished, a JavaScript `ImageBitmap` object is transmitted to the main webR
#' thread for display.
#'
#' The resulting webR output messages are of type `Message` with the `type`
#' property set as `'canvas'` and the `data` property populated with further
#' details about the event that triggered the message.
#' The resulting webR output messages are of type
#' \href{./js/interfaces/WebRChan.CanvasMessage.html}{`CanvasMessage`}, with
#' the \href{./js/interfaces/WebRChan.CanvasMessage.html#type}{`type`}
#' property set as `'canvas'` and the
#' \href{./js/interfaces/WebRChan.CanvasMessage.html#data}{`data`} property
#' populated with further details about the event that triggered the message.
#'
#' When the graphics device creates a new page an output message is emitted with
#' the `data` property set to `{ event: 'canvasNewPage' }`.
#' the \href{./js/interfaces/WebRChan.CanvasMessage.html#data}{`data`}
#' property set to `{ event: 'canvasNewPage' }`.
#'
#' When bitmap image data is sent to the main thread for display, a message is
#' emitted with the the bitmap additionally included as part of the `data`
#' property, `{ event: 'canvasImage', image: ImageBitmap }`.
#' emitted with the the bitmap additionally included as part of the
#' \href{./js/interfaces/WebRChan.CanvasMessage.html#data}{`data`} property,
#' `{ event: 'canvasImage', image: ImageBitmap }`.
#'
#' A 2x scaling is used to improve the bitmap output visual quality. As such,
#' the width and height of the HTML canvas element should be twice the width and
Expand All @@ -34,8 +39,12 @@ canvas <- function(width=504, height=504, pointsize=12, bg="transparent", ...) {
.Call(ffi_dev_canvas, width, height, pointsize, bg)
}

#' Use the webR canvas device as the default graphics device
#' @param ... Arguments to be passed to the canvas graphics device.
#' Use the webR canvas graphics device
#'
#' Set R options so that the webR canvas graphics device is used as the default
#' graphics device for new plots.
#'
#' @param ... Arguments to be passed to the graphics device.
#' @export
canvas_install <- function(...) {
options(device = function() { webr::canvas(...) })
Expand Down
19 changes: 12 additions & 7 deletions packages/webr/man/canvas.Rd

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

7 changes: 4 additions & 3 deletions packages/webr/man/canvas_install.Rd

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

0 comments on commit 4fe8725

Please sign in to comment.