SVG_: Create a compact 'svg' object

Description Usage Arguments Value Examples

View source: R/SVG.R

Description

The SVG_() function is a variation on SVG() (the entry point for building an SVG) in that the output tags will be as compact as possible (fewer linebreaks, less space characters). This is a reasonable option if the eventual use for the generated SVG is as inline SVG within HTML documents.

Usage

1
SVG_(width = NULL, height = NULL, viewbox = TRUE)

Arguments

width

The width and height attributes on the top-level <svg> element. Both of these attributes are optional but, if provided, take in a variety of dimensions and keywords. If numerical values are solely used, they are assumed to be 'px' length values. Dimensions can be percentage values (i.e., "75%") or length values with the following units: "em", "ex", "px", "in", "cm", "mm", "pt", and "pc". Using NULL, the default, excludes the attribute.

height

The width and height attributes on the top-level <svg> element. Both of these attributes are optional but, if provided, take in a variety of dimensions and keywords. If numerical values are solely used, they are assumed to be 'px' length values. Dimensions can be percentage values (i.e., "75%") or length values with the following units: "em", "ex", "px", "in", "cm", "mm", "pt", and "pc". Using NULL, the default, excludes the attribute.

viewbox

An optional set of dimensions that defines the SVG viewBox attribute. The viewBox for an SVG element is the position and dimension, in user space, of an SVG viewport. If supplied, this could either be in the form of a four-element, numeric vector corresponding to the "min-x", "min-y", "width", and "height" of the rectangle, or, as TRUE which uses the vector c(0, 0, width, height). Using NULL, the default, excludes this attribute.

Value

An svg object.

Examples

1
2
3
4
5
6
7
8
if (interactive()) {

# Create a simple SVG with a rectangle and a circle
svg <-
  SVG_(width = 100, height = 50) %>%
  svg_rect(x = 0, y = 0, width = 30, height = 20) %>%
  svg_circle(x = 50, y = 10, diameter = 20)
}

rich-iannone/omsvg documentation built on March 11, 2021, 5:13 p.m.