I believe that I've found a bug in Chrome's SVG rendering however I'd like to know if there are any workarounds.
With code like this:
<html>
<body>
<svg>
<path clip-path="url(#clip)" d="M 0,100 H 1000 V 100" style="stroke: #000; stroke-width: 2px"></path>
<defs>
<clipPath id="clip">
<rect width="400" height="400"></rect>
</clipPath>
</defs>
</svg>
</body>
</html>
There should be a 1000px long horizontal line (path
) clipped by a 400px × 400px rect
.
The line is visible and correctly clipped in Firefox and Internet Explorer (10) but it is completely invisible in Chrome.
There problem only exists if the path
is completely horizontal or vertical as shown in this example.
It is a requirement that the d
attribute of the path
is an equivelent which D3.js can generate.
This is indeed a Chrome bug. If you reverse the order of
<defs>
and the<path>
element, then it works. This is basically the same issue as with the<use>
element.A workaround which I've made work adds an extra
moveto
command to the beginning of thed
attribute:View in browser
The extra
moveto
has no visible effect but means that thepath
is not technically straight. It is visible and clipped correctly in Chrome.