I'm attempting to use ViewBox & preserveAspectRatio to automatically adjust my d3.svg.arc when the window size has changed ...
var svg = d3.select("#chart").append("svg")
.append("g")
.attr("viewBox", "0 0 700 500")
.attr("preserveAspectRatio", "xMinYMin meet")
.attr("transform", "translate(" + r + "," + r +") rotate(180) scale(-1, -1)");
I'm a bit confused why it doesn't work at all - I've also attempted to set the preserve to "none" & delete any set margins that I had. yet still no luck - any help or advice would be appreciated.
Here's an example: http://jsfiddle.net/xwZjN/53/
We use viewBox to make the SVG image scalable. viewBox = “0 0 100 100”: defines a coordinate system having x=0, y=0, width=100 units and height=100 units. Thus, the SVG containing a rectangle having width=50px and height=50px will fill up the height and width of the SVG image, and all the dimensions get scaled equally.
Values of width and height: With the width and height values you can change the size of the SVG vector. So, if we want to change the size and make it larger, then set the value for width and height, in viewBox, smaller then the width and height properties of the SVG element.
You are applying viewBox
and preserveAspectRatio
to the g
element, they need to be applied to the svg
element:
var svg = d3.select("#chart").append("svg")
.attr("viewBox", "0 0 700 500")
.attr("preserveAspectRatio", "xMinYMin meet")
.append("g")
.attr("transform", "translate(" + r + "," + r +") rotate(180) scale(-1, -1)");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With