svg_rect {omsvg} | R Documentation |
Addition of a rect
element
Description
The svg_rect()
function adds a rectangle to an svg
object. The position
of the rectangle is given by x
and y
, and this refers to the upper left
point of the rectangle. The width
and the height
are the dimensions of
the rectangle. All of these dimensions are in units of px
. The optional
rx
and ry
parameter are corner radius values (again, in px
units) that
define x and y radius of the corners of the rectangle.
Usage
svg_rect(
svg,
x,
y,
width,
height,
rx = NULL,
ry = NULL,
stroke = NULL,
stroke_width = NULL,
fill = NULL,
opacity = NULL,
attrs = list(),
anims = list(),
filters = list(),
id = NULL
)
Arguments
svg |
The |
x , y |
The |
width , height |
The |
rx , ry |
Optional corner radius values in the 'x' and 'y' directions.
Applies to all corners of the rectangle. If only one value is provided
(say, just for |
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. |
fill |
The fill color of the element. |
opacity |
The opacity of the element. Must be a value in the
range of |
attrs |
A presentation attribute list. The helper function
|
anims |
An animation directive list for the element. This should be
structured using the |
filters |
A filter directive list for the element. This is easily
created by using a list of |
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
if (interactive()) {
# Create an SVG with a single
# rectangle element
svg_1 <-
SVG(width = 100, height = 100) %>%
svg_rect(
x = 20, y = 10,
width = 40, height = 15,
stroke = "blue", fill = "yellow"
)
# Create an SVG with a single
# rectangle element that moves
# to new `x` positions
svg_2 <-
SVG(width = 300, height = 300) %>%
svg_rect(
x = 50, y = 50,
width = 50, height = 50,
stroke = "magenta", fill = "lightblue",
anims = anims(
0.5 ~ list(
anim_position(
x = 50, y = 50,
easing_fn = ease_out()
),
anim_rotation(rotation = 0)
),
2.0 ~ list(
anim_position(
x = 200, y = 50,
easing_fn = ease_in_out()
),
anim_rotation(rotation = 90)
)
)
)
}