Skip to content

Instantly share code, notes, and snippets.

@ilyabo
Last active August 29, 2015 14:14
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 ilyabo/3c126045466e1ce33469 to your computer and use it in GitHub Desktop.
Save ilyabo/3c126045466e1ce33469 to your computer and use it in GitHub Desktop.
d3 selection filtering
{"description":"d3 selection filtering","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"tab":"edit","display_percent":0.7,"thumbnail":"http://i.imgur.com/Z4ghHZY.png","fullscreen":false,"ajax-caching":true}
var svg = d3.select("svg")
var nodes = svg.selectAll('.node')
.data(d3.range(50))
.enter()
.append('g')
.attr('class','node')
nodes
.filter(function(d) { return d % 3 === 0 })
.append('rect')
.attr('class', 'node')
.attr('width',20)
.attr('height',20)
.attr('x',function(d) { return d*30})
.attr('y',100)
.attr('fill','black')
nodes
.filter(function(d) { return d % 3 })
.append('circle')
.attr('class', 'node')
.attr('cx',function(d) { return d*30 + 10})
.attr('cy',110)
.attr('r',10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment