Spaces:
Running
Running
Download bio.js from dinoclub/Project_66: direct link, hf CLI and curl.
- Browser
- Download file 30.5 kB
-
https://huggingface.co/spaces/dinoclub/Project_66/resolve/main/bio.js
- Command line
-
hf download hf://spaces/dinoclub/Project_66/bio.js
-
curl -L -o bio.js https://huggingface.co/spaces/dinoclub/Project_66/resolve/main/bio.js
30.5 kB
| /* Member profile ("bio") view. Route: #m-<bioguide>. Data: bios.json (one record per member), cd116/cd118/cd119.json (district outlines). | |
| Shares helpers defined in index.html: $, esc, pct, usdS, tit, SHORT, PTEXT, KIND, ABBR, topo. */ | |
| let BIOS = null, BIO_CUR = null, BIO_C = null; | |
| const SHAPES = {}; | |
| const PARTY = {D: "Democrat", R: "Republican", I: "Independent"}; | |
| const STATE_NAME = {AL:"Alabama",AK:"Alaska",AZ:"Arizona",AR:"Arkansas",CA:"California",CO:"Colorado",CT:"Connecticut",DE:"Delaware",FL:"Florida",GA:"Georgia",HI:"Hawaii",ID:"Idaho",IL:"Illinois",IN:"Indiana",IA:"Iowa",KS:"Kansas",KY:"Kentucky",LA:"Louisiana",ME:"Maine",MD:"Maryland",MA:"Massachusetts",MI:"Michigan",MN:"Minnesota",MS:"Mississippi",MO:"Missouri",MT:"Montana",NE:"Nebraska",NV:"Nevada",NH:"New Hampshire",NJ:"New Jersey",NM:"New Mexico",NY:"New York",NC:"North Carolina",ND:"North Dakota",OH:"Ohio",OK:"Oklahoma",OR:"Oregon",PA:"Pennsylvania",RI:"Rhode Island",SC:"South Carolina",SD:"South Dakota",TN:"Tennessee",TX:"Texas",UT:"Utah",VT:"Vermont",VA:"Virginia",WA:"Washington",WV:"West Virginia",WI:"Wisconsin",WY:"Wyoming",DC:"District of Columbia",PR:"Puerto Rico"}; | |
| const ORD = n => { n = +n; const s = ["th","st","nd","rd"], v = n % 100; return n + (s[(v - 20) % 10] || s[v] || s[0]); }; | |
| const posLabel = id => SHORT[id] || (PTEXT[id] ? PTEXT[id][0] : id); | |
| const loadBios = () => BIOS ? Promise.resolve(BIOS) : fetch("bios.json").then(r => r.json()).then(d => (BIOS = d)); | |
| const shapeFile = c => (+c >= 119 ? "cd119" : +c === 118 ? "cd118" : +c === 115 ? "cd115" : "cd116"); | |
| const loadShape = n => SHAPES[n] ? Promise.resolve(SHAPES[n]) : fetch(n + ".json").then(r => r.json()).then(d => (SHAPES[n] = d)); | |
| function seatLabel(c) { | |
| if (c.chamber === "Senate") return "Senator, " + (STATE_NAME[c.state] || c.state); | |
| const d = +c.district; | |
| return (STATE_NAME[c.state] || c.state) + (d === 0 || (c.geo || "").endsWith("00") ? " at-large" : "'s " + ORD(d) + " district"); | |
| } | |
| const seatShort = c => c.chamber === "Senate" ? c.state + " Senate" : c.state + "-" + ((c.geo || "").endsWith("00") ? "AL" : +c.district); | |
| function routeBio() { | |
| const h = location.hash.slice(1); | |
| const on = h.startsWith("m-"); | |
| $("#bio").hidden = !on; | |
| document.querySelector(".app").classList.toggle("bio-on", on); | |
| if (!on) { if (typeof layout === "function" && topo) requestAnimationFrame(layout); return; } | |
| const id = h.slice(2); | |
| $("#bio").innerHTML = '<div class="bio-in"><p class="bio-load">Loading the profile</p></div>'; | |
| loadBios().then(() => { | |
| if (!BIOS.members[id]) { $("#bio").innerHTML = '<div class="bio-in"><a class="back" href="#map">← Back to the map</a><p class="bio-load">No scored record for this member.</p></div>'; return; } | |
| BIO_CUR = id; const cs = Object.keys(BIOS.members[id].congresses).sort(); BIO_C = cs[cs.length - 1]; | |
| renderBio(); $("#bio").scrollTop = 0; window.scrollTo(0, 0); | |
| }).catch(() => { $("#bio").innerHTML = '<div class="bio-in"><a class="back" href="#map">← Back to the map</a><p class="bio-load">Could not load the profile data. Reload to try again.</p></div>'; }); | |
| } | |
| window.addEventListener("hashchange", routeBio); | |
| function renderBio() { | |
| const R = BIOS.members[BIO_CUR], cs = Object.keys(R.congresses).sort(), C = R.congresses[BIO_C]; | |
| const first = (R.terms || []).filter(t => t[0] === "rep" || t[0] === "sen").map(t => t[1]).sort()[0]; | |
| const avgKey = C.chamber + "-" + C.party, avg = (BIOS.party_avg[BIO_C] || {})[avgKey]; | |
| const o = R.outside, tr = R.trades, ct = R.courts; | |
| const nCases = ct ? ct.cases.length : null; | |
| let h = '<div class="bio-in">'; | |
| h += '<nav class="bio-nav"><a class="back" href="#map">← Map</a><span class="kick">Congress · a profile · draft data</span></nav>'; | |
| h += '<header class="bio-head"><div class="bio-id"><h1 class="bname">' + esc(R.name || BIO_CUR) + '</h1>'; | |
| h += '<p class="lede">' + PARTY[C.party] + ', ' + esc(seatLabel(C)) + (first ? '. In Congress since ' + first.slice(0, 4) : '') + (R.born ? '. Born ' + R.born : '') + '.</p>'; | |
| h += '<div class="bchips" role="group" aria-label="Congress shown">' + cs.map(c => { const x = R.congresses[c]; return '<button type="button" data-bc="' + c + '" aria-pressed="' + (c === BIO_C) + '">' + ORD(c) + ' · ' + esc(seatShort(x)) + '</button>'; }).join("") + '</div></div>'; | |
| h += '<figure class="bmap"><svg id="bmap" role="img" aria-label="Map of the area this member represents"></svg><figcaption id="bmapcap"></figcaption></figure></header>'; | |
| // tiles | |
| const tile = (k, v, cap, cls) => '<div class="tile' + (cls ? " " + cls : "") + '"><span class="tk">' + k + '</span><b>' + v + '</b><span class="tc">' + cap + '</span></div>'; | |
| h += '<div class="tiles">' + | |
| tile(C.chamber === "Senate" ? "Against their state" : "Against their district", pct(C.gap), C.against + " of " + C.n + " counted votes (narrower or bundled bills count half; averaged by issue), " + ORD(BIO_C) + " Congress", "hot") + | |
| tile("Their party's average", avg == null ? "n/a" : pct(avg), PARTY[C.party] + "s in the " + C.chamber + ", same votes") + | |
| tile("Outside money", o ? usdS(o.sup) + ' <small>for</small>' : "none", o ? usdS(o.opp) + " against, 2018 to 2026" : "no independent spending reported") + | |
| tile("Stock trades", tr ? tr.trades.toLocaleString("en-US") : "0", tr ? (tr.late ? tr.late + " filed late (estimate)" : "since 2019") : "no reports found since 2019") + | |
| tile("Federal court records", ct ? String(nCases) : "pending", ct ? "name matches in their state, D.C. or appeals courts" : "search still running (" + BIOS.courts_searched + " members done)") + '</div>'; | |
| // sections | |
| h += sec("gap", "Against their district, Congress by Congress", "Share of counted votes that went against what most of their constituents are estimated to want, with a 95% range. Ticks show each party's average in the same chamber.", '<div class="chart" id="ch-gap"></div>'); | |
| h += sec("votes", "Every scored vote", "Each dot is one counted vote, placed by date and by how much of their " + (C.chamber === "Senate" ? "state" : "district") + " is estimated to support the position. Filled dots went against that majority.", '<div class="chart" id="ch-votes"></div><div class="tbl" id="tb-votes"></div>'); | |
| h += sec("opinion", "What their " + (C.chamber === "Senate" ? "state" : "district") + " thinks", "Cooperative Election Study estimates for the area they represented in the " + ORD(BIO_C) + " Congress, next to the national figure. Estimates lean toward the state average, so treat gaps of a few points as noise.", '<div class="chart" id="ch-op"></div>'); | |
| h += sec("money", "Money around them", "Independent spending by super PACs, parties and outside groups in their races, by election cycle, and the political action committees that gave to them directly.", '<div class="chart" id="ch-out"></div><div class="pies" id="pies"></div><div class="two"><div id="tb-out"></div><div id="tb-pac"></div></div>'); | |
| h += sec("trades", "Stock trades they disclosed", "Transactions on periodic transaction reports filed with the House Clerk or Senate since 2019. Scanned paper reports are not counted.", '<div class="chart" id="ch-tr"></div><div id="tb-tr"></div>'); | |
| h += sec("courts", "Federal court records naming them", "Dockets from CourtListener's RECAP archive where a party's name matches theirs, in their state, D.C. or an appeals court, placed against their time in office.", '<div class="chart" id="ch-ct"></div><div id="tb-ct"></div>'); | |
| if (R.signed || BIO_C === "119") h += sec("signed", "Bills they signed", "Positions with majority support that have a matching 119th Congress bill in their chamber, and whether they sponsored or cosponsored one.", '<div id="tb-sig"></div>'); | |
| h += '<details class="behind"><summary>Behind the numbers</summary><div class="body-txt">' + | |
| '<p>Votes count when a roll call matches a position at least 66% of adults support nationally, in a survey close in time to the vote, under written selection rules (screen logs and reasons are public in the project folder). Each vote is compared with the estimated majority in the member\'s own district or state; votes where the estimate is within 3 points of 50% are skipped. Partial matches count half. Positions are averaged so one issue cannot dominate.</p>' + | |
| '<p>District estimates shift the national figure by how the place differs from the nation on a matching Cooperative Election Study question, or else by its mix of Democrats, Republicans and others. Outside money: FEC independent expenditures, amendments applied, approximate. Stock trades: parsed electronic filings; "late" means the trade was reported more than 45 days after it happened. Court records are name matches, not verified identities; criminal and bankruptcy matches are held back for review.</p>' + | |
| '<p>Every vote match was re-checked by a second reviewer who did not see the vote counts; the two agreed on 95% of decisions. Votes the reviewer could not settle are marked for review. All figures are a draft until the first public release.</p></div></details>'; | |
| h += '</div>'; | |
| $("#bio").innerHTML = h; | |
| document.querySelectorAll("#bio .bchips button").forEach(b => b.onclick = () => { BIO_C = b.dataset.bc; renderBio(); }); | |
| miniMap(R, C); chGap(R); chVotes(R, C); chOpinion(R, C); chMoney(R); chTrades(R); chCourts(R); tbSigned(R, C); | |
| } | |
| const sec = (id, title, sub, body) => '<section class="bsec" id="s-' + id + '"><h2>' + title + '</h2><p class="bsub">' + sub + '</p>' + body + '</section>'; | |
| const W_ = el => Math.max(300, Math.min(1080, el.getBoundingClientRect().width || 900)); | |
| const svgEl = (el, w, h, label) => d3.select(el).append("svg").attr("viewBox", "0 0 " + w + " " + h).attr("role", "img").attr("aria-label", label).attr("class", "bchart"); | |
| function miniMap(R, C) { | |
| const svg = d3.select("#bmap"), W = 260, H = 200; svg.attr("viewBox", "0 0 " + W + " " + H); | |
| const f = stFips[C.state]; if (!f || !topo) return; | |
| const stateF = topojson.feature(topo, topo.objects.states).features.find(s => s.id === f); | |
| const proj = d3.geoAlbersUsa(), p = d3.geoPath(proj); | |
| if (C.chamber === "Senate") { | |
| proj.fitExtent([[8, 8], [W - 8, H - 8]], stateF); | |
| svg.append("path").attr("d", p(stateF)).attr("class", "mm-on"); | |
| $("#bmapcap").textContent = STATE_NAME[C.state] || C.state; return; | |
| } | |
| const n = shapeFile(BIO_C); | |
| loadShape(n).then(t => { | |
| const fs = topojson.feature(t, t.objects[n]).features.filter(x => x.properties.g.slice(0, 2) === f); | |
| const me = fs.find(x => x.properties.g === C.geo) || fs.find(x => x.properties.g.endsWith(String(C.district).padStart(2, "0"))); | |
| proj.fitExtent([[8, 8], [W - 8, H - 8]], stateF || {type: "FeatureCollection", features: fs}); | |
| svg.selectAll("path.mm").data(fs).join("path").attr("class", d => d === me ? "mm mm-on" : "mm").attr("d", p); | |
| if (stateF) svg.append("path").attr("d", p(stateF)).attr("class", "mm-st"); | |
| $("#bmapcap").textContent = seatShort(C) + ", district lines used in the " + ORD(BIO_C) + " Congress"; | |
| }).catch(() => { $("#bmapcap").textContent = seatShort(C); }); | |
| } | |
| function chGap(R) { | |
| const el = $("#ch-gap"), w = W_(el), h = 240, m = {l: 44, r: 16, t: 14, b: 34}; | |
| const cs = ["116", "117", "118", "119"]; | |
| const x = d3.scaleBand().domain(cs).range([m.l, w - m.r]).padding(.38), y = d3.scaleLinear().domain([0, 1]).range([h - m.b, m.t]); | |
| const s = svgEl(el, w, h, "Share of votes against their district by Congress"); | |
| [0, .25, .5, .75, 1].forEach(v => { s.append("line").attr("x1", m.l).attr("x2", w - m.r).attr("y1", y(v)).attr("y2", y(v)).attr("class", "grid"); | |
| s.append("text").attr("x", m.l - 6).attr("y", y(v) + 3.5).attr("text-anchor", "end").attr("class", "ax").text(v * 100 + "%"); }); | |
| cs.forEach(c => { | |
| const C = R.congresses[c], cx = x(c), bw = x.bandwidth(); | |
| s.append("text").attr("x", cx + bw / 2).attr("y", h - 12).attr("text-anchor", "middle").attr("class", "ax").text(ORD(c)); | |
| const av = BIOS.party_avg[c] || {}; | |
| if (!C) { s.append("text").attr("x", cx + bw / 2).attr("y", y(.06)).attr("text-anchor", "middle").attr("class", "ax dim").text("not scored"); return; } | |
| s.append("rect").attr("x", cx).attr("width", bw).attr("y", y(C.gap)).attr("height", Math.max(1, y(0) - y(C.gap))).attr("class", c === BIO_C ? "bar on" : "bar").append("title").text(ORD(c) + " Congress: " + pct(C.gap) + " against (" + C.against + " of " + C.n + " votes)"); | |
| s.append("line").attr("x1", cx + bw / 2).attr("x2", cx + bw / 2).attr("y1", y(C.lo)).attr("y2", y(C.hi)).attr("class", "whisk"); | |
| s.append("text").attr("x", cx + bw + 4).attr("y", y(C.gap) + 4).attr("text-anchor", "start").attr("class", "val").text(pct(C.gap)); | |
| ["D", "R"].forEach(p => { const v = av[C.chamber + "-" + p]; if (v == null) return; | |
| s.append("line").attr("x1", cx - 6).attr("x2", cx + bw + 6).attr("y1", y(v)).attr("y2", y(v)).attr("class", "tick " + p).append("title").text(PARTY[p] + "s' average, " + C.chamber + ": " + pct(v)); }); | |
| }); | |
| el.insertAdjacentHTML("beforeend", '<div class="lgd2"><span><i class="sw bar"></i>This member</span><span><i class="sw tickD"></i>Democrats\' average</span><span><i class="sw tickR"></i>Republicans\' average</span><span class="dim">Line: 95% range from the number of votes</span></div>'); | |
| } | |
| function allVotes(R) { | |
| const out = []; | |
| Object.entries(R.congresses).forEach(([c, C]) => C.votes.forEach(v => { const t = (BIOS.tests[c] || {})[v[0]]; if (!t) return; | |
| out.push({c, ch: C.chamber, key: v[0], vote: v[1], against: !!v[2], est: v[3], review: !!v[4], date: t[0], bill: t[1], q: t[2], pos: t[3], match: t[4], side: t[5], anchor: t[6], aligned: t[7], url: t[10], oroll: t[11], sess: t[12]}); })); | |
| return out.sort((a, b) => a.date < b.date ? 1 : -1); | |
| } | |
| function chVotes(R, C) { | |
| const V = allVotes(R), el = $("#ch-votes"); | |
| if (!V.length) { el.innerHTML = '<p class="dim">No counted votes.</p>'; return; } | |
| const w = W_(el), h = 300, m = {l: 48, r: 16, t: 16, b: 34}; | |
| const pd = d3.timeParse("%Y-%m-%d"); | |
| const x = d3.scaleTime().domain([pd("2017-01-03"), pd("2027-01-03")]).range([m.l, w - m.r]); | |
| const y = d3.scaleLinear().domain([.45, 1]).range([h - m.b, m.t]); | |
| const s = svgEl(el, w, h, "Counted votes by date and estimated local support"); | |
| [.5, .6, .7, .8, .9, 1].forEach(v => { s.append("line").attr("x1", m.l).attr("x2", w - m.r).attr("y1", y(v)).attr("y2", y(v)).attr("class", v === .5 ? "grid mid" : "grid"); | |
| s.append("text").attr("x", m.l - 6).attr("y", y(v) + 3.5).attr("text-anchor", "end").attr("class", "ax").text(v * 100 + "%"); }); | |
| const CST = {"115": ["2017-01-03", "2019-01-03"], "116": ["2019-01-03", "2021-01-03"], "117": ["2021-01-03", "2023-01-03"], "118": ["2023-01-03", "2025-01-03"], "119": ["2025-01-03", "2027-01-03"]}[BIO_C]; | |
| if (CST) s.append("rect").attr("x", x(pd(CST[0]))).attr("width", x(pd(CST[1])) - x(pd(CST[0]))).attr("y", m.t).attr("height", h - m.b - m.t).attr("class", "term"); | |
| [["2017-01-03", "115th"], ["2019-01-03", "116th"], ["2021-01-03", "117th"], ["2023-01-03", "118th"], ["2025-01-03", "119th"]].forEach(([d, l]) => { | |
| s.append("line").attr("x1", x(pd(d))).attr("x2", x(pd(d))).attr("y1", m.t).attr("y2", h - m.b).attr("class", "grid"); | |
| s.append("text").attr("x", x(pd(d)) + 4).attr("y", h - 12).attr("class", "ax").text(l + " Congress"); }); | |
| s.append("text").attr("x", m.l).attr("y", m.t - 4).attr("class", "ax").text("estimated local support for the position"); | |
| const seen = {}; | |
| V.forEach(v => { const d = pd(v.date); if (!d) return; const k = v.date + (v.est || 0).toFixed(2); const j = (seen[k] = (seen[k] || 0) + 1) - 1; | |
| const cy = y(v.est == null ? .47 : v.est) - j * 7; | |
| const g = s.append("circle").attr("cx", x(d)).attr("cy", cy).attr("r", 5.5).attr("class", "vd" + (v.review ? " rv" : v.against ? " ag" : " ok") + (v.c === BIO_C ? "" : " other")); | |
| g.append("title").text(v.date + " \u00b7 " + v.bill + ": " + v.q + "\nPosition: " + posLabel(v.pos) + "\nVoted " + v.vote + (v.review ? " (held for review, not scored)" : v.against ? " \u2014 against the local majority" : " \u2014 with the local majority") + (v.est != null ? "\nEstimated local support: " + pct(v.est) : "")); }); | |
| el.insertAdjacentHTML("beforeend", '<div class="lgd2"><span><i class="sw ag"></i>Against the local majority</span><span><i class="sw ok"></i>With it</span><span><i class="sw rv"></i>Held for review, not scored</span></div>'); | |
| const sideL = {D: "Democratic-backed", R: "Republican-backed", X: "both parties"}; | |
| const VC = V.filter(v => v.c === BIO_C); | |
| $("#tb-votes").innerHTML = '<h3>' + ORD(BIO_C) + ' Congress: ' + VC.length + ' counted vote' + (VC.length === 1 ? '' : 's') + '</h3>' + (VC.length ? '' : '<p class="dim">No counted votes in this Congress.</p>') + '<div class="scroll"><table class="btab"><thead><tr><th>Date</th><th>Measure</th><th>Position</th><th>Vote</th><th class="n">Local support</th><th>Result</th></tr></thead><tbody>' + | |
| VC.map(v => '<tr><td class="mono">' + v.date + '</td><td><b>' + esc(v.bill) + '</b> ' + esc(v.q) + '<div class="dim">' + ORD(v.c) + ' ' + v.ch + ' ' + (v.url ? '<a href="' + esc(v.url) + '" target="_blank" rel="noopener">roll ' + v.oroll + (v.sess ? ', session ' + v.sess : '') + '</a>' : 'roll ' + esc(v.key.split("-")[0].slice(1))) + ' · ' + (v.match === "partial" ? "partial match" : "direct match") + ' · ' + sideL[v.side] + '</div></td><td>' + esc(posLabel(v.pos)) + '</td><td class="mono">' + v.vote + '</td><td class="n mono">' + (v.est == null ? "n/a" : pct(v.est)) + '</td><td>' + (v.review ? '<span class="chip">held for review</span>' : v.against ? '<span class="chip warn">against</span>' : '<span class="chip">with</span>') + '</td></tr>').join("") + '</tbody></table></div>'; | |
| } | |
| function chOpinion(R, C) { | |
| const el = $("#ch-op"), items = BIOS.op_items[BIO_C] || [], rows = (C.opinion || []).map(([k, v]) => ({it: items[k], v})).filter(r => r.it); | |
| if (!rows.length) { el.innerHTML = '<p class="dim">No survey estimates for this area in this Congress.</p>'; return; } | |
| const w = W_(el), rh = 34, m = {l: Math.min(330, w * .42), r: 50, t: 22, b: 26}, h = m.t + m.b + rows.length * rh; | |
| const x = d3.scaleLinear().domain([0, 1]).range([m.l, w - m.r]); | |
| const s = svgEl(el, w, h, "Local versus national support on survey questions"); | |
| [0, .25, .5, .75, 1].forEach(v => { s.append("line").attr("x1", x(v)).attr("x2", x(v)).attr("y1", m.t - 6).attr("y2", h - m.b).attr("class", v === .5 ? "grid mid" : "grid"); | |
| s.append("text").attr("x", x(v)).attr("y", h - 8).attr("text-anchor", "middle").attr("class", "ax").text(v * 100 + "%"); }); | |
| rows.forEach((r, i) => { const cy = m.t + i * rh + rh / 2; | |
| s.append("text").attr("x", m.l - 10).attr("y", cy + 4).attr("text-anchor", "end").attr("class", "lab").text(r.it[0].length > 58 ? r.it[0].slice(0, 56) + "\u2026" : r.it[0]).append("title").text(r.it[0] + (r.it[1] === "proxy" ? " (proxy for a related position)" : "")); | |
| s.append("line").attr("x1", x(Math.min(r.v, r.it[2]))).attr("x2", x(Math.max(r.v, r.it[2]))).attr("y1", cy).attr("y2", cy).attr("class", "dumb"); | |
| s.append("circle").attr("cx", x(r.it[2])).attr("cy", cy).attr("r", 5).attr("class", "nat").append("title").text("Nation: " + pct(r.it[2])); | |
| s.append("circle").attr("cx", x(r.v)).attr("cy", cy).attr("r", 6).attr("class", "loc").append("title").text((C.chamber === "Senate" ? "State" : "District") + ": " + pct(r.v)); | |
| s.append("text").attr("x", w - m.r + 8).attr("y", cy + 4).attr("class", "val").text(pct(r.v)); }); | |
| el.insertAdjacentHTML("beforeend", '<div class="lgd2"><span><i class="sw loc"></i>' + (C.chamber === "Senate" ? "State" : "District") + '</span><span><i class="sw nat"></i>Nation</span></div>'); | |
| } | |
| const PIEK = {superpac: ["Super PACs", 1], hybrid: ["Hybrid PACs", 2], single: ["Single-candidate PACs", 7], party: ["Party committees", 4], pac: ["Other PACs", 6], nondisclosing: ["Groups not naming donors", 5], | |
| corp: ["Corporations", 1], trade: ["Trade associations", 2], labor: ["Labor unions", 3], member: ["Membership groups", 4], ideol: ["Issue and ideological PACs", 6], coop: ["Cooperatives", 7], lead: ["Other politicians' PACs", 5], other: ["Other", 6]}; | |
| function donut(title, parts, note) { | |
| const tot = d3.sum(parts, p => p[1]); | |
| if (!tot) return ""; | |
| parts = parts.filter(p => p[1] > 0).sort((a, b) => b[1] - a[1]); | |
| const r = 78, ar = d3.arc().innerRadius(r * .62).outerRadius(r), pie = d3.pie().sort(null).value(p => p[1]).padAngle(.012); | |
| const col = k => "var(--k" + ((PIEK[k] || [k, 6])[1]) + ")", lab = k => (PIEK[k] || [k])[0]; | |
| const svg = '<svg viewBox="' + (-r) + ' ' + (-r) + ' ' + 2 * r + ' ' + 2 * r + '" width="' + 2 * r + '" height="' + 2 * r + '" role="img" aria-label="' + esc(title) + '">' + | |
| pie(parts).map(a => '<path class="slice" d="' + ar(a) + '" style="fill:' + col(a.data[0]) + '"><title>' + esc(lab(a.data[0])) + ': ' + usdS(a.data[1]) + '</title></path>').join("") + | |
| '<text class="ctr" text-anchor="middle" y="2">' + usdS(tot) + '</text><text class="ctr2" text-anchor="middle" y="18">total</text></svg>'; | |
| return '<div class="pie"><h3>' + esc(title) + '</h3>' + svg + '<div class="plg">' + parts.map(p => '<div><i style="background:' + col(p[0]) + '"></i><span>' + esc(lab(p[0])) + '</span><span class="mono">' + usdS(p[1]) + '</span><span class="pct mono">' + (p[1] / tot * 100 < 1 ? "<1" : Math.round(p[1] / tot * 100)) + '%</span></div>').join("") + '</div>' + (note ? '<p class="dim">' + note + '</p>' : '') + '</div>'; | |
| } | |
| function chPies(R) { | |
| const o = R.outside, p = R.pac, k = (o && o.kinds) || {}, h = []; | |
| if (o) { | |
| h.push(donut("Spent to help them", Object.keys(k).map(x => [x, k[x][0]]))); | |
| h.push(donut("Spent to defeat them", Object.keys(k).map(x => [x, k[x][1]]))); | |
| } | |
| if (p && p.by_type) h.push(donut("Direct PAC gifts by donor type", Object.keys(p.by_type).map(x => [x, p.by_type[x]]).concat(p.lead ? [["lead", p.lead]] : []), p.lead ? "Includes " + usdS(p.lead) + " from other politicians\u2019 leadership PACs, which the PAC total below leaves out." : "")); | |
| $("#pies").innerHTML = h.join(""); | |
| } | |
| function chMoney(R) { | |
| chPies(R); | |
| const o = R.outside, el = $("#ch-out"); | |
| if (!o) el.innerHTML = '<p class="dim">No independent spending reported in their races, 2018 to 2026.</p>'; | |
| else { | |
| const cyc = Object.keys(o.cycles).sort(), w = W_(el), h = 260, m = {l: 64, r: 16, t: 18, b: 30}; | |
| const mx = d3.max(cyc, c => Math.max(o.cycles[c][0], o.cycles[c][1])) || 1; | |
| const x = d3.scaleBand().domain(cyc).range([m.l, Math.min(w - m.r, m.l + 150 * cyc.length)]).padding(.35), y = d3.scaleLinear().domain([-mx, mx]).nice().range([h - m.b, m.t]); | |
| const s = svgEl(el, w, h, "Outside spending for and against them by cycle"); | |
| y.ticks(5).forEach(v => { s.append("line").attr("x1", m.l).attr("x2", w - m.r).attr("y1", y(v)).attr("y2", y(v)).attr("class", v === 0 ? "grid mid" : "grid"); | |
| s.append("text").attr("x", m.l - 6).attr("y", y(v) + 3.5).attr("text-anchor", "end").attr("class", "ax").text(usdS(Math.abs(v))); }); | |
| cyc.forEach(c => { const [a, b] = o.cycles[c]; | |
| s.append("rect").attr("x", x(c)).attr("width", x.bandwidth()).attr("y", y(a)).attr("height", y(0) - y(a)).attr("class", "bar for").append("title").text(c + ": " + usdS(a) + " supporting"); | |
| s.append("rect").attr("x", x(c)).attr("width", x.bandwidth()).attr("y", y(0)).attr("height", y(-b) - y(0)).attr("class", "bar opp").append("title").text(c + ": " + usdS(b) + " opposing"); | |
| s.append("text").attr("x", x(c) + x.bandwidth() / 2).attr("y", h - 10).attr("text-anchor", "middle").attr("class", "ax").text(c); }); | |
| s.append("text").attr("x", m.l + 4).attr("y", m.t + 10).attr("class", "ax").text("supporting them"); | |
| s.append("text").attr("x", m.l + 4).attr("y", h - m.b - 6).attr("class", "ax").text("opposing them"); | |
| $("#tb-out").innerHTML = '<h3>Biggest outside spenders</h3><table class="btab"><tbody>' + o.top.map(t => '<tr><td>' + esc(/^[A-Z0-9&]{2,6}$/.test(t[0].trim()) ? t[0].trim() : tit(t[0])) + ' <span class="chip' + (t[1] === "nondisclosing" ? " warn" : "") + '">' + KIND[t[1]] + '</span></td><td class="n mono">' + (t[2] ? usdS(t[2]) + " for" : "") + (t[2] && t[3] ? "<br>" : "") + (t[3] ? usdS(t[3]) + " against" : "") + '</td></tr>').join("") + '</tbody></table>' + | |
| ((o.dark_sup + o.dark_opp) > 0 ? '<p class="dim">From groups that need not name their donors: ' + usdS(o.dark_sup) + ' for, ' + usdS(o.dark_opp) + ' against.</p>' : '') + '<p class="dim">Covers all their races in these cycles, including runs for other offices.</p>'; | |
| } | |
| const p = R.pac; | |
| $("#tb-pac").innerHTML = '<h3>Direct PAC gifts' + (p ? ', ' + usdS(p.total) + ' in total' : '') + '</h3>' + (p ? '<div class="hbars">' + p.top.map(t => { const mx = p.top[0][1] || 1; return '<div class="hb"><span class="hl">' + esc(tit(t[0])) + '</span><span class="hv"><i style="width:' + (t[1] / mx * 100) + '%"></i></span><span class="mono">' + usdS(t[1]) + '</span></div>'; }).join("") + '</div><p class="dim">FEC, ' + (p.cycles || []).join(", ") + ' cycles; party, leadership and conduit committees left out.</p>' : '<p class="dim">No PAC gifts matched.</p>'); | |
| } | |
| function chTrades(R) { | |
| const t = R.trades, el = $("#ch-tr"); | |
| if (!t) { el.innerHTML = '<p class="dim">No periodic transaction reports found since 2019.</p>'; return; } | |
| const ys = Object.keys(t.by_year).filter(y => +y >= 2018).sort(), w = W_(el), h = 220, m = {l: 48, r: 16, t: 16, b: 30}; | |
| const x = d3.scaleBand().domain(ys).range([m.l, w - m.r]).padding(.3), y = d3.scaleLinear().domain([0, d3.max(ys, k => t.by_year[k][0]) || 1]).nice().range([h - m.b, m.t]); | |
| const s = svgEl(el, w, h, "Stock trades disclosed per year"); | |
| y.ticks(4).forEach(v => { s.append("line").attr("x1", m.l).attr("x2", w - m.r).attr("y1", y(v)).attr("y2", y(v)).attr("class", "grid"); s.append("text").attr("x", m.l - 6).attr("y", y(v) + 3.5).attr("text-anchor", "end").attr("class", "ax").text(v); }); | |
| ys.forEach(k => { const [n, lo, hi] = t.by_year[k]; | |
| s.append("rect").attr("x", x(k)).attr("width", x.bandwidth()).attr("y", y(n)).attr("height", y(0) - y(n)).attr("class", "bar").append("title").text(k + ": " + n + " trades, between " + usdS(lo) + " and " + usdS(hi)); | |
| s.append("text").attr("x", x(k) + x.bandwidth() / 2).attr("y", h - 10).attr("text-anchor", "middle").attr("class", "ax").text(k); }); | |
| $("#tb-tr").innerHTML = '<div class="tiles small">' + | |
| '<div class="tile"><span class="tk">Reports</span><b>' + t.filings + '</b><span class="tc">' + (t.unparsed ? t.unparsed + " scanned, not counted" : "all read") + '</span></div>' + | |
| '<div class="tile"><span class="tk">Filed late</span><b>' + t.late + '</b><span class="tc">trades reported 45+ days after (estimate)</span></div>' + | |
| '<div class="tile"><span class="tk">Most traded</span><b class="sm">' + t.top.slice(0, 3).map(a => esc(a[0])).join(", ") + '</b><span class="tc">by number of trades</span></div></div>'; | |
| } | |
| function chCourts(R) { | |
| const c = R.courts, el = $("#ch-ct"); | |
| if (!c) { el.innerHTML = '<p class="dim">Not searched yet. The court search is still running (' + BIOS.courts_searched + ' members done).</p>'; return; } | |
| const cases = c.cases.filter(k => k[2]); | |
| const pd = d3.timeParse("%Y-%m-%d"), terms = (R.terms || []).filter(t => t[0] === "rep" || t[0] === "sen"); | |
| if (!cases.length) { el.innerHTML = '<p class="dim">No matching dockets found' + (c.possible ? '; ' + c.possible + ' same-name matches in other states are not shown' : '') + '.</p>'; return; } | |
| const yrs = cases.map(k => +k[2].slice(0, 4)).concat(terms.map(t => +t[1].slice(0, 4))); | |
| const x0 = pd(Math.max(1990, d3.min(yrs) - 1) + "-01-01"), x1 = pd("2027-01-01"); | |
| const w = W_(el), h = 150, m = {l: 16, r: 16, t: 26, b: 30}; | |
| const x = d3.scaleTime().domain([x0, x1]).range([m.l, w - m.r]); | |
| const s = svgEl(el, w, h, "Court records over time against their years in office"); | |
| terms.forEach(t => s.append("rect").attr("x", x(pd(t[1]))).attr("width", Math.max(1, x(pd(t[2])) - x(pd(t[1])))).attr("y", m.t).attr("height", h - m.t - m.b).attr("class", "term")); | |
| s.append("text").attr("x", m.l).attr("y", m.t - 8).attr("class", "ax").text("shaded: years in office"); | |
| x.ticks(8).forEach(d => s.append("text").attr("x", x(d)).attr("y", h - 10).attr("text-anchor", "middle").attr("class", "ax").text(d.getFullYear())); | |
| cases.forEach((k, i) => s.append("circle").attr("cx", x(pd(k[2]))).attr("cy", m.t + 12 + (i % 5) * ((h - m.t - m.b - 24) / 4)).attr("r", 5).attr("class", "vd " + (k[4] ? "rv" : "ag")).append("title").text(k[2] + " \u00b7 " + k[0] + " (" + k[1] + ")")); | |
| el.insertAdjacentHTML("beforeend", '<div class="lgd2"><span><i class="sw ag"></i>Docket naming them</span><span><i class="sw rv"></i>Suit naming many officials at once</span></div>'); | |
| $("#tb-ct").innerHTML = '<div class="scroll"><table class="btab"><tbody>' + c.cases.map(k => '<tr><td class="mono">' + esc(k[2] || "") + '</td><td><a href="' + esc(k[5]) + '" target="_blank" rel="noopener">' + esc(k[0]) + '</a><div class="dim">' + esc(k[1]) + '</div></td><td>' + esc(k[3]) + ' office' + (k[4] ? '<div class="dim">named with many officials</div>' : '') + '</td></tr>').join("") + '</tbody></table></div><p class="dim">Name matches only, not verified to be the same person. Includes suits against them as officials and amicus listings.' + (c.possible ? ' ' + c.possible + ' same-name matches in other states are not shown.' : '') + '</p>'; | |
| } | |
| function tbSigned(R, C) { | |
| const el = $("#tb-sig"); if (!el) return; | |
| const sen = C.chamber === "Senate", mine = new Set(Object.values(R.signed || {}).flat()); | |
| const rows = (BIOS.cosp || []).map(p => ({p, bills: p.bills.filter(b => /^S\d/.test(b[0]) === sen)})).filter(r => r.bills.length); | |
| if (!rows.length) { el.innerHTML = '<p class="dim">No tracked bills in their chamber.</p>'; return; } | |
| const got = rows.filter(r => r.bills.some(b => mine.has(b[0]))).length; | |
| el.innerHTML = '<p class="big2"><b>' + got + '</b> of ' + rows.length + ' tracked positions</p><div class="siggrid">' + rows.map(r => { const g = r.bills.filter(b => mine.has(b[0])); | |
| return '<div class="sig' + (g.length ? ' yes' : '') + '"><span>' + esc(posLabel(r.p.id)) + '</span><span class="mono">' + (g.length ? g.map(b => esc(b[0])).join(", ") : "none signed") + '</span></div>'; }).join("") + '</div><p class="dim">Sponsor or cosponsor of a matching bill; not signing is not opposing. Titles matched by hand, unreviewed.</p>'; | |
| } | |