rk.paste.JS.graph: Paste simple JavaScript plot code

View source: R/rk.paste.JS.graph.R

rk.paste.JS.graphR Documentation

Paste simple JavaScript plot code

Description

This function is similar to rk.paste.JS, but adds some code parts to its output which are commonly used to generate plots with RKWard.

Usage

rk.paste.JS.graph(
  ...,
  plotOpts = NULL,
  printoutObj = NULL,
  level = 2,
  indent.by = rk.get.indent(),
  empty.e = rk.get.empty.e(),
  useIsPreview = TRUE
)

Arguments

...

The actual plot code, passed through to rk.paste.JS.

plotOpts

An object generated by rk.XML.embed or rk.plotOptions, i.e. embedded plot options.

printoutObj

An rk.JS.var object fetching the "code.printout" modifier of plotOpts (see examples below!). If NULL and plotOpts is of class rk.plot.opts (as returned by rk.plotOptions), will be fetched from plotOpts automatically.

level

Integer, which indentation level to use, minimum is 1.

indent.by

A character string defining the indentation string to use.

empty.e

For rk.JS.ite objects only: Logical, if TRUE will force to add empty else {} brackets when there is no else statement defined, which is considered to enhance code readability by some.

useIsPreview

Logical, defines which variable name shoud be used to toggle previews. If TRUE will use the newer and recommended approach (js(if("!is_preview"){...}), otherwise the now deprecated js(if("full"){...}) approach, which is only still included for backward compatibility.

Details

The contents of the ... argument are evaluated by rk.paste.JS and encapsulated between if(!is_preview){rk.graph.on()} try({ and }) if(!is_preview){rk.graph.off()}. If generic plot options are supplied, their "code.preprocess" and "code.calculate" modifiers are also automatically taken care of, so you only need to include "code.printout" inside of ....

Value

A character string.

See Also

rk.paste.JS

Examples

tmp.var.selectVars <- rk.XML.varselector(label="Select data")
tmp.var.x <- rk.XML.varslot(label="My data", source=tmp.var.selectVars, required=TRUE)
# let this be the embedded generic plot options in yout plot dialog
tmp.plot.options <- rk.plotOptions()

# you can now generate the plot code using generic plot options
js.prnt <- rk.paste.JS.graph(
 echo("\t\tplot("),
 echo("\n\t\t\tx=", tmp.var.x),
 echo(tmp.plot.options),
 echo(")"),
 plotOpts=tmp.plot.options)

cat(js.prnt)

rkward-community/rkwarddev documentation built on May 9, 2022, 3:02 p.m.