// Money-chart harness: exercises the real renderMoney against a realistic // fixture (spend from 09-04, revenue from 09-06, balance only on the last // day — the deploy-day shape). Asserts chart invariants, not observed shape. function mkSeries() { const rows = []; const start = new Date(Date.UTC(2026, 8, 4)); // 2026-09-04 for (let i = 0; i < 66; i++) { const d = new Date(start.getTime() + i * 86400000); const key = d.toISOString().slice(0, 10); const rev = key >= "2026-09-06" ? 100 + i * 2 : 0; // cumulative climbs rows.push({ day: key, revenue_cum: rev, spend_day: 5 + i, spend_cum: (5 + i) * (i + 1) / 2, oc_balance: i === 65 ? 1160.25 : null, }); } return rows; } moneyData = { caveat: "Balance history begins 2026-11-08: the Open Collective API exposes only the current balance.", balance_history_start: "2026-11-08", balance_current: { value: 1160.25, currency: "USD" }, errors: [], series: mkSeries(), }; moneyLoaded = true; // --- cumulative mode (default) --- renderMoney(); let svg = $("money-body").innerHTML; const count = (re) => (svg.match(re) || []).length; const polys = count(/]*>([^<]*)<\/text>/g)].map(m => ({ x: m[1], y: m[2], t: m[3] })); const yTicks = texts.filter(o => !/^\d{2}-\d{2}$/.test(o.t) && o.t.startsWith("$")); if (yTicks.length !== 5) throw new Error("expected 5 y ticks, got " + yTicks.length + ": " + JSON.stringify(yTicks)); const vals = yTicks.map(o => parseFloat(o.t.replace(/[$,]/g, ""))); for (let k = 1; k < vals.length; k++) { if (!(vals[k] > vals[k - 1])) throw new Error("tick values not ascending bottom-first: " + vals); if (!(parseFloat(yTicks[k].y) < parseFloat(yTicks[k - 1].y))) throw new Error("tick positions not descending"); } if (vals[vals.length - 1] < 1828) throw new Error("top tick " + vals[4] + " does not clear max cumulative 1828"); const xTicks = texts.filter(o => /^\d{2}-\d{2}$/.test(o.t)); if (xTicks.length !== 3) throw new Error("expected 3 date marks, got " + xTicks.length); // Zero tick must sit lowest. const ys = yTicks.map(o => parseFloat(o.y)); if (Math.min.apply(null, ys) !== Math.max.apply(null, ys) && ys[0] !== Math.max.apply(null, ys)) throw new Error("zero tick not lowest"); // --- daily mode: spend bars only, legend relabels, no lines --- setMoneySpendMode("daily"); svg = $("money-body").innerHTML; const rects2 = (svg.match(/