Skip to content

Instantly share code, notes, and snippets.

@mathisonian mathisonian/svg-sizing.js
Last active Jan 27, 2016

Embed
What would you like to do?
// 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
You can’t perform that action at this time.