svg_line: Addition of an 'line' element

Description Usage Arguments Value Examples

View source: R/elements.R

Description

The svg_line() function adds a line to an svg object. The line is drawn using a start point (x1 and y1) and an end point (x2 and y2) points. These positions are in units of px.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
svg_line(
  svg,
  x1,
  y1,
  x2,
  y2,
  stroke = NULL,
  stroke_width = NULL,
  opacity = NULL,
  attrs = list(),
  anims = list(),
  filters = list(),
  id = NULL
)

Arguments

svg

The svg object that is created using the SVG() function.

x1, y1

The x and y positions of the line's start point.

x2, y2

The x and y positions of the line's end point.

stroke

The color of the stroke applied to the element (i.e., the outline).

stroke_width

The width of the stroke in units of pixels.

opacity

The opacity of the element. Must be a value in the range of 0 to 1.

attrs

A presentation attribute list. The helper function svg_attrs_pres() can help us easily generate this named list object. For the most part, the list's names are the presentation attribute names and the corresponding values are the matching attribute values.

anims

An animation directive list for the element. This should be structured using the anims() function.

filters

A filter directive list for the element. This is easily created by using a list of filter_*() functions (e.g., list(filter_gaussian_blur(2), filter_drop_shadow(2, 2))).

id

An optional ID value to give to the built tag. This is useful for modifying this element in a later function call or for interacting with CSS.

Value

An svg object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
if (interactive()) {

# Create an SVG with a single
# line element
svg <-
  SVG(width = 100, height = 50) %>%
    svg_line(
      x1 = 5, y1 = 5,
      x2 = 95, y2 = 45,
      stroke = "blue"
    )
}

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