I'm pretty new at SVG and Raphael, but I've been using Illustrator for many years, so I have some assumptions on how it works. I want to combine two paths which should return a single element.
I need to make a speech bubble, but it could be anything really. In this case I tried to make two rect
, one with round corners and another square rect
which was rotated. It looked alright, but when I tried to move the speech bubble, the rotated element moved in the wrong direction, because of the 45 degree rotation.
How can I compbine paths which I can later manipulate as if it was a single element/path?
Here you go DEMO
Note, that it is easier to create triangle via
path()
and not worry about rotation. Good Luck ;)First thing is that you could push your 2 elements into a Raphael set which you would later move with
Element.transform()
. This would let you apply the move handler once, and not twice.Also for your issue, it is acually documented:
If you mean merging paths like using the Illustrator
Pathfinder
panel - turning several paths into one path (not a set of paths), merging overlap - I'm pretty sure there's no direct Raphael or SVG equivalent.The closest thing is, creating a compound path (aka composite path) - the equivalent of
cmd-8
orObject > Make Compound Path
in Illustrator. This merges paths together into one path, but doesn't remove areas of overlap.Basically, for a set
paper.set( paper.path('M0,0 4,0 0,4z'),paper.path('M9,9 4,9 9,4z') );
, an equivalent compound path would bepaper.path('M0,0 4,0 0,4z M9,9 4,9 9,4z');
- just joining the path definitions into one, each starting with its ownM
.Some differences to Raphael sets:
toFront()
changes the order within the set, and transforms centre around each item, like Illustrator'stransform each
, unless you give the transform static co-ordinates.JSBIN demo - compare the gradients, and see how the compound pair is just one path on the DOM.
Here's a simple plugin that adds the ability to take a set and create a compound path from it:
Then use it like this:
Note that it only combines paths in a set - if you need to combine other shapes with paths, you'll need a way to convert them into paths first.