Skip to content

Instantly share code, notes, and snippets.

@danmartens
Created April 29, 2012 19:32
Show Gist options
  • Save danmartens/2552869 to your computer and use it in GitHub Desktop.
Save danmartens/2552869 to your computer and use it in GitHub Desktop.
D3.js Selection Extensions
d3.selection::attrs = (attrs) ->
for key, value of attrs
@attr(key, value)
return this
d3.selection::addClass = (name) ->
@classed(name, true)
return this
d3.selection::removeClass = (name) ->
@classed(name, false)
return this
d3.selection::show = ->
@node()?.style.display = 'inherit'
return this
d3.selection::hide = ->
@node()?.style.display = 'none'
return this
d3.selection::arrangeFront = ->
parentNode = @node().parentNode
parentNode.removeChild(@node())
parentNode.appendChild(@node())
return this
d3.selection::arrangeBack = ->
parentNode = @node().parentNode
parentNode.removeChild(@node())
parentNode.insertBefore(@node(), parentNode.firstChild)
return this
d3.selection::bounds = ->
@node()?.getBBox()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment