javascript - D3: How to implement horizontally responsive SVG elements? -
it quite straight forward implement responsive svg elements below.
<div id="chartid"/> var svg = d3.select("#chartid") .append("svg") .attr("preserveaspectratio", "xminymin meet") .attr("viewbox", "0 0 600 400"); svg.append("rect") .attr("fill","blue") .attr("x", 10) .attr("y", 10) .attr("width", 500) .attr("height", 500);
the following takes place when window size shrank.
before shrinking
after shrinking
as can seen rect angle horizontally , vertically responsive.
but, how can implement svg element horizontally responsive , following takes place?
one option redraw svg element every time window size changed, know if there more sophisticated solution available.
the preserveaspectratio attribute determines scaling , alignment used fit viewbox in svg. when preserveaspectratio = "xminymin meet", content scaled uniformly (i.e. horizontal , vertical scaled @ same ratio). when preserveaspectratio = "none", content scaled non-uniformly. in code, change...
.attr("preserveaspectratio", "xminymin meet")
to...
.attr("preserveaspectratio", "none")
Comments
Post a Comment