Skip to content

Instantly share code, notes, and snippets.

@mathisonian
Last active January 27, 2016 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathisonian/3ab0184bde2a496439c1 to your computer and use it in GitHub Desktop.
Save mathisonian/3ab0184bde2a496439c1 to your computer and use it in GitHub Desktop.
// This can be generalized to arbitrary
// aspect ratios. See last example for
// more on that.
// See calculation for total size in
// example above
var size = 202;
// 1st example - set an explicit
// width and height
d3.select('#example-1')
.append('svg')
.attr('width', size)
.attr('height', size);
// 2nd example - viewbox
d3.select('#example-2')
.append('svg')
.attr('width', '100%')
.attr('viewBox', '0 0 ' + size + ' ' + size);
// Note: all subsequent code inside of the
// viewbox SVG can still assume a width
// and height of 202, and it will automatically
// scale correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment