Public
Edited
Dec 13
1 star
Insert cell
Insert cell
Insert cell
Insert cell
rarity = d3.scalePoint(["Legendary", "Rare", "Uncommon", "Common"], [0.2, 1])
Insert cell
list = (aspect) =>
d3.sort(
all.filter(
(d) =>
d.aspects[0]?.attributes.name === aspect &&
d.type.attributes.name !== "Base"
),
(d) =>
["Leader", "Unit", "Event", "Upgrade"].indexOf(
d.type.attributes.name
),
(d) => d.title
)
Insert cell
Insert cell
cards
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
cards = {
if (cached) {
yield set.file.json();
} else {
let cards = [];
let page = 1;
while (true) {
const res = await fetch(
`https://cors-proxy.visnup.vercel.app/admin.starwarsunlimited.com/api/card-list?locale=en&orderBy[expansion][id]=asc&sort[0]=type.sortValue%3Aasc%2C%20expansion.sortValue%3Adesc%2CcardNumber%3Aasc%2C&filters[$and][0][variantOf][id][$null]=true&filters[$and][1][expansion][id][$in][0]=${set.id}&aspectMethod=0&traitMethod=0&pagination[page]=${page}&pagination[pageSize]=250`
);
const json = await res.json();
cards = cards.concat(json.data.map((d) => d.attributes));
yield cards;
if (json.data.length === 0) break;
page++;
}
}
}
Insert cell
sets = [
{ name: "Spark of Rebellion", file: FileAttachment("sor@3.json"), id: 2 },
{ name: "Shadows of the Galaxy", file: FileAttachment("shd@5.json"), id: 8 },
{ name: "Twilight of the Republic", file: FileAttachment("twi.json"), id: 18 }
]
Insert cell
all = (await Promise.all(sets.map((d) => d.file.json()))).flat().map((d) => {
for (const [k, v] of Object.entries(d))
if (v && typeof v === "object" && "data" in v) d[k] = v.data;
return d;
})
Insert cell
d3.csvFormat(all)
Insert cell
grouped = d3.rollup(
all.filter(
(d) => d.type.attributes.name !== "Base" && d.reprintOf === null
),
(r) => Math.ceil(r.length / 12),
(d) => d.aspects[0]?.attributes.name
)
Insert cell
d3.sum(grouped.values())
Insert cell
pages = 912 / 12
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