Skip to content

Commit

Permalink
fix: added option to replace entire values; closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
m-jahn committed Nov 1, 2024
1 parent 801bae2 commit 7d50ba4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: fluctuator
Type: Package
Title: An Interface to Import and Modify SVG (XML) Graphic Files
Version: 0.2.0
Version: 0.2.1
Author: Michael Jahn <michael.jahn@scilifelab.se>
Maintainer: Michael Jahn <michael.jahn@scilifelab.se>
Description: SVG is the primary choice for scalable, open-source graphic files. This packages provides a simple interface to import SVG graphic files in to R, modify these in a programmatic way, and export the files again. The purpose of this package is to overlay scientific data on medium or large scale network representations, which is too laborious and time-consuming to do manually. SVG Graphics have to be drawn beforehand, for example using Inkscape. Objects ("nodes") are than identified and modified using unique IDs/label in R.
Expand Down
6 changes: 5 additions & 1 deletion R/set_attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ set_single_attribute <- function(
modify_node_rec <- function(curr_node, attr, pattern, replacement, changed_nodes = 0) {
att <- XML::xmlGetAttr(curr_node, name = attr)
if (!is.null(att)) {
att <- gsub(pattern, replacement, att)
if (pattern == "") {
att <- replacement
} else {
att <- gsub(pattern, replacement, att)
}
XML::removeAttributes(curr_node, .attrs = attr)
att_list <- stats::setNames(list(curr_node, att), c("node", attr))
do.call(XML::addAttributes, att_list)
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ The most important feature of this package is to change SVG attributes
using the `set_attributes()` function. The function takes four important
arguments: the name (`label`) of the `node` whose attributes should be
changed, and which corresponds to Inkscape object names. The `attribute`
that is supposed to be changed (e.g. `style`). And a pattern +
replacement that modifies the character value of the attribute.
that is supposed to be changed (e.g. `style`). And finally a `pattern`
as well as a `replacement` that modifies the character value of the
attribute. If `pattern` is an empty string (`""`), the entire value of
the attribute will be overwritten with the replacement.

In this example we change the fill color of `node_1` to red. Then we
also change the thickness of the two arrows (reactions) `ABC` and `DEF`.
Expand Down
2 changes: 1 addition & 1 deletion vignettes/README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ get_attributes(SVG, node = "ABC", attr = c("label", "style"))
### Change attributes of SVG

The most important feature of this package is to change SVG attributes using the `set_attributes()` function.
The function takes four important arguments: the name (`label`) of the `node` whose attributes should be changed, and which corresponds to Inkscape object names. The `attribute` that is supposed to be changed (e.g. `style`). And a pattern + replacement that modifies the character value of the attribute.
The function takes four important arguments: the name (`label`) of the `node` whose attributes should be changed, and which corresponds to Inkscape object names. The `attribute` that is supposed to be changed (e.g. `style`). And finally a `pattern` as well as a `replacement` that modifies the character value of the attribute. If `pattern` is an empty string (`""`), the entire value of the attribute will be overwritten with the replacement.

In this example we change the fill color of `node_1` to red. Then we also change the thickness of the two arrows (reactions) `ABC` and `DEF`.

Expand Down
7 changes: 5 additions & 2 deletions vignettes/README.html
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,11 @@ <h3 id="change-attributes-of-svg">Change attributes of SVG</h3>
function takes four important arguments: the name (<code>label</code>)
of the <code>node</code> whose attributes should be changed, and which
corresponds to Inkscape object names. The <code>attribute</code> that is
supposed to be changed (e.g. <code>style</code>). And a pattern +
replacement that modifies the character value of the attribute.</p>
supposed to be changed (e.g. <code>style</code>). And finally a
<code>pattern</code> as well as a <code>replacement</code> that modifies
the character value of the attribute. If <code>pattern</code> is an
empty string (<code>&quot;&quot;</code>), the entire value of the attribute will
be overwritten with the replacement.</p>
<p>In this example we change the fill color of <code>node_1</code> to
red. Then we also change the thickness of the two arrows (reactions)
<code>ABC</code> and <code>DEF</code>.</p>
Expand Down
6 changes: 4 additions & 2 deletions vignettes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ The most important feature of this package is to change SVG attributes
using the `set_attributes()` function. The function takes four important
arguments: the name (`label`) of the `node` whose attributes should be
changed, and which corresponds to Inkscape object names. The `attribute`
that is supposed to be changed (e.g. `style`). And a pattern +
replacement that modifies the character value of the attribute.
that is supposed to be changed (e.g. `style`). And finally a `pattern`
as well as a `replacement` that modifies the character value of the
attribute. If `pattern` is an empty string (`""`), the entire value of
the attribute will be overwritten with the replacement.

In this example we change the fill color of `node_1` to red. Then we
also change the thickness of the two arrows (reactions) `ABC` and `DEF`.
Expand Down

0 comments on commit 7d50ba4

Please sign in to comment.