Public
Edited
Dec 4, 2022
2 forks
3 stars
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.cell(
d3.range(8 * 8).map((d) => ({ x: d % 8, y: Math.floor(d / 8) })),
{
x: "x",
y: "y",
fill: (d) => ((d.y + d.x) % 2 ? "seagreen" : "ivory"),
inset: -3
}
),
Plot.text(tidy, {
x: "x",
y: "y",
text: (d) => unicode[d.p.toLowerCase()],
fill: (d) => (isWhite(d.p) ? "white" : "black"),
stroke: (d) => (!isWhite(d.p) ? "white" : "black"),
fontSize: size / 10
})
],
x: { tickFormat: (d) => "abcdefgh"[d], label: null },
y: { tickFormat: (d) => 8 - d, label: null },
margin: 20,
width: size,
height: size
})
Insert cell
isWhite = (p) => p.toUpperCase() === p
Insert cell
size = 480
Insert cell
unicode = ({ r: "♜", n: "♞", b: "♝", q: "♛", k: "♚", p: "♟" })
Insert cell
tidy = board
.flatMap((R, y) => R.map((p, x) => ({ p, x, y })))
.filter((d) => d.p)
Insert cell
board = new FENBoard(fen).board
Insert cell
FENBoard = import("https://cdn.skypack.dev/fen-chess-board?min").then((r) => r.default)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more