SVG clipPath and transformations

svg

Solution

Because the transform applies to the clipPath too.

From the SVG specification...

If clipPathUnits="userSpaceOnUse", the contents of the ‘clipPath’ represent values in the current user coordinate system in place at the time when the ‘clipPath’ element is referenced (i.e., the user coordinate system for the element referencing the ‘clipPath’ element via the ‘clip-path’ property). If attribute ‘clipPathUnits’ is not specified, then the effect is as if a value of 'userSpaceOnUse' were specified.

Problem

I have two nearly identical pieces of code where the right half of a circle should be clipped according to a rectangle. In the first example, all works well: ``` <svg> <clipPath id="cut"> <rect width="100" height="100" x="100" y="50"></rect> </clipPath> <circle class="consumption" cx="100" cy="100" clip-path="url(#cut)" r="50"></circle> </svg> ``` jsfiddle In the second one though, when I am using a translation on the circle to specify its position, nothing is shown anymore. ``` <svg> <clipPath id="cut"> <rect width="100" height="100" x="100" y="50"></rect> </clipPath> <circle class="consumption" transform="translate(100,100)" clip-path="url(#cut)" r="50"></circle> </svg> ``` jsfiddle Why?

Original source