An SVG is loaded several times in the same page. The SVG is used to show a graphic representation of values. Think of a map where every region shows a given value using a color code.
In each SVG, for every region a CSS class is dynamically applied to match the desired SVG pattern fill used.
CSS styles and patterns are defined in the SVG file. Here is an example:
<svg height="100" width="100">
<style>
/* */
.striped-pain-1 {fill: url(#striped-pain-1);}
/* */
</style>
<defs>
<pattern id="striped-pain-1" width="4" height="1" patternTransform="rotate(45 0 0)" patternUnits="userSpaceOnUse">
<line x1="0" y1="0" x2="0" y2="2" style="stroke:#EABFD5; stroke-width:6"></line>
</pattern>
</defs>
The problem is when on of the SVGs is hidden (via display:none
for example) all SVGs from there to the bottom of the page loose the pattern fill.
I have made a simplified Plunker showing the problem.
https://plnkr.co/edit/F5TzOwDEzneHEW7PT3Ls?p=preview
The only way I have found to prevent this is using different pattern ids
for every SVG, but since all share the same file I don't like the solution to duplicate all of them and rename the ids just for this. I wonder there should be a better solution.