Public
Edited
Apr 25, 2023
Insert cell
Insert cell
Insert cell
Inputs.button([
["One", () => filter("name","one")], // calls the function filter with specific inputs
["Two", () => filter("name","two")],
["Three", () => filter("name","three")],
["Four", () => filter("name","four")],
["Five", () => filter("name","five")],
[">= 2", () => filterGreater("value",2)], // or calls the function filterGreater with inputs
[">= 3", () => filterGreater("value",3)],
[">= 4", () => filterGreater("value",4)]
])
Insert cell
Insert cell
data = [
{"name": "one", "value": 1},
{"name": "two", "value": 2},
{"name": "three", "value": 3},
{"name": "four", "value": 4},
{"name": "five", "value": 5}
]
Insert cell
circles = viz.select("#layer1").selectAll(".mycircle")
.data(data)
.join("circle")
.classed("mycircle", true)
.attr("cx",d => d.value * 100)
.attr("cy", 150)
.attr("r", d => d.value * 10)
.style("fill","steelblue");
Insert cell
Insert cell
Insert cell
dimAll = () => {
// first a function to dim (change opacity) of all of the circle objects
circles.style("opacity",0.1);
}
Insert cell
filter = (field,val) => {
// create a function to increase opacity only for a single element, via its data.
dimAll(); // first we call dimAll to dim all of them.
circles.filter(d => d[field] === val).style("opacity", 1); // find the ones where field = value and change opacity
}
Insert cell
filterGreater = (field,val) => {
// create a function to increase opacity only for a single element, via its data.
dimAll(); // first we call dimAll to dim all of them.
circles.filter(d => d[field] >= val).style("opacity", 1); // find the ones where field = value and change opacity
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more