Skip to content

Instantly share code, notes, and snippets.

@trtg
Created December 29, 2012 13:30
Show Gist options
  • Save trtg/4406969 to your computer and use it in GitHub Desktop.
Save trtg/4406969 to your computer and use it in GitHub Desktop.
d3 tributary crossfilter custom filters
{"description":"d3 tributary crossfilter custom filters","endpoint":"","display":"html","public":true,"require":[{"name":"crossfilter","url":"https://raw.github.com/jasondavies/crossfilter/filter-custom/crossfilter.min.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"tab":"edit","display_percent":0.7,"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,"hidepanel":false}
//this requires using jason davies' fork of cross-filter
//located here: https://raw.github.com/jasondavies/crossfilter/filter-custom/crossfilter.min.js
var data = [
{id:1, tags:["svg","d3"]},
{id:2, tags:["processing","canvas"]},
{id:3, tags:["webgl","canvas"]},
{id:4, tags:["raphael","svg"]}
];
var xf = crossfilter(data);
var tags = xf.dimension(function(d){return d.tags});
var display = d3.select("#display");
var tag = "svg";
//define custom filter to return
//just records with the tag "svg"
tags.filter(function(d) {
//console.log(d):
if(d.indexOf(tag)>=0)return true;
return false;
})
display.append("br");
display.selectAll("span")
.data(tags.top(Infinity))
.enter()
.append("span")
.text(function(d){return JSON.stringify(d)})
.append("br")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment