Render a RegionResult onto its model SVG and return the raw SVG string
Source:R/render-svg.R
render_venn_svg.RdLoads the bundled SVG template for `result@model` (or the explicit `model` override), walks the DOM via xml2 to overwrite text content (`Name*`, `Count_*`, `CountSUM_*`, `Title`) and inline `fill:` colors (`Shape*`, `Shape*2` for Euler extras, `Bullet*`), and serializes back to a string.
Usage
render_venn_svg(
result,
model = NULL,
set_names = NULL,
colors = NULL,
title = NULL,
show_names = TRUE,
show_counts = TRUE,
show_items = FALSE,
item_options = NULL,
highlight = NULL
)Arguments
- result
A [`RegionResult-class`].
- model
Optional model id override (filename stem). Default = `result@model`.
- set_names
Optional named character vector mapping letters (`"A"`, `"B"`, ...) to display names. Unspecified letters fall back to `result@dataset@set_names`.
- colors
Optional named character vector mapping letters to fill hex colors. Applies to `BulletX`, `ShapeX`, and `ShapeX2` (Euler extra shapes).
- title
Optional title override. If `NULL`, the template's default title text is preserved.
- show_names
If `FALSE`, blanks every `NameA-I` element.
- show_counts
If `FALSE`, blanks every `Count_*` and `CountSUM_*` element.
- show_items
If `TRUE`, replace the per-region count text with the actual item identifiers (rendered as `<tspan>` lines inside each `Count_*` text node). Default `FALSE`.
- item_options
Named list of overrides for the item-text engine. Recognised keys: `max_items_per_region` (default 20), `ncol_items` (default 1), `truncate_long_names` (default 12; 0 disables), `line_height` (default 10), `font_size` (default 8), `show_counts_with_items` (default `FALSE`), `ellipsis` (default `"..."`). Unknown keys raise a warning.
- highlight
Character vector of region labels (e.g. `c("AB", "ABC")`) or an integer vector of region bitmasks (e.g. the output of [parse_region_expression()]). When set, only the listed regions keep their original fill colour; all other set-shapes are desaturated to `#cccccc` at 25% opacity. Default `NULL` (no spotlight).
Details
For `model = "proportional"`, delegates to [generate_proportional_svg()].
Mirrors Python `render_venn_svg` byte-for-byte except for: (a) the return type is `character` instead of an `SvgImage` wrapper class; (b) xml2 may emit slightly different whitespace/attribute ordering than lxml. Functional content (text, fill colors, structure) is identical.
Examples
ds <- methods::new("VennDataset",
set_names = c("A", "B"),
items = list(A = c("x", "y"), B = c("y", "z")),
item_order = c("x", "y", "z"),
universe_size = 10L, source_path = NULL, format = "csv")
result <- analyze(ds)
svg <- render_venn_svg(result)
nchar(svg) > 0
#> [1] TRUE
# \donttest{
result <- analyze(load_sample("dataset_real_cancer_drivers_4"))
svg <- render_venn_svg(result)
nchar(svg) > 0
#> [1] TRUE
# }