Skip to content

Instantly share code, notes, and snippets.

@marshallformula
Created November 13, 2017 21:33
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 marshallformula/2784a4d130154f7d09937d5730feb120 to your computer and use it in GitHub Desktop.
Save marshallformula/2784a4d130154f7d09937d5730feb120 to your computer and use it in GitHub Desktop.
d3 margin convention
const totalWidth = 960
const totalHeight = 600
const margin = { top: 20, right: 20, bottom: 20, left: 20}
const width = totalWidth - margin.left - margin.right
const height = totalHeight - margin.top - margin.bottom
const svg = d3.select('#chart').append('svg')
.attr('width', width + margin.left + margin.right)
.attr('height', height + margin.top + margin.bottom)
.append('g')
.attr('transform', `translate(${margin.left}, ${margin.top})`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment