javascript - Why is my SVG image blurry when using a fill pattern? -
i have repeated image on page.
if add manually (via d3.js), image clear, if use image fill pattern blurry.
issue consistent on latest ie, ff, , chrome.
is there way make fill pattern same when manually add images?
js fiddle here, , code included below.
svg code:
<svg> <defs> <symbol id="rack"> <rect height="50" width="50" rx="5" ry="5" fill="#c9cfd6" stroke="#505356" stroke-width="3" /> <line x1="8" y1="8" x2="36" y2="40" stroke="#505356" /> <line x1="36" y1="8" x2="8" y2="40" stroke="#505356" /> </symbol> <!-- using pattern looks blurry!!! --> <pattern id="rack_pattern" patternunits="userspaceonuse" x="0" y="0" width="50" height="50"> <use xlink:href="#rack" /> </pattern> </defs> </svg>
javascript:
// blurry using fill var svg = d3.select("body").style("background-color", "black") .append("svg") .attr("width", 900) .attr("height", 500) .attr("viewbox", "0 0 3700 500") svg.append("rect") .attr("x", 0) .attr("y", 0) .attr("height", 300) .attr("width", 3500) .attr("fill", "url(#rack_pattern)"); var data = []; (var r=0; r<7 ;r++) { (var c=1; c<71; c++) { data.push( { x: 3500 - (c * 50), y: (r * 50) + 320 } ); }; }; // clearer adding iteratively var clear_section = svg.selectall("use") .data(data).enter() .append("use") .attr("xlink:href", "#rack") .attr("x", function(d) { return d.x; }) .attr("y", function(d) { return d.y; });
the rect in symbol not 50 units wide 53 units wide (1/2 stroke pokes out on each edge) pattern subject rescaling. if change rect this
<rect height="47" width="47" rx="5" ry="5" fill="#c9cfd6" stroke="#505356" stroke-width="3" />
it becomes 50 units wide , pattern looks sharper there's no scaling.
Comments
Post a Comment