const getSprite = (() => { const stripForm = ["flabebe", "floette", "florges", "vivillon", "basculin", "furfrou", "magearna", "alcremie",]; return pokemon => { pokemon = pokemon .replace("-alola", "-alolan") .replace("-galar", "-galarian") .replace("-phony", "") // sinistea and polteageist .replace("darmanitan-galarian", "darmanitan-galarian-standard"); if (stripForm.find(s => pokemon.includes(s))) { pokemon = pokemon.replace(/-.*$/, ""); } return `https://img.pokemondb.net/sprites/sword-shield/icon/${pokemon}.png`; } })(); const renderStatPair = (lbl, val, valueClass = "value") => ` ${lbl} ${val} `; const renderStatRow = lines => `
${lines.join("\n")}
`; const renderPokemonTileCluster = (area, { mu, nu, proportion }, scores) => { const textColor = getContrastingTextColor(mu.hex); return `
${(100 * proportion).toFixed(2)}% ${mu.hex}
${ [ ["α =", scores.alpha.toFixed(3)], ["σ =", scores.sigma.toFixed(3)], ["Θ =", scores.bigTheta.toFixed(3)], ["θ =", scores.theta.toFixed(3) + "°"], ["ϕ =", scores.phi.toFixed(3) + "°"], ["δ =", scores.delta.toFixed(3)], ["M =", scores.manhattan.toFixed(3)], ["Ч =", scores.ch.toFixed(3)], ["ℓ =", scores.lightnessDiff.toFixed(3)], ] .map(([lbl, val]) => renderStatPair(lbl, val)) .map(ls => renderStatRow([ls])) .join("\n") }
${ [ ["μ =", `(${mu.vector[0].toFixed(2)},`], ["", mu.vector[1].toFixed(2) + ","], ["", mu.vector[2].toFixed(2) + ")"], ["ν =", `(${nu[0].toFixed(2)},`], ["", nu[1].toFixed(2) + ","], ["", nu[2].toFixed(2) + ")"], ["I =", scores.inertia.toFixed(2)], ["V =", scores.muNuAngle.toFixed(2) + "°"], ["N =", scores.size], ["L =", scores.lightness.toFixed(2)], ["C =", scores.chroma.toFixed(2)], ["β = ", scores.importance.toFixed(2)], ] .map(([lbl, val]) => renderStatPair(lbl, val)) .map(ls => renderStatRow([ls])) .join("\n") }
`; }; const clusterToggles = {}; const renderPokemonTile = (kind, name, { total: { mu, nu, size }, clusters }, scores, bestClusterIndex) => { const clusterToggleId = `${name}-${kind}-pkmn-expand-toggle`; const textColor = getContrastingTextColor(mu.hex); return `
${name.split("-").map(part => part.charAt(0).toUpperCase() + part.substr(1)).join(" ")}
${mu.hex}
${ renderStatRow( [ ["α =", scores.total.alpha.toFixed(3)], ["σ =", scores.total.sigma.toFixed(3)], ["Θ =", scores.total.bigTheta.toFixed(3)], ["θ =", scores.total.theta.toFixed(3) + "°"], ["ϕ =", scores.total.phi.toFixed(3) + "°"], ].map(([lbl, val]) => renderStatPair(lbl, val)) )} ${ renderStatRow( [ ["δ =", scores.total.delta.toFixed(3)], ["M =", scores.total.manhattan.toFixed(3)], ["Ч =", scores.total.ch.toFixed(3)], ["ℓ =", scores.total.lightnessDiff.toFixed(3)], ].map(([lbl, val]) => renderStatPair(lbl, val)) )}
${ renderStatRow( [ ["μ =", `(${mu.vector.map(c => c.toFixed(2)).join(", ")})`, "vector"], ["ν =", `(${nu.map(c => c.toFixed(2)).join(", ")})`, "vector"], ].map(([lbl, val, cls]) => renderStatPair(lbl, val, cls)) )} ${ renderStatRow( [ ["I =", scores.total.inertia.toFixed(2)], ["V =", scores.total.muNuAngle.toFixed(2) + "°"], ["N =", size], ["L =", scores.total.lightness.toFixed(2)], ["C =", scores.total.chroma.toFixed(2)], ].map(([lbl, val, cls]) => renderStatPair(lbl, val, cls)) )} ${ bestClusterIndex < 0 ? "" : `
` } ${ renderStatRow([ `${bestClusterIndex === 0 ? "▼" : ""}`, `${bestClusterIndex === 1 ? "▼" : ""}`, `${bestClusterIndex === 2 ? "▼" : ""}`, `${bestClusterIndex === 3 ? "▼" : ""}`, ])}
${clusters.map((c, i) => renderPokemonTileCluster(`cls${i+1}`, c, scores.clusters[i])).join("\n")}
` };