Last active
January 27, 2016 05:08
-
-
Save mathisonian/3ab0184bde2a496439c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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