Public
Edited
Jul 20, 2024
Insert cell
Insert cell
stringFields = ['sex', 'nationality'].map(d => ({label: d, value: vg.column(d)}));
Insert cell
numFields = ['weight', 'height', 'gold', 'silver'].map(d => ({label: d, value: vg.column(d)}));
Insert cell
data = FileAttachment("athletes.parquet")
Insert cell
pq.readParquet(new Uint8Array(await data.arrayBuffer()))
Insert cell
pq = {
const pq = await import("https://unpkg.com/parquet-wasm@0.1.1/web.js");
// default seems to need to resolve first?
await pq.default();
return pq;
}
Insert cell
athletes = FileAttachment("athletes.parquet")
Insert cell
viewof regression = {
await vg
.coordinator()
.exec([
vg.loadObjects("athletes", FileAttachment("athletes.parquet").parquet())
]);

const $query = vg.Selection.intersect();

const $x = vg.Param.value(numFields[0].value);
const $y = vg.Param.value(numFields[1].value);
const $color = vg.Param.value(stringFields[0].value);

return vg.vconcat(
vg.hconcat(
vg.menu({ label: "X-axis", as: $x, options: numFields }),
vg.menu({ label: "Y-axis", as: $y, options: numFields }),
vg.menu({ label: "Color", as: $color, options: stringFields })
),
vg.plot(
vg.dot(vg.from("athletes"), {
x: vg.sql`${$x}`,
y: vg.sql`${$y}`,
fill: vg.sql`${$color}`,
r: 2,
opacity: 0.05
}),
vg.regressionY(vg.from("athletes", { filterBy: $query }), {
x: vg.sql`${$x}`,
y: vg.sql`${$y}`,
stroke: vg.sql`${$color}`
}),
vg.intervalXY({
as: $query,
brush: { fillOpacity: 0, stroke: "currentColor" }
})
// vg.xyDomain(vg.Fixed),
// vg.colorDomain(vg.Fixed)
)
);
}
Insert cell
// import vgplot and configure Mosaic to use DuckDB-WASM
vg = {
const vg = await import('https://cdn.jsdelivr.net/npm/@uwdata/vgplot@0.7.1/+esm');
vg.coordinator().databaseConnector(vg.wasmConnector());
return vg;
}
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