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); 

jsfiddle

the following takes place when window size shrank.

before shrinking

enter image description here

after shrinking

enter image description here

as can seen rect angle horizontally , vertically responsive.

but, how can implement svg element horizontally responsive , following takes place?

enter image description here

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

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -