Public
Edited
Jan 8, 2023
1 fork
Importers
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
viewof fullList = pokemonTable(
pokedexList.filter((mon) => satisfiesFilter(mon, filter)),
{
columns: [
...(view.showBaseStats
? ["baseStats", "total", "hp", "atk", "def", "spa", "spd", "spe"]
: []),
...(view.showAbilities ? ["abilities", "hidden"] : []),
"weightkg",
"heightm",
...(view.showTraining
? ["evYield", "catchRate", "baseFriendship", "baseExp", "growthRate"]
: []),
...(view.showBreeding ? ["eggGroups", "genderCode"] : []),
"category",
"color"
]
}
)
Insert cell
function satisfiesFilter(mon, filter) {
if (filter.name) {
if (!mon.name.toLowerCase().includes(filter.name.toLowerCase())) {
return false;
}
}
if (filter.type1 || filter.type2) {
const testTypes = _.compact([filter.type1, filter.type2]);
if (testTypes.some((type) => !mon.types.includes(type))) {
return false;
}
if (filter.type1 === filter.type2) {
if (mon.types.length > 1) {
return false;
}
}
}
if (filter.eggGroup1 || filter.eggGroup2) {
const testGroups = _.compact([filter.eggGroup1, filter.eggGroup2]);
if (testGroups.some((group) => !mon.eggGroups.includes(group))) {
return false;
}
if (filter.eggGroup1 === filter.eggGroup2) {
if (mon.eggGroups.length > 1) {
return false;
}
}
}
if (!_.isNil(filter.genderCode)) {
if (mon.genderCode !== filter.genderCode) {
return false;
}
}
if (!filter.showGmax && isGmax(mon)) {
return false;
}
if (!!filter.color) {
if (mon.color !== filter.color) return false;
}
if (!!filter.gen) {
if (mon.gen !== filter.gen) return false;
}
return true;
}
Insert cell
function normalizeData(mon) {
return {
...mon,
nameAndForme: {
name: mon.baseSpecies ?? mon.name,
forme: mon.baseSpecies && mon.name.slice(mon.baseSpecies.length + 1)
},
total: baseStatTotal(mon),
...mon.baseStats,
abilities: _.compact([mon.abilities[0], mon.abilities[1]]),
hidden: mon.abilities["H"],
sprite: getSpriteUrl(mon),
genderCode: getGenderCode(mon)
};
}
Insert cell
function renderType(type) {
return `
<span style="background-color: ${typeColors[type]}; padding: 0.25rem 0.25rem; border-radius: 0.25rem; font-family: sans-serif; color: white; align-text: center;">
${type}
</span>
`
}
Insert cell
function renderBaseStats(stats) {
const path = baseStatsPath(stats)
return html`<svg viewbox="-1 -1 2 2" style="height: 3rem; aspect-ratio: 1 / 1">
<path d="${path}" stroke="thistle" fill="lavender" stroke-width="${1/32}" stroke-linejoin="round"/>
</svg>`
}
Insert cell
// Get the svg path of the pokemon's stats
function baseStatsPath(stats) {
const order = ["hp", "spa", "spd", "spe", "def", "atk"];
const STAT_MAX = 255;
const path = d3.path();
let angle = -Math.PI / 2;
for (let stat of order) {
const magnitude = stats[stat] / STAT_MAX;
const point = [Math.cos(angle) * magnitude, Math.sin(angle) * magnitude];
if (stat === "hp") {
path.moveTo(...point);
} else {
path.lineTo(...point);
}
angle -= Math.PI / 3;
}
path.closePath();
return path.toString();
}
Insert cell
statDisplayMap = ({
hp: "HP",
atk: "Atk",
def: "Def",
spa: "Sp.Atk",
spd: "Sp.Def",
spe: "Speed"
})
Insert cell
function pokemonTable(
list,
{
columns = ["baseStats", "total", "hp", "atk", "def", "spa", "spd", "spe"],
rows = 30
} = {}
) {
return Inputs.table(list.map(normalizeData), {
rows,
columns: ["gen", "num", "sprite", "nameAndForme", "types", ...columns],
header: {
genderCode: "genderRatio",
nameAndForme: "pokemon"
},
format: {
gen: (gen) => formatGen(gen),
nameAndForme: ({ name, forme }) => {
return html`
<div>
<div style="font-weight: bold;">${name}</div>
<div>${forme ?? ""}</div>
</div>
`;
},
types: (ts) =>
html`<div style="display: flex; width: 4rem; flex-direction: column; gap: 0.125rem;">${ts.map(
renderType
)}</div>`,
sprite: (spriteUrl) =>
html`<img src="${spriteUrl}" style="max-height:3rem;" />`,
heightm: (h) => h.toFixed(1),
weightkg: (w) => w.toFixed(1),
baseStats: renderBaseStats,
abilities: (abilities) =>
html`<div style="display:flex;flex-direction:column">${abilities.map(
(ability) => `<div>${ability}</div>`
)}</div>`,
evYield: (evYield) => {
return html`<div>
${Object.entries(evYield).map(
([stat, value]) => `<div>${value} ${statDisplayMap[stat]}</div>`
)}
</div>`;
},
eggGroups: (eggGroups) =>
html`<div style="display:flex;flex-direction:column">${eggGroups.map(
(eggGroup) => `<div>${eggGroup}</div>`
)}</div>`,
genderCode: (code) => {
const text = displayGenderRatio(code);
const mPercent = code === -1 ? 0 : (code / 8) * 100;
const fPercent = code === -1 ? 0 : ((8 - code) / 8) * 100;
const nPercent = code === -1 ? 100 : 0;
return html`
<div style="display:flex;flex-direction:column;align-items:center;">
<div style="width:100%; height:1rem; display:flex; border-radius: 8px; overflow:hidden">
<div style="height:100%; background-color:lightskyblue; width: ${mPercent}%"></div>
<div style="height:100%; background-color:pink; width: ${fPercent}%"></div>
<div style="height:100%; background-color:grey; width: ${nPercent}%"></div>
</div>
<div>${text}</div>
</div>
`;
}
}
});
}
Insert cell
import { getGenderCode, displayGenderRatio, baseStatTotal, types, eggGroups, pokedexList, typeColors, isGmax, normalizeName, isRegionalForme, colors, getGeneration, formatGen, getSpriteUrl } from "@tesseralis/pokemon-dataviz"
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