Public
Edited
Jun 28, 2022
1 fork
6 stars
Insert cell
Insert cell
Insert cell
viewof chart = {
const brush = vl.selectInterval("brush").encodings("y");

const base = vl
.markBar()
.select(brush)
.encode(
vl.x().count(),
vl.y().fieldQ("Horsepower"),
vl.color().if(brush, vl.value("steelblue")).value("gray")
)
.height(maxY);

return base.data(data).render();
}
Insert cell
Insert cell
update = {
// From https://codepen.io/keckelt/pen/bGNQPYq?editors=1111
// brush_y -> brush_tuple -> brush
// Updates on pixels
chart.signal("brush_y", [by0, maxY / 2]);
await chart.runAsync();
}
Insert cell
Insert cell
Insert cell
chart.getState(false, true).signals
Insert cell
Insert cell
viewof chart2 = {
const brush = vl.selectInterval("brush").encodings(["y", "x"]);

const base = vl
.markPoint()
.select(brush)
.encode(
vl.x().fieldQ("Displacement"),
vl.y().fieldQ("Horsepower"),
vl.color().if(brush, vl.value("steelblue")).value("gray")
)
.height(maxY);

return base.data(data).render();
}
Insert cell
update2 = {
chart2.signal("brush_x", [0, by0]);
chart2.signal("brush_y", [0, by0]);
await chart2.runAsync();
}
Insert cell
Insert cell
viewof country = Scrubber(d3.group(data, (d) => d.Origin).keys(), {
delay: 1000
})
Insert cell
viewof chart3 = {
const brush = vl.selectPoint("brush").fields("Origin");

const base = vl
.markBar()
.select(brush)
.encode(
vl.x().count(),
vl.y().fieldN("Origin"),

vl.color().if(brush, vl.value("steelblue")).value("gray")
)
.height(maxY);

return base.data(data).render();
}
Insert cell
update3 = {
// To reverse engineer the format I used JSON.stringify(chart3.getState().signals.brush_tuple)

chart3.signal("brush_tuple", {
unit: "",
fields: [{ type: "E", field: "Origin" }],
values: [country]
});

await chart3.runAsync();
}
Insert cell
data = (await require("vega-datasets@2"))["cars.json"]()
Insert cell
import { vl } from "@vega/vega-lite-api-v5"
Insert cell
import { Scrubber } from "@mbostock/scrubber"
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