----------------------------------------------------------
Clipped Path (AKA clipPath)
A clipPath is the path of a SVG shape that can be used in combination with another shape to remove any parts of the combined shape that doesn’t fall within the clipPath. That sounds slightly confusing, so we will break it down a bit to hopefully clarify the explanation.
Let’s imagine that we want to display the intersection of two shapes. What we will do is define our
clipPath
which will act as a ‘cookie cutter’ which can cut out the shape we want (we will choose an ellipse). Then we will draw our base shape (which is analogous to the dough) that we will use our cookie cutter on (our dough will be shaped as a rectangle). The intersection of the cookie cutter and the dough is our clipped path.
Our clipPath (cookie cutter) element is an ellipse;
clipPath (cookie cutter) |
Rectangle element (dough) |
The intersection of the two is the clipped path (shaded grey);
Combination of the ellipse and the rectangle |
The graphic examples above are misleading in the sense that the two basic shapes are not actually displayed. All that results from the use of the
clipPath
is the region that is the intersection of the two.The clipped path |
The following is an example of the code section required to draw the clipped path in conjunction with the HTML file outlined at the start of this chapter. The
clipPath
element is given the ID
‘ellipse-clip’ and a specified size and location. Then when the rectangle is appended. the clipPath
is specified as an attribute (via a URL) using clip-path
.
This will produce a path as follows;
The clipped path |
An example of this in use can bee seen in the difference chart explanation later in the book.
The description above (and heaps of other stuff) is in the D3 Tips and Tricks book that can be downloaded for free (or donate if you really want to :-)).
Hi there, Thanks for every line wrote. You help me a lot.
ReplyDeletePlease, check "difference chart" link. It is broke, pointing for you local machine.
Thanks! I have edited it.
DeleteThanks for this. I’ve been trying to make custom shapes in Inkscape and bring them as vector shapes into Paintshop Pro 8. The crop document size method here in conjunction with saving as an .emf works brilliantly for me. I love both editingso this is great for me.
ReplyDelete