Skip to content

Instantly share code, notes, and snippets.

@ruedap
Created April 28, 2014 16:21
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 ruedap/11376847 to your computer and use it in GitHub Desktop.
Save ruedap/11376847 to your computer and use it in GitHub Desktop.
D3Example class
class D3Example
constructor: (@selector, width, height, @margin, hasBorder) ->
@margin = top: 20, right: 20, bottom: 20, left: 20 unless @margin
@el = @defineRootElement(@selector, +width, +height, @margin, hasBorder)
defineRootElement: (selector, width, height, margin, hasBorder) =>
@width = width - margin.left - margin.right
@height = height - margin.top - margin.bottom
d3.select(selector)
.append('svg')
.attr
width: width
height: height
.append('g')
.attr
transform: "translate(#{margin.left},#{margin.top})"
id: 'margin-convention'
if hasBorder
d3.select(selector)
.select('svg')
.insert('rect', ':first-child')
.attr
width: width
height: height
fill: 'none'
stroke: '#bbb'
'stroke-width': 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment