Skip to content

Commit

Permalink
Bug fix: multiple transforms are now cumulative (again). Fixes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
coolbutuseless committed Feb 29, 2020
1 parent 83d0f5a commit 1d03996
Show file tree
Hide file tree
Showing 4 changed files with 33 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: minisvg
Type: Package
Title: SVG Document Builder
Version: 0.1.10
Version: 0.1.11
Author: mikefc
Maintainer: mikefc <mikefc@coolbutuseless.com>
Description: Build SVG documents with R.
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

# minisvg 0.1.11 2020-02-29

* Bug fix: multiple transforms are now cumulative (again!). (Fixes Issue #7)

# minisvg 0.1.10 2020-02-22

* Added new `$child` list which tracks the direct child elements by tag name.
Expand Down
17 changes: 9 additions & 8 deletions R/SVGElement.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,6 @@ SVGElement <- R6::R6Class(

do.call(self$append, children)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# If duplicate named attributes are given, keep only the last one
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dups <- rev(duplicated(rev(names(attribs))))
if (any(dups)) {
attribs <- attribs[!dups]
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# If one of the values for an attribute is an SVGElement, convert it
# into an ID
Expand Down Expand Up @@ -143,6 +135,15 @@ SVGElement <- R6::R6Class(
trans <- attribs[names(attribs) == 'transform']
attribs[names(attribs) == 'transform'] <- NULL

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# If duplicate named attributes are given, keep only the last one.
# Make sure to do this *AFTER* all the 'transform' attributes have been
# selected as we want to keep all the transforms and concatenate them.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dups <- rev(duplicated(rev(names(attribs))))
if (any(dups)) {
attribs <- attribs[!dups]
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# If element is animate, animateColor, animateMotion, animateTransform
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-cumulative-transform.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


test_that("transforms are cumulative", {

heart_shadow <- stag$g(
fill = 'grey',
svg_prop$transform$rotate(-10, 50, 100),
svg_prop$transform$translate(-36, 45.5),
svg_prop$transform$skewX(40),
svg_prop$transform$scale(1, 0.5)
)

expect_equal(
heart_shadow$attribs$transform,
"rotate(-10 50 100) translate(-36 45.5) skewX(40) scale(1 0.5)"
)


})

0 comments on commit 1d03996

Please sign in to comment.