Skip to content

Commit

Permalink
plugins/moveElemsAttrsToGroup: merge split-level transforms instead o…
Browse files Browse the repository at this point in the history
…f replacing (fix #10)
  • Loading branch information
deepsweet committed Oct 20, 2012
1 parent b4141bd commit 50b825d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
11 changes: 10 additions & 1 deletion plugins/moveElemsAttrsToGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ exports.moveElemsAttrsToGroup = function(item, params) {
if (item.isElem('g') && !item.isEmpty() && item.content.length > 1) {

var intersection = {},
hasTransform = false,
every = item.content.every(function(g) {
if (g.elem && g.attrs) {
if (!Object.keys(intersection).length) {
Expand All @@ -48,7 +49,15 @@ exports.moveElemsAttrsToGroup = function(item, params) {
item.content.forEach(function(g) {
for (var name in intersection) {
g.removeAttr(name);
item.addAttr(intersection[name]);

if (name === 'transform') {
if (!hasTransform) {
item.attr('transform').value += ' ' + intersection[name].value;
hasTransform = true;
}
} else {
item.addAttr(intersection[name]);
}
}
});
}
Expand Down
8 changes: 8 additions & 0 deletions test/plugins/moveElemsAttrsToGroup.04.orig.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions test/plugins/moveElemsAttrsToGroup.04.should.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 50b825d

Please sign in to comment.