Skip to content

Instantly share code, notes, and snippets.

Forked from dandavison/
Last active December 17, 2015 22:29
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
class BaseChart
width: 100
height: 100
_margin: {}
@margin: top: 0, right: 0, bottom: 0, left: 0
@chart: ->
instance = new this
chart = (selection) ->
selection.each (d, i) -> instance.draw(this, d, i)
mixedChart = _.extend chart,
instance, _.cloneDeep instance.__proto__
constructor: ->
Object.keys(Vis.margin).forEach (k) =>
@_margin[k] = Vis.margin[k]
draw: (el, d, i) ->
throw new Error 'You must declare a #draw function.'
margin: (margin) ->
return @_margin unless arguments.length
for k,v of margin
@_margin[k] = v
# Generate the getters/setters in the accessors property.
buildAccessors: ->
for name, accessor of @accessors
continue if this[name]?
do (name, accessor) =>
this[name] = (_) ->
return accessor unless arguments.length
accessor = _
class MyChart extends BaseChart
draw: (elem, d, i) ->
# generate chart here; `d` is the data and `elem` is the element
chart = MyChart.chart()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment