addCSS: Use the Cascading Style Sheet within an SVG file

Description Usage Arguments Value Author(s) See Also Examples

Description

This function associates the Cascading Style Sheet with the specified (parsed) SVG document. It can either insert a link or (h)reference to the CSS file (or URL) or can insert its contents directly into the SVG. Inserting the contents is useful if one wants to make the SVG independent of the location of the CSS file, e.g. if the CSS file is a local file and we want the SVG file to be distributed elsewhere. On the other hand, using a reference to the file allows us to have a single copy shared by multiple SVG files, and also facilitates updating the CSS file and having the changes be used by these SVG files without requiring additional processing.

The CSS to be used is determined from the R option "SVGCSS". If this is not set, we look at the environment variable SVGCSS. If that is not set, then we use the default which is in the installed SVGAnnotation package directories.

Usage

1
2
3
addCSS(doc, css = getDefaultSVGCSS(),
       insert = inherits(css, "AsIs") || getOption("InsetScriptContents", FALSE), 
        silent = FALSE)

Arguments

doc

the parsed SVG document

css

the name of the CSS file/URL. By default, we use the CSS file that comes with this package. The R user can specify a different one directly in the call to this function, or by setting the R option named SVGCSS, e.g. options(SVGCSS = "mySVG.css").

insert

a logical value indicating whether to insert the contents of the CSS document into the XML document or add a reference to it.

silent

a logical value that controls whether a warning is emitted if one attempts to insert an already present CSS file. If this is FALSE (the default) a warning informs you; otherwise no message is issued.

Value

The updated XML document.

Author(s)

Duncan Temple Lang

See Also

addECMAScripts svgPlot

compressStyles and convertCSSStylesToSVG

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
  doc = svgPlot(plot(1:10))
  addCSS(doc)
  addCSS(doc)  # get a warning since it is already there.

     # add a reference
  addCSS(doc, "http://www.omegahat.org/OmegaTech.css", FALSE)

    # put the content in directly
  addCSS(doc, insert = TRUE)
     #
  addCSS(doc, I("class {\n  fill: red;\n  stroke: blue;}"))


  saveXML(doc, tempfile())

duncantl/SVGAnnotation documentation built on May 15, 2019, 5:57 p.m.