You have two options for getting SVG to adapt to window size.
"" " " . SVG, ( ) CSS . SVG viewBox, , . , , , . , , .
, - tween:
http://fiddle.jshell.net/h8Mg9/
Key code:
var svg = d3.select("body").append("svg")
.attr("height", "100%")
.attr("width", "100%")
.attr("viewBox",
"0 0 " + (margin.left + diameter + margin.right) +
" " + (margin.top + diameter + margin.bottom) )
.attr("preserveAspectRatio", "xMidYMid meet");
, , 100px . , - .
- , svg . . , . , ; , .
tween demo:
http://fiddle.jshell.net/h8Mg9/2/
Key code:
function setSize() {
var svgStyles = window.getComputedStyle(svg.node());
diameter = Math.min(
(parseInt(svgStyles["width"])
- margin.left - margin.right),
(parseInt(svgStyles["height"])
- margin.top - margin.bottom) );
arc.outerRadius(diameter/2)
.innerRadius(diameter/2 - ringThickness);
vis.attr("transform",
"translate(" + (margin.left + diameter/2) + ","
+ (margin.top + diameter/2) + ")");
background.attr("d", arc);
if(!transitioning) {
foreground.attr("d", arc);
label.attr("transform", function(d) {
return "translate("+arc.centroid(d)+")"
});
}
}
setSize();
window.addEventListener("resize", setSize, false)
, , externalRadius. . .
, ( ) , . , , , .. , .