// A utility for creating "full size" graphics programs with D3.js. // Useful for full-screen graphics, or graphics indended for use inside iFrames. function fullsize(render){ // Append a div to the body, // make it fill the display using CSS, // store a reference to the DOM node for later use. var div = d3.select("body") .append("div") .style("position", "fixed") .style("left", "0px") .style("right", "0px") .style("top", "0px") .style("bottom", "0px") .node(); // Append an SVG as a child of the container DOM node. var svg = d3.select(div) .append("svg"); // This function updates the size of the SVG // and invokes the render() function. function redraw(){ // Extract the width and height that was computed by CSS. var width = div.clientWidth; var height = div.clientHeight; // Use the extracted size to set the size of an SVG element. svg .attr("width", width) .attr("height", height); // Invoke the render function passed into fullsize(). render(svg, width, height); } // Draw for the first time to initialize. redraw(); // Redraw based on the new size whenever the browser window is resized. window.addEventListener("resize", redraw); }