Update app/static/js/game.js

This commit is contained in:
sistav committed 2026-07-08 22:06:20 -04:00
1 parent 67f08f4fb1
commit b8ff2f4115
1 file changed
+6 -16
+6 -16
View File
@@ -34,8 +34,7 @@ async function init() {
}
}
// Wraps text in an unstyled link to the game on chess.com when we have one.
// Built with createElement/textContent — player names come from the API.
function gameLink(text) {
if (!analysis.game_url) return document.createTextNode(text);
const a = document.createElement("a");
@@ -47,8 +46,7 @@ function gameLink(text) {
return a;
}
// Name plates hug the board: whoever owns the pieces at the top of the board
// gets the top plate, so they follow the flip when the user played black.
function profileLink(username, text) {
const a = document.createElement("a");
a.className = "quiet-link";
@@ -84,7 +82,6 @@ function renderSummary() {
`;
}
// Print-style annotation marks; ordinary moves go unremarked, as in a column.
const NAG_MARKS = { best: "!", good: "", inaccuracy: "?!", mistake: "?", blunder: "??", unknown: "" };
function renderMoveList() {
@@ -142,16 +139,14 @@ function showPly(ply) {
}
}
// ---- Eval graph ----
// viewBox coordinates; the SVG scales uniformly to the board column's width.
const GRAPH = { W: 1000, H: 240, PAD: 10 };
const SVG_NS = "http://www.w3.org/2000/svg";
let graphPts = null; // [{ply, cp}], index == ply
// Compress evals so ±1 pawn uses most of the height and mate scores don't
// flatten everything else (same idea as lichess's curve).
function evalToY(cp) {
const v = Math.atan((cp ?? 0) / 300) / (Math.PI / 2); // -1..1, + = white better
const v = Math.atan((cp ?? 0) / 300) / (Math.PI / 2);
return GRAPH.PAD + ((1 - v) / 2) * (GRAPH.H - 2 * GRAPH.PAD);
}
@@ -171,7 +166,6 @@ function renderEvalGraph() {
svg.innerHTML = "";
svg.setAttribute("viewBox", `0 0 ${GRAPH.W} ${GRAPH.H}`);
// Older cached analyses predate initial_eval_cp; fall back to level.
const startCp = analysis.initial_eval_cp ?? 0;
graphPts = [{ ply: 0, cp: startCp }];
let lastCp = startCp;
@@ -180,9 +174,7 @@ function renderEvalGraph() {
graphPts.push({ ply: m.ply, cp: lastCp });
}
// Ink on paper, like a stock listing: the faint shaded area is White's
// share of the game, the ink line is the story, red dots mark the sins.
// Colors come from the stylesheet's :root variables so the palette has one home.
const theme = getComputedStyle(document.documentElement);
const PAPER = theme.getPropertyValue("--paper").trim();
const INK = theme.getPropertyValue("--ink").trim();
@@ -201,7 +193,6 @@ function renderEvalGraph() {
fill: AREA,
}));
// Equality midline — a solid hairline rule.
const midY = evalToY(0);
svg.appendChild(svgEl("line", {
x1: 0, y1: midY, x2: GRAPH.W, y2: midY,
@@ -221,7 +212,6 @@ function renderEvalGraph() {
}));
}
// Hover crosshair + current-position marker.
svg.appendChild(svgEl("line", {
id: "eval-hover-line", x1: 0, y1: 0, x2: 0, y2: GRAPH.H,
stroke: MUTED, "stroke-width": 1.5, visibility: "hidden",