This documentation may lag behind the latest version, use the documentation provided with the package for up to date information.
The function grid.script()
allows the inclusion of JavaScript text or files
within an SVG image. When used in conjunction with
grid.garnish()
, grid.script()
can
define the behaviour of the SVG document with regards to interactivity.
The usage of the function is defined as follows:
grid.script(script = NULL, filename = NULL,
type = "application/ecmascript",
inline = FALSE, name = NULL)
Typical usage would be to include a JavaScript file (via the filename
parameter), or perhaps include a character vector containing JavaScript code
(using the script
parameter). The inline
parameter is also useful as it can
enable JavaScript to be embedded within an SVG image, rather than linked to an
external resource (this is implied when using the script
argument). A
demonstration of grid.script()
is shown below:
> # Loading gridSVG
> library(gridSVG)
>
> # Including JavaScript using a character vector
> grid.script('alert("Demonstrating interactivity in gridSVG.");')
>
> # Including JavaScript from a file called tooltips.js
> grid.script(filename = "tooltips.js")
Knowledge of JavaScript is required to perform interactivity, but it is not an uncommon language and there is plenty of documentation available to learn it. A good resource for interacting with SVG via JavaScript is available at carto:net.
Applications of grid.script()
are shown in the
arrayQualityMetrics and
Tooltips examples.