Public
Edited
Apr 5, 2023
3 stars
Insert cell
Insert cell
Insert cell
<div id="plot" style="width:900px;height:600px"><div id="label" style="position:absolute;top:10px;left:10px;background-color:gray;z-index:100;"</div></div>
Insert cell
{
scatterplot.plotAPI({
encoding: {
foreground: {
field: "candidate",
lambda: `d => ${JSON.stringify(showing)}.indexOf(d) > -1`
}
}
});
}
Insert cell
scatterplot = {
const plot = new deepscatter.default("#plot", 900, 600);
await plot.plotAPI({
arrow_table: votes,
point_size: 2.5,
max_points: 5e5,
zoom_balance: 0.35,
alpha: 40,
background_color: "#FFFAF2",
encoding: {
jitter_size: {},
color: {
field: "candidate",
range: "dark2"
},
x: {
field: "x",
transform: "literal"
},
y: {
field: "y",
transform: "literal"
}
}
});

invalidation.then(() => plot.destroy());
return plot;
}
Insert cell
import { selected_points } from "@fgregg/2023-mayoral-election-dot-density-maps@533"
Insert cell
deepscatter = import("https://benschmidt.org/deepscatter@2.8.0")
Insert cell
import { DuckDBClient, arrow } from "@bmschmidt/trees"
Insert cell
candidates = (await db.query(`SELECT distinct("field") from votes LIMIT 10`))
.toArray()
.map((d) => d.field)
Insert cell
votes = {
enums_made;
const tb = await db.query(`
SELECT x::FLOAT x, (y * -1.5)::FLOAT y, field::candidate candidate, row_number() OVER () AS ix FROM votes`);
return tb;
}
Insert cell
enums_made = {
await db.query(
"CREATE TABLE votes AS SELECT *,row_number() OVER () AS ix FROM 'https://benschmidt.org/selected_points.csv'"
);

return db.query(
`CREATE TYPE candidate AS ENUM (SELECT "field" FROM votes WHERE "field" IS NOT NULL)`
);
}
Insert cell
db = DuckDBClient.of({})
Insert cell
new URL("https://benschmidt.org/selected_points.csv")
Insert cell
selected_points.csv
Type SQL, then Shift-Enter. Ctrl-space for more options.

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