Public
Edited
Apr 12, 2023
6 forks
8 stars
Insert cell
Insert cell
{
const div = html`<div style="display:flex">`;

const charts = new Map();
for (let a of attribs) {
const chart = BrushableBarChart()
.x("value")
.y("key")
.width(width / attribs.length)
.height(500)
.onBrush(selection => {
const keys = selection.map(d => d.key);
cs.dims.get(a).filter(keys.length === 0 ? null : d => keys.includes(d));
update();
});
charts.set(a, chart);
}

function update() {
d3.select(div)
.selectAll(".charts")
.data(attribs)
.join("div")
.attr("class", "charts")
.style("width", width / attribs.length)
.each(function(a) {
const data =
a === "Nationality"
? cs.groups.get(a).top(10)
: cs.groups.get(a).all();
d3.select(this)
.datum(data)
.call(charts.get(a));
});
}

update();

return div;
}
Insert cell
attribs = ["Position", "Nationality", "Overall", "Age"]
Insert cell
cs = {
const cs = crossfilter(data);

cs.dims = new Map();
cs.groups = new Map();
for (let a of attribs) {
const dim = cs.dimension(d => d[a]);
cs.dims.set(a, dim);
cs.groups.set(a, dim.group());
}
return cs;
}
Insert cell
data = (await FileAttachment("fifaData.csv").csv()).map(d3.autoType)
Insert cell
d3 = require("d3@6")
Insert cell
crossfilter = require("crossfilter2")
Insert cell
import { BrushableBarChart } from "@john-guerra/d3-reusable-brushable-barchart-pattern"
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