Created
April 28, 2014 16:21
-
-
Save ruedap/11376847 to your computer and use it in GitHub Desktop.
D3Example class
This file contains 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
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