[ Launch: ordinal (cross)filtering ] 4720257 by enjalot
[ Launch: ordinal (cross)filtering ] 4720078 by enjalot
-
-
Save enjalot/4720257 to your computer and use it in GitHub Desktop.
dropdown (cross)filtering
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
{"description":"dropdown (cross)filtering","endpoint":"","display":"div","public":true,"require":[{"name":"crossfilter","url":"https://raw.github.com/enjalot/crossfilter/master/crossfilter.min.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"data.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"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} |
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
[ | |
{"name":"ian", "food":"chicken"}, | |
{"name":"dan", "food":"salad"}, | |
{"name":"dan", "food":"chicken"}, | |
{"name":"ian", "food":"salad"}, | |
{"name":"dan", "food":"chicken"}, | |
{"name":"ian", "food":"beef"}, | |
{"name":"dan", "food":"beef"}, | |
{"name":"ian", "food":"chicken"}, | |
{"name":"dan", "food":"salad"}, | |
{"name":"ian", "food":"chicken"}, | |
{"name":"ian", "food":"chicken"}, | |
{"name":"pam", "food":"chicken"}, | |
{"name":"pam", "food":"chicken"}, | |
{"name":"pam", "food":"chicken"}, | |
{"name":"pam", "food":"chicken"}, | |
{"name":"pam", "food":"chicken"} | |
] |
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
//using filter-custom branch of crossfilter from jason davies | |
var xf = crossfilter(); | |
var data = tributary.data; | |
xf.add(data); | |
var name = xf.dimension(function(d) { return d.name }); | |
var food = xf.dimension(function(d) { return d.food }); | |
var display = d3.select("#display"); | |
//possible names | |
var names = ["dan", "ian", "pam"]; | |
//input that manipulates your filter | |
var select = display.append("select") | |
select.selectAll("option.name") | |
.data(names) | |
.enter() | |
.append("option") | |
.classed("name", true) | |
.attr({ | |
value: function(d) { return d } | |
}) | |
.text(function(d) { return d }) | |
select.on("change", function(d) { | |
console.log(this.selectedIndex, names[this.selectedIndex]) | |
//update the filter and rerender our vis | |
updateFilter(names[this.selectedIndex]); | |
}) | |
var svg = display.append("svg") | |
.attr({ | |
class: "chart", | |
width: 400 + "px", | |
height: 400 + "px" | |
}) | |
updateFilter(); | |
function updateFilter(filterName) { | |
//update the filter | |
name.filter(filterName) | |
//update our data by redoing the group | |
var foods = food.group().all(); | |
console.log(foods); | |
//rerender barchart with foods | |
var barSel = svg.selectAll("rect.bar") | |
.data(foods, function(d) { return d.key }); | |
barSel.enter() | |
.append("rect").classed("bar", true) | |
barSel.attr({ | |
width: 20, | |
height: function(d) { return d.value * 10 }, | |
x: function(d,i) { return 100 + i * 25 }, | |
y: function(d) { return 100} | |
}) | |
} | |
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
svg.chart { | |
top: 100px; | |
right: 100px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment