Merge pull request #286 from Lambro-codes/feat/graph-tooltips
feat(noc): tooltips and clickable legends on the dashboard charts
This commit is contained in:
commit
253927f10c
18 changed files with 214 additions and 18 deletions
|
|
@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
- The NOC charts have tooltips, on the dashboard and on the wallboard in the NOC window: hover (or touch) a chart to see every series on that day, with a total. Click an entry in the legend to hide or show that series, and the scale follows what is left. The "how it arrives" bars on the Traffic tab show the same kind of tooltip, and its legend picks which ways in (caches, PNIs, IX peering, transit) the table counts.
|
||||
## [2.9.1] — 2026-11-04
|
||||
|
||||
- Jokes in the game now poke fun at networks, cables and routers, never at people, countries or beliefs. A few networks have new names (Atlas Hold-the-Line Telecom, Star-Blink, Telekom Malay-tency, Oh Yas Sénégal, Afghan Tele-Pass, Island-Hop Micronesia, Tel-One-derful, Tango Two-Step), so do three of the names for your own cables, and about forty descriptions of networks, cities, cables and events were rewritten.
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ const path = require('node:path');
|
|||
const { load } = require('../../tests/harness');
|
||||
|
||||
const HEADLESS_JS = fs.readFileSync(path.join(__dirname, 'mcp-headless.js'), 'utf8');
|
||||
const ACT_DIR = path.join(__dirname, '..', '..', 'src', 'game', '90-actions');
|
||||
const ACT_DIRS = ['90-actions', '94-dashboard', '96-map'].map((d) => path.join(__dirname, '..', '..', 'src', 'game', d));
|
||||
|
||||
// The arguments of the actions the command tables do not type (the drafts), read from their source
|
||||
// (`dfSrc:({v})=>`): in the page the actions are wrapped for puzzle mode, so their own parameter lists are not visible.
|
||||
|
|
@ -20,8 +20,8 @@ function actArgs() {
|
|||
if (ACT_ARGS) return ACT_ARGS;
|
||||
ACT_ARGS = {};
|
||||
const re = /(?:^|[\s,{])([A-Za-z]\w*):\s*(?:async\s*)?\(\s*\{([^}]*)\}\s*(?:=\s*\{\s*\}\s*)?\)\s*=>/g;
|
||||
for (const f of fs.readdirSync(ACT_DIR).filter((f) => f.endsWith('.js')).sort()) {
|
||||
const src = fs.readFileSync(path.join(ACT_DIR, f), 'utf8');
|
||||
for (const [dir, f] of ACT_DIRS.flatMap((d) => fs.readdirSync(d).filter((f) => f.endsWith('.js')).sort().map((f) => [d, f]))) {
|
||||
const src = fs.readFileSync(path.join(dir, f), 'utf8');
|
||||
for (const m of src.matchAll(re)) if (!ACT_ARGS[m[1]]) ACT_ARGS[m[1]] = m[2].split(',').map((a) => a.split('=')[0].trim()).filter(Boolean);
|
||||
}
|
||||
return ACT_ARGS;
|
||||
|
|
|
|||
|
|
@ -1757,6 +1757,7 @@
|
|||
"dashboard.all_n":"Alle ({n})",
|
||||
"dashboard.amp_huts_and_spares":"Verstärkerhütten und Ersatzteile",
|
||||
"dashboard.caches_pnis_and_ix":"Caches, PNIs und IX",
|
||||
"dashboard.chart_total":"Gesamt",
|
||||
"dashboard.customers_are_upset":"Kunden sind verärgert",
|
||||
"dashboard.delivered_30_days":"Geliefert, 30 Tage",
|
||||
"dashboard.five_nines_ish":"fünf Neunen, so ungefähr",
|
||||
|
|
|
|||
|
|
@ -1755,6 +1755,7 @@
|
|||
"dashboard.all_n":"Todo ({n})",
|
||||
"dashboard.amp_huts_and_spares":"Casetas de amplificación y repuestos",
|
||||
"dashboard.caches_pnis_and_ix":"cachés, PNIs e IX",
|
||||
"dashboard.chart_total":"Total",
|
||||
"dashboard.customers_are_upset":"los clientes están molestos",
|
||||
"dashboard.delivered_30_days":"Entregado, 30 días",
|
||||
"dashboard.five_nines_ish":"casi cinco nueves",
|
||||
|
|
|
|||
|
|
@ -1755,6 +1755,7 @@
|
|||
"dashboard.all_n":"Toutes ({n})",
|
||||
"dashboard.amp_huts_and_spares":"Abris d’amplis et rechanges",
|
||||
"dashboard.caches_pnis_and_ix":"caches, PNI et IX",
|
||||
"dashboard.chart_total":"Total",
|
||||
"dashboard.customers_are_upset":"les clients râlent",
|
||||
"dashboard.delivered_30_days":"Livré, 30 jours",
|
||||
"dashboard.five_nines_ish":"cinq neuf, ou presque",
|
||||
|
|
|
|||
|
|
@ -1755,6 +1755,7 @@
|
|||
"dashboard.all_n":"Tutte ({n})",
|
||||
"dashboard.amp_huts_and_spares":"Shelter amplificatori e ricambi",
|
||||
"dashboard.caches_pnis_and_ix":"cache, PNI e IX",
|
||||
"dashboard.chart_total":"Totale",
|
||||
"dashboard.customers_are_upset":"clienti furiosi",
|
||||
"dashboard.delivered_30_days":"Consegnato, 30 giorni",
|
||||
"dashboard.five_nines_ish":"cinque nove, più o meno",
|
||||
|
|
|
|||
|
|
@ -1755,6 +1755,7 @@
|
|||
"dashboard.all_n":"Todos ({n})",
|
||||
"dashboard.amp_huts_and_spares":"Abrigos de amplificador e reservas",
|
||||
"dashboard.caches_pnis_and_ix":"caches, PNIs e IX",
|
||||
"dashboard.chart_total":"Total",
|
||||
"dashboard.customers_are_upset":"clientes furiosos",
|
||||
"dashboard.delivered_30_days":"Entregue, 30 dias",
|
||||
"dashboard.five_nines_ish":"cinco noves, quase",
|
||||
|
|
|
|||
|
|
@ -415,6 +415,7 @@ const API_CMD={
|
|||
|
||||
const API_VIEW={
|
||||
traceMode:{args:[['m','string']],doc:'Redo the open traceroute in a routing mode: normal, fast or scenic.'},
|
||||
chartToggle:{args:[['c','string'],['k','string']],doc:'Hide or show one series of a dashboard chart (a legend click); hiding every series shows them all again.'},
|
||||
help:{args:[],doc:'Open the how-to-play modal.'},
|
||||
dash:{args:[],doc:'Open the NOC dashboard.'},
|
||||
dashClose:{args:[],doc:'Close the NOC dashboard.'},
|
||||
|
|
|
|||
|
|
@ -161,8 +161,9 @@ function linkPanel(id){
|
|||
return h;
|
||||
}
|
||||
const EGC={c:[tr('common.caches'),'#16A866'],p:[tr('common.pnis'),'#7B61FF'],ix:[tr('common.ix_peering_0631'),'#FFD23F'],t:[tr('common.transit'),'#FF8A3D'],l2:[tr('common.l2_circuits'),'#2F8CFF']};
|
||||
function svgChart(rows,stackKeys,lines,fmtY){
|
||||
const W=600,H=180,L=50,B=20,T=8,Rr=8;if(rows.length<2)return `<p class="empty">${tr('link_panels.collecting_data_check_back_in_a')}</p>`;
|
||||
const CHBOX={W:600,H:180,L:50,B:20,T:8,R:8};
|
||||
function svgChart(rows,stackKeys,lines,fmtY,id){
|
||||
const {W,H,L,B,T,R:Rr}=CHBOX,off=(id&&UI.chartOff&&UI.chartOff[id])||{};stackKeys=stackKeys.filter(k=>!off[k]);lines=lines.filter(ln=>!off[ln.k]);if(rows.length<2)return `<p class="empty">${tr('link_panels.collecting_data_check_back_in_a')}</p>`;
|
||||
let ymax=1;for(const r of rows){let s=0;for(const k of stackKeys)s+=r[k]||0;ymax=Math.max(ymax,s);for(const ln of lines)ymax=Math.max(ymax,r[ln.k]||0);}ymax*=1.1;
|
||||
const x=i=>L+(W-L-Rr)*i/(rows.length-1),y=v=>T+(H-T-B)*(1-v/ymax);let g='';
|
||||
for(let j=0;j<=3;j++){const v=ymax*j/3,yy=y(v);g+=`<line x1="${L}" x2="${W-Rr}" y1="${yy}" y2="${yy}" stroke="#D5DEEC" stroke-width="1"/><text x="${L-6}" y="${yy+3}" text-anchor="end" font-size="10" fill="#55608A" font-weight="700">${fmtY(v)}</text>`;}
|
||||
|
|
@ -170,7 +171,7 @@ function svgChart(rows,stackKeys,lines,fmtY){
|
|||
for(const k of stackKeys){const top=rows.map((r,i)=>base[i]+(r[k]||0));let d=`M${x(0)},${y(top[0])}`;for(let i=1;i<rows.length;i++)d+=`L${x(i)},${y(top[i])}`;for(let i=rows.length-1;i>=0;i--)d+=`L${x(i)},${y(base[i])}`;g+=`<path d="${d}Z" fill="${EGC[k][1]}" fill-opacity=".85" stroke="#1E2640" stroke-width=".8"/>`;top.forEach((v,i)=>base[i]=v);}
|
||||
for(const ln of lines){let d='';rows.forEach((r,i)=>{d+=(i?'L':'M')+x(i)+','+y(r[ln.k]||0);});g+=`<path d="${d}" fill="none" stroke="${ln.col}" stroke-width="2.5" ${ln.dash?'stroke-dasharray="5 4"':''} stroke-linejoin="round"/>`;const last=rows[rows.length-1][ln.k]||0;g+=`<circle cx="${x(rows.length-1)}" cy="${y(last)}" r="3.5" fill="${ln.col}" stroke="#1E2640" stroke-width="1.5"/>`;}
|
||||
g+=`<text x="${L}" y="${H-5}" font-size="10" fill="#55608A" font-weight="700">${dateStr(rows[0].d)}</text><text x="${W-Rr}" y="${H-5}" text-anchor="end" font-size="10" fill="#55608A" font-weight="700">${dateStr(rows[rows.length-1].d)}</text>`;
|
||||
return `<svg class="chart" viewBox="0 0 ${W} ${H}" role="img">${g}</svg>`;}
|
||||
return `<svg class="chart" viewBox="0 0 ${W} ${H}" role="img"${id?` data-ch="${id}"`:''}>${g}</svg>`;}
|
||||
// For a network you currently reach over transit: the cheapest way to move it to peering.
|
||||
// Exchange members as sets, rebuilt once per routing pass: hints are asked for many networks at a time.
|
||||
let IXMR=null,IXMC={};const ixHas=(x,id)=>{if(IXMR!==R){IXMR=R;IXMC={};}return (IXMC[x]||(IXMC[x]=new Set(ixMembers(x)))).has(id);};
|
||||
|
|
|
|||
|
|
@ -7,20 +7,22 @@ function renderDash(){checkLayer();
|
|||
const tile=(l,v,sub)=>`<div class="tile"><div class="lbl">${l}</div><div class="val">${v}</div>${sub?`<div class="sub">${sub}</div>`:''}</div>`;
|
||||
let h=`<div style="display:flex;align-items:center;gap:10px"><div><div class="eyebrow">AS${S.asn} · ${esc(S.name)} · ${tierLabel()}</div><h2 style="font-size:28px">${tr('common.noc_dashboard')}</h2></div><button class="x" data-act="dashClose" aria-label="${tr('common.close')}">×</button></div>`+dashTabs();const DT=UI.dtab||'overview';if(DT==='overview')h+=`
|
||||
<div class="dgrid">${tile(tr('common.traffic_now'),fmtG(R.served),tr('dashboard.of_g_wanted',{g:fmtG(R.demand)}))}${tile(tr('common.peak'),fmtG(S.stats.peak))}${tile(tr('dashboard.delivered_30_days'),(up*100).toFixed(1)+'%',up>=0.999?tr('dashboard.five_nines_ish'):up>=0.99?tr('dashboard.two_nines_and_change'):tr('dashboard.customers_are_upset'))}${tile(tr('common.peering_ratio'),pct(R.peerShare||0),tr('dashboard.caches_pnis_and_ix'))}${tile(tr('dashboard.monthly_p_l'),`<span style="color:${net>=0?'var(--eye)':'var(--bad)'}">${net>=0?'+':''}${fmt$(net)}</span>`,tr('dashboard.in_in_out_out',{in:fmt$(R.revMo),out:fmt$(R.costMo)}))}${tile(tr('common.incidents'),S.stats.incidents,tr('dashboard.n_shrugged_off',{n:S.stats.survived}))}</div>
|
||||
<div class="dcols"><div class="panel2"><h3>${tr('dashboard.traffic_by_way_out')}</h3>${svgChart(rows,['c','p','ix','t','l2'],[{k:'dem',col:'#1E2640',dash:true}],v=>fmtCap(Math.round(v)))}<div class="legend">${Object.keys(EGC).map(k=>`<span><i style="background:${EGC[k][1]}"></i>${EGC[k][0]} ${pct((R.egT[k]||0)/tot)}</span>`).join('')}<span><i style="background:#fff;border-style:dashed"></i>${tr('common.demand')}</span></div></div>
|
||||
<div class="panel2"><h3>${tr('dashboard.money_per_month')}</h3>${svgChart(rows,[],[{k:'rev',col:'#16A866'},{k:'cost',col:'#FF4D5E'}],v=>fmt$(v))}<div class="legend"><span><i style="background:#16A866"></i>${tr('common.revenue')}</span><span><i style="background:#FF4D5E"></i>${tr('common.costs')}</span></div>
|
||||
<div class="dcols"><div class="panel2"><h3>${tr('dashboard.traffic_by_way_out')}</h3>${svgChart(rows,['c','p','ix','t','l2'],[{k:'dem',col:'#1E2640',dash:true}],v=>fmtCap(Math.round(v)),'traffic')}${chartLegend('traffic',k=>k==='dem'?'':' '+pct((R.egT[k]||0)/tot))}</div>
|
||||
<div class="panel2"><h3>${tr('dashboard.money_per_month')}</h3>${svgChart(rows,[],[{k:'rev',col:'#16A866'},{k:'cost',col:'#FF4D5E'}],v=>fmt$(v),'money')}${chartLegend('money')}
|
||||
<h3 style="margin-top:8px">${tr('dashboard.where_the_money_goes')}</h3>${Object.entries(R.cost).filter(([k,v])=>v>0).sort((a,b)=>b[1]-a[1]).map(([k,v])=>`<div class="kv"><span>${{pops:tr('dashboard.pops_and_routers'),links:tr('dashboard.waves_and_fiber'),transit:tr('common.transit'),ix:tr('common.ix_ports'),pni:tr('common.pnis'),caches:tr('common.cache_power'),nni:tr('common.fabric_ports'),optical:tr('dashboard.amp_huts_and_spares'),loans:tr('common.loan_repayments'),revshare:tr('dashboard.investor_revenue_share'),extras:tr('dashboard.licenses_and_scrubbing'),wholesale:tr('dashboard.nearly_broadband_network_wholesale'),levy:tr('dashboard.regional_broadband_levy')}[k]||k}</span><b>${tr('common.price_mo',{price:fmt$(v)})}</b></div>`).join('')}</div></div>`;
|
||||
const tT=(R.egT.t||0)||1;
|
||||
const row=(n,e,want)=>{const t=e.c+e.p+e.ix+e.t;return {n,e,t,want,cost:(R.cost.transit||0)*e.t/tT,lost:want>0.01?Math.max(0,1-t/want):0};};
|
||||
const offMix=(UI.chartOff&&UI.chartOff.mix)||{},filt=Object.keys(offMix).length>0;
|
||||
// The legend above the table picks which ways in count; "lost" still looks at everything the network gets.
|
||||
const row=(n,e0,want)=>{const e={};for(const k of ['c','p','ix','t'])e[k]=offMix[k]?0:e0[k];const t=e.c+e.p+e.ix+e.t,all=e0.c+e0.p+e0.ix+e0.t;return {n,e,t,want,cost:(R.cost.transit||0)*e.t/tT,lost:want>0.01?Math.max(0,1-all/want):0};};
|
||||
const nets=NETS.filter(n=>!n.tail).map(n=>row(n,R.netEg[n.id]||{c:0,p:0,ix:0,t:0},R.demTo[n.id]||0));
|
||||
{const e={c:0,p:0,ix:0,t:0};let w=0;for(const n of NETS)if(n.tail){const x=R.netEg[n.id];if(x)for(const k in e)e[k]+=x[k]||0;w+=R.demTo[n.id]||0;}nets.push(row({id:'_tail',name:tr('dashboard.the_long_tail_n_small_networks',{n:NETS.filter(n=>n.tail).length}),asn:'many',type:'eye',col:'#8A93B8'},e,w));}
|
||||
for(let i=nets.length-1;i>=0;i--)if(!(nets[i].t>0.01||nets[i].want>0.01))nets.splice(i,1);
|
||||
for(let i=nets.length-1;i>=0;i--)if(!(nets[i].t>0.01||(!filt&&nets[i].want>0.01)))nets.splice(i,1);
|
||||
{const k=UI.dashSort||'traffic',dir=UI.dashDir||-1,val=x=>k==='name'?x.n.name.toLowerCase():k==='asn'?x.n.asn:k==='type'?x.n.type:k==='cost'?x.cost:k==='lost'?x.lost:x.t;nets.sort((a,b)=>{const A=val(a),B=val(b);return (A<B?-1:A>B?1:0)*dir||b.t-a.t;});}
|
||||
if(DT==='cust')h+=custSection();
|
||||
if(DT==='conn')h+=connSection();
|
||||
if(DT==='traffic')h+=`<div class="btns">${btn(tr('ops.standing_orders'),'opsOpen',{},'sm')}</div>`;
|
||||
if(DT==='traffic')h+=`<div class="panel2" style="margin-top:12px"><h3>${tr('dashboard.traffic_by_network_asn')}</h3><p class="note" style="margin-top:0">${tr('dashboard.where_your_users_traffic_comes_from')}</p><div class="legend" style="margin:0 0 6px">${['c','p','ix','t'].map(k=>`<span><i style="background:${EGC[k][1]}"></i>${EGC[k][0]}</span>`).join('')}</div><div class="tscroll"><table class="tbl"><thead><tr>${[['name',tr('common.network_6974'),''],['asn','AS',''],['type',tr('common.type'),''],['traffic',tr('common.traffic'),'r'],['mix',tr('dashboard.how_it_arrives'),''],['cost',tr('common.transit_cost'),'r'],['lost',tr('common.lost'),'r']].map(([k,l,c])=>`<th class="${c}">${k==='mix'?l:`<button class="thb" data-act="dashSort" data-args="${esc(JSON.stringify({k}))}">${l}${UI.dashSort===k?(UI.dashDir>0?' ▲':' ▼'):''}</button>`}</th>`).join('')}</tr></thead><tbody>
|
||||
${nets.map(({n,e,t,want})=>{return `<tr><td><span class="nmc">${logo(n)}<b>${esc(n.name)}</b></span>${n.pops&&n.pops.some(c=>S.pops[c])?btn(tr('pni_all.peer_on_all_pops'),'pniAllOpen',{net:n.id},'ghost sm pall'):''}</td><td>${n.asn}</td><td><span class="tag ${n.type}">${TYPE_L[n.type]}</span></td><td class="r">${fmtG(t)}</td><td><div class="mix" title="${['c','p','ix','t'].filter(k=>e[k]>0.01).map(k=>EGC[k][0]+' '+fmtG(e[k])).join(' · ')||tr('common.nothing_yet')}">${t?['c','p','ix','t'].filter(k=>e[k]>0).map(k=>`<i style="width:${+(e[k]/t*100).toFixed(2)}%;background:${EGC[k][1]}"></i>`).join(''):''}</div></td><td class="r">${e.t>0.01?tr('common.price_mo',{price:fmt$((R.cost.transit||0)*e.t/tT)}):'—'}</td><td class="r${want-t>want*0.05?' dlost':''}">${want>0.01?pct(Math.max(0,1-t/want)):'—'}</td></tr>`;}).join('')}</tbody></table></div></div>`;
|
||||
if(DT==='traffic')h+=`<div class="panel2" style="margin-top:12px"><h3>${tr('dashboard.traffic_by_network_asn')}</h3><p class="note" style="margin-top:0">${tr('dashboard.where_your_users_traffic_comes_from')}</p>${chartLegend('mix')}<div class="tscroll"><table class="tbl"><thead><tr>${[['name',tr('common.network_6974'),''],['asn','AS',''],['type',tr('common.type'),''],['traffic',tr('common.traffic'),'r'],['mix',tr('dashboard.how_it_arrives'),''],['cost',tr('common.transit_cost'),'r'],['lost',tr('common.lost'),'r']].map(([k,l,c])=>`<th class="${c}">${k==='mix'?l:`<button class="thb" data-act="dashSort" data-args="${esc(JSON.stringify({k}))}">${l}${UI.dashSort===k?(UI.dashDir>0?' ▲':' ▼'):''}</button>`}</th>`).join('')}</tr></thead><tbody>
|
||||
${nets.map(({n,e,t,want,lost})=>{return `<tr><td><span class="nmc">${logo(n)}<b>${esc(n.name)}</b></span>${n.pops&&n.pops.some(c=>S.pops[c])?btn(tr('pni_all.peer_on_all_pops'),'pniAllOpen',{net:n.id},'ghost sm pall'):''}</td><td>${n.asn}</td><td><span class="tag ${n.type}">${TYPE_L[n.type]}</span></td><td class="r">${fmtG(t)}</td><td><div class="mix" role="img" aria-label="${['c','p','ix','t'].filter(k=>e[k]>0.01).map(k=>EGC[k][0]+' '+fmtG(e[k])).join(' · ')||tr('common.nothing_yet')}" data-mix="${esc(JSON.stringify(Object.fromEntries(['c','p','ix','t'].filter(k=>e[k]>0.01).map(k=>[k,+e[k].toFixed(2)]))))}">${t?['c','p','ix','t'].filter(k=>e[k]>0).map(k=>`<i style="width:${+(e[k]/t*100).toFixed(2)}%;background:${EGC[k][1]}"></i>`).join(''):''}</div></td><td class="r">${e.t>0.01?tr('common.price_mo',{price:fmt$((R.cost.transit||0)*e.t/tT)}):'—'}</td><td class="r${lost>0.05?' dlost':''}">${want>0.01?pct(lost):'—'}</td></tr>`;}).join('')}</tbody></table></div></div>`;
|
||||
if(DT==='traffic'){const top=transitTop(S.transit.map(t=>t.id),8);if(top.length)h+=`<div class="panel2" style="margin-top:12px"><h3>${tr('dashboard.who_your_transit_carries')}</h3><p class="note" style="margin-top:0">${tr('dashboard.the_networks_you_pay_transit_to')}</p>${top.map(([id,v])=>`<div class="row">${logo(NET[id])}<div class="grow"><div class="nm">${esc(NET[id].name)} <span class="meta">AS${NET[id].asn} · ${fmtG(v)} · ${tr('dashboard.about_price_mo',{price:fmt$((R.cost.transit||0)*v/tT)})}</span></div><div class="meta">${esc(offTransitHint(id))}</div></div>${btn(tr('common.where_6276'),'netFocus',{id},'ghost sm')}</div>`).join('')}</div>`;}
|
||||
const ls=S.links.filter(l=>capOf(l)>0).map(l=>({l,u:(R.load[l.id]||0)/capOf(l)})).sort((a,b)=>b.u-a.u).slice(0,8);
|
||||
const rs=Object.keys(S.pops).map(c=>({c,u:(R.nodeLoad[c]||0)/(R.nodeCap[c]||1)})).sort((a,b)=>b.u-a.u).slice(0,6);
|
||||
|
|
|
|||
44
src/game/94-dashboard/65-chart-legend.js
Normal file
44
src/game/94-dashboard/65-chart-legend.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* The NOC charts: legend entries switch a series on and off (the scale follows what is left), and hovering or
|
||||
touching a chart shows every visible series on that day. View state only: UI.chartOff is never saved. */
|
||||
const CHARTS={
|
||||
traffic:{stack:['c','p','ix','t','l2'],lines:['dem'],fmt:v=>fmtG(v),name:k=>k==='dem'?tr('common.demand'):EGC[k][0],col:k=>k==='dem'?'#1E2640':EGC[k][1]},
|
||||
mix:{stack:['c','p','ix','t'],lines:[],fmt:v=>fmtG(v),name:k=>EGC[k][0],col:k=>EGC[k][1]}, // the Traffic tab's table
|
||||
money:{stack:[],lines:['rev','cost'],fmt:v=>fmt$(v),name:k=>k==='rev'?tr('common.revenue'):tr('common.costs'),col:k=>k==='rev'?'#16A866':'#FF4D5E'}
|
||||
};
|
||||
const chartKeys=C=>[...C.stack,...C.lines];
|
||||
function chartLegend(id,label){const C=CHARTS[id],off=(UI.chartOff&&UI.chartOff[id])||{};
|
||||
return `<div class="legend">${chartKeys(C).map(k=>`<button class="lg${off[k]?' off':''}" aria-pressed="${!off[k]}" data-act="chartToggle" data-args="${esc(JSON.stringify({c:id,k}))}"><i style="background:${k==='dem'?'#fff;border-style:dashed':C.col(k)}"></i>${C.name(k)}${label?label(k):''}</button>`).join('')}</div>`;}
|
||||
Object.assign(ACT,{
|
||||
chartToggle:({c,k})=>{const C=CHARTS[c];if(!C||!chartKeys(C).includes(k))return;
|
||||
const off=((UI.chartOff=UI.chartOff||{})[c]=UI.chartOff[c]||{});if(off[k])delete off[k];else off[k]=1;
|
||||
if(chartKeys(C).every(x=>off[x]))UI.chartOff[c]={}; // nothing left to draw: show everything again
|
||||
renderDash();},
|
||||
});
|
||||
// The tooltip and its cursor line sit on <body>, outside the dashboard, so the per-tick redraw never removes them.
|
||||
// Pointer moves are frequent: the tip is only rebuilt (and measured) when what it shows changes, not on every pixel.
|
||||
let chartTip=null,chartCur=null,chartKey='',chartTw=0,chartTh=0;
|
||||
function chartHide(){if(chartTip&&!chartTip.hidden){chartTip.hidden=chartCur.hidden=true;chartKey='';}}
|
||||
function chartEnsure(){if(!chartTip){chartTip=document.createElement('div');chartTip.className='chtip';chartCur=document.createElement('div');chartCur.className='chcur';document.body.append(chartCur,chartTip);}}
|
||||
// Fill the tip when its content key changes; measure it once, so moving inside the same content reads no layout.
|
||||
function chartFill(key,html,showCur){if(key===chartKey&&!chartTip.hidden)return false;chartKey=key;chartTip.innerHTML=html;chartTip.hidden=false;chartCur.hidden=!showCur;chartTw=chartTip.offsetWidth;chartTh=chartTip.offsetHeight;return true;}
|
||||
// Keep the tip inside the window, beside x and above y (below it when there is no room).
|
||||
function chartPlace(x,cy){const tw=chartTw,th=chartTh;
|
||||
chartTip.style.left=Math.max(4,Math.min(innerWidth-tw-4,x+12>innerWidth-tw-4?x-tw-12:x+12))+'px';
|
||||
chartTip.style.top=Math.max(4,Math.min(innerHeight-th-4,cy-th-8<4?cy+14:cy-th-8))+'px';}
|
||||
function chartShow(svg,cx,cy){const id=svg.dataset.ch,C=CHARTS[id],H=S&&S.hist||[],n=Math.min(90,H.length),r=svg.getBoundingClientRect(),[bW,bH,bL,bT,bB,bR]=svg.dataset.box?svg.dataset.box.split(',').map(Number):[CHBOX.W,CHBOX.H,CHBOX.L,CHBOX.T,CHBOX.B,CHBOX.R];
|
||||
if(!C||n<2||!r.width)return chartHide();
|
||||
chartEnsure();
|
||||
const sx=r.width/bW,i=Math.max(0,Math.min(n-1,Math.round(((cx-r.left)/sx-bL)/(bW-bL-bR)*(n-1)))),row=H[H.length-n+i],off=(UI.chartOff&&UI.chartOff[id])||{};
|
||||
const x=r.left+(bL+(bW-bL-bR)*i/(n-1))*sx;
|
||||
const key=id+'|'+row.d+'|'+Object.keys(off).join();
|
||||
if(chartFill(key,chartHtml(C,row,off),true)||chartCur.dataset.x!==String(x)){chartCur.dataset.x=x;chartCur.style.cssText=`left:${x}px;top:${r.top+bT*sx}px;height:${(bH-bT-bB)*sx}px`;}
|
||||
chartPlace(x,cy);}
|
||||
function chartHtml(C,row,off){const ks=chartKeys(C).filter(k=>!off[k]),st=C.stack.filter(k=>!off[k]);
|
||||
return `<b>${dateStr(row.d)}</b>`+ks.map(k=>`<div><i style="background:${C.col(k)}"></i>${C.name(k)}<span>${C.fmt(row[k]||0)}</span></div>`).join('')+(st.length>1?`<div class="tot">${tr('dashboard.chart_total')}<span>${C.fmt(st.reduce((a,k)=>a+(row[k]||0),0))}</span></div>`:'');}
|
||||
// The "how it arrives" bars of the Traffic tab: the same tip, with each way in and its share.
|
||||
function mixShow(el,cx,cy){const raw=el.dataset.mix;chartEnsure();
|
||||
if(chartKey!=='mix|'+raw||chartTip.hidden){let m;try{m=JSON.parse(raw);}catch(e){return chartHide();}
|
||||
const ks=['c','p','ix','t'].filter(k=>m[k]>0),tot=ks.reduce((a,k)=>a+m[k],0);
|
||||
chartFill('mix|'+raw,ks.length?ks.map(k=>`<div><i style="background:${EGC[k][1]}"></i>${EGC[k][0]}<span>${fmtG(m[k])} · ${pct(m[k]/tot)}</span></div>`).join(''):tr('common.nothing_yet'),false);}
|
||||
chartPlace(cx,cy);}
|
||||
for(const t of ['pointermove','pointerdown'])document.addEventListener(t,e=>{const c=e.target.closest&&e.target.closest('svg[data-ch],.mix[data-mix]');if(!c)chartHide();else if(c.dataset.mix!==undefined)mixShow(c,e.clientX,e.clientY);else chartShow(c,e.clientX,e.clientY);});
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
per network, opened once a window says hello, so other games' tabs never unpack them. With no window nothing is sent. */
|
||||
const NOC_HB=3000,NOC_LOST=10000,NOC_GAP=1000;
|
||||
// What a click in the window does: changes only its own view, or runs in the game. Every button the dashboard draws is in one list.
|
||||
const NOC_LOCAL=['connCity','connF','connNet','connSort','custCity','custF','custSort','dashClose','dashSort','dashTab','listMore'];
|
||||
const NOC_LOCAL=['chartToggle','connCity','connF','connNet','connSort','custCity','custF','custSort','dashClose','dashSort','dashTab','listMore'];
|
||||
const NOC_GO=['buyIx','buyNni','buyTransit','cache','connCancel','custGo','dashLink','goConn','lagIx','lagP','lagT','leaseSwap','netFocus','opsOpen','pni','pniAllOpen'];
|
||||
const NOC={win:false,id:null,ctl:null,st:null,stId:null,peer:false,until:0,dirty:false,sent:0,speed:1,hid:false,yoAt:0,gone:false};
|
||||
{const id=RW_IN?null:new URLSearchParams(location.search).get('noc');if(slotOkId(id)){NOC.win=true;NOC.id=id;}}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ const nwG=v=>v>=1000?(+(v/1000).toFixed(1))+'T':(v>=10||v===0?Math.round(v):+v.t
|
|||
const nwMapBox=()=>{let y0=Infinity,y1=-Infinity;for(const p of COAST){const b=polyBox(p);if(ringArea(p)>=600){y0=Math.min(y0,b[1]);y1=Math.max(y1,b[3]);}}return [0,Math.floor(y0),W,Math.ceil(y1-y0)];};
|
||||
function nwLand(){let d='';for(const p of COAST){if(ringArea(p)<600&&!CITIES.some(c=>inPoly(c.x,c.y,p)))continue;d+='M'+p.map(q=>Math.round(q[0])+' '+Math.round(q[1])).join('L')+'Z';}return d;}
|
||||
// ---------- charts ----------
|
||||
function nwChart(rows,stack,lines,fmtY,CW=900,CH=260,L=62){if(rows.length<2)return `<p class="nw-empty">${tr('link_panels.collecting_data_check_back_in_a')}</p>`;
|
||||
function nwChart(rows,stack,lines,fmtY,CW=900,CH=260,L=62,id=''){if(rows.length<2)return `<p class="nw-empty">${tr('link_panels.collecting_data_check_back_in_a')}</p>`;
|
||||
const B=22,T=8,Rr=8;let ymax=1;for(const r of rows){let s=0;for(const k of stack)s+=r[k]||0;ymax=Math.max(ymax,s);for(const ln of lines)ymax=Math.max(ymax,r[ln.k]||0);}ymax*=1.1;
|
||||
const x=i=>+(L+(CW-L-Rr)*i/(rows.length-1)).toFixed(1),y=v=>+(T+(CH-T-B)*(1-v/ymax)).toFixed(1);let g='';
|
||||
for(let j=0;j<=4;j++){const v=ymax*j/4,yy=y(v);g+=`<line class="nw-grid" x1="${L}" x2="${CW-Rr}" y1="${yy}" y2="${yy}"/><text class="nw-ax" x="${L-6}" y="${yy+3}" text-anchor="end">${esc(fmtY(v))}</text>`;}
|
||||
|
|
@ -21,7 +21,7 @@ function nwChart(rows,stack,lines,fmtY,CW=900,CH=260,L=62){if(rows.length<2)retu
|
|||
g+=`<path d="${d}Z" fill="${EGC[k][1]}" fill-opacity=".55"/><path d="${e}" fill="none" stroke="${EGC[k][1]}" stroke-width="1.5"/>`;top.forEach((v,i)=>base[i]=v);}
|
||||
for(const ln of lines){let d='';rows.forEach((r,i)=>{d+=(i?'L':'M')+x(i)+','+y(r[ln.k]||0);});g+=`<path d="${d}" fill="none" stroke="${ln.col}" stroke-width="2" ${ln.dash?'stroke-dasharray="5 4"':''} stroke-linejoin="round"/><circle cx="${x(rows.length-1)}" cy="${y(rows[rows.length-1][ln.k]||0)}" r="3.5" fill="${ln.col}"/>`;}
|
||||
g+=`<text class="nw-ax" x="${L}" y="${CH-6}">${esc(dateStr(rows[0].d))}</text><text class="nw-ax" x="${CW-Rr}" y="${CH-6}" text-anchor="end">${esc(dateStr(rows[rows.length-1].d))}</text>`;
|
||||
return `<svg class="nw-chart" viewBox="0 0 ${CW} ${CH}" role="img">${g}</svg>`;}
|
||||
return `<svg class="nw-chart" viewBox="0 0 ${CW} ${CH}" role="img"${id?` data-ch="${id}" data-box="${CW},${CH},${L},${T},${B},${Rr}"`:''}>${g}</svg>`;}
|
||||
function nwSpark(vals,col){if(vals.length<2)return '';let a=Infinity,b=-Infinity;for(const v of vals){if(v<a)a=v;if(v>b)b=v;}const sp=b-a||1;
|
||||
const pts=vals.map((v,i)=>(100*i/(vals.length-1)).toFixed(1)+','+(26-22*(v-a)/sp).toFixed(1)).join(' ');
|
||||
return `<svg class="nw-spark" viewBox="0 0 100 28" preserveAspectRatio="none" aria-hidden="true"><polyline points="${pts}" fill="none" stroke="${col}" stroke-width="2" vector-effect="non-scaling-stroke"/></svg>`;}
|
||||
|
|
@ -80,11 +80,11 @@ function nocWall(){if(!NOCW.built)nwBuild();const rows=(S.hist||[]).slice(-90),A
|
|||
NOCW.sum={bad:A.filter(a=>a.k==='bad').length,warn:A.filter(a=>a.k==='warn').length};
|
||||
const put=(id,h)=>{const e=$(id);if(e._h!==h){e._h=h;morph(e,h);}};
|
||||
put('nwTiles',nwTiles());put('nwOver',nwMap());put('nwAlarms',nwAlarmsHtml(A));
|
||||
put('nwTraffic',`<div class="nw-h"><h3>${esc(tr('dashboard.traffic_by_way_out'))}</h3><div class="nw-legend">${Object.keys(EGC).filter(k=>(R.egT[k]||0)>0.01||rows.some(r=>(r[k]||0)>0)).map(k=>`<span><i style="background:${EGC[k][1]}"></i>${esc(EGC[k][0])} <b class="num">${esc(fmtG(R.egT[k]||0))}</b></span>`).join('')}<span><i class="dash"></i>${esc(tr('common.demand'))}</span></div></div>${nwChart(rows,['c','p','ix','t','l2'],[{k:'dem',col:'#E8EEFA',dash:true}],nwG)}`);
|
||||
put('nwTraffic',`<div class="nw-h"><h3>${esc(tr('dashboard.traffic_by_way_out'))}</h3><div class="nw-legend">${Object.keys(EGC).filter(k=>(R.egT[k]||0)>0.01||rows.some(r=>(r[k]||0)>0)).map(k=>`<span><i style="background:${EGC[k][1]}"></i>${esc(EGC[k][0])} <b class="num">${esc(fmtG(R.egT[k]||0))}</b></span>`).join('')}<span><i class="dash"></i>${esc(tr('common.demand'))}</span></div></div>${nwChart(rows,['c','p','ix','t','l2'],[{k:'dem',col:'#E8EEFA',dash:true}],nwG,900,260,62,'traffic')}`);
|
||||
put('nwPorts',nwPorts());
|
||||
put('nwRouters',nwBars(tr('common.router_load'),Object.keys(S.pops).map(c=>[CITY[c].name,`${S.pops[c].routers||1} × ${RG[S.pops[c].rgen||0].n}`,(R.nodeLoad[c]||0)/(R.nodeCap[c]||1)]).sort((a,b)=>b[2]-a[2]).slice(0,6)));
|
||||
put('nwLinks',nwBars(tr('common.busiest_links'),S.links.filter(l=>capOf(l)>0).map(l=>[`${CITY[l.a].name} ⇄ ${CITY[l.b].name}`,capName(l),(R.load[l.id]||0)/capOf(l)]).sort((a,b)=>b[2]-a[2]).slice(0,6)));
|
||||
put('nwMoney',`<div class="nw-h"><h3>${esc(tr('dashboard.money_per_month'))}</h3><div class="nw-legend"><span><i style="background:${NW_COL.ok}"></i>${esc(tr('common.revenue'))}</span><span><i style="background:${NW_COL.bad}"></i>${esc(tr('common.costs'))}</span></div></div>${nwChart(rows,[],[{k:'rev',col:NW_COL.ok},{k:'cost',col:NW_COL.bad}],fmt$,520,220,74)}`);}
|
||||
put('nwMoney',`<div class="nw-h"><h3>${esc(tr('dashboard.money_per_month'))}</h3><div class="nw-legend"><span><i style="background:${NW_COL.ok}"></i>${esc(tr('common.revenue'))}</span><span><i style="background:${NW_COL.bad}"></i>${esc(tr('common.costs'))}</span></div></div>${nwChart(rows,[],[{k:'rev',col:NW_COL.ok},{k:'cost',col:NW_COL.bad}],fmt$,520,220,74,'money')}`);}
|
||||
// The window's own controls never reach the game: they change what this screen shows.
|
||||
function nocUiClick(e){const b=e.target.closest&&e.target.closest('[data-nc]');if(!b)return;const v=b.getAttribute('data-nc');
|
||||
if(v==='wall'||v==='details')nocView(v);
|
||||
|
|
|
|||
|
|
@ -1756,6 +1756,7 @@
|
|||
"dashboard.all_n":"All ({n})",
|
||||
"dashboard.amp_huts_and_spares":"Amp huts and spares",
|
||||
"dashboard.caches_pnis_and_ix":"caches, PNIs and IX",
|
||||
"dashboard.chart_total":"Total",
|
||||
"dashboard.customers_are_upset":"customers are upset",
|
||||
"dashboard.delivered_30_days":"Delivered, 30 days",
|
||||
"dashboard.five_nines_ish":"five nines-ish",
|
||||
|
|
|
|||
15
src/styles/42-chart-tooltips.css
Normal file
15
src/styles/42-chart-tooltips.css
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
.legend .lg{font:inherit;color:inherit;background:none;border:0;padding:2px 4px;margin:-2px -4px;border-radius:6px;cursor:pointer}
|
||||
.legend .lg:hover{background:rgba(30,38,64,.08)}
|
||||
.legend .lg.off{opacity:.45;text-decoration:line-through}
|
||||
.chart[data-ch]{touch-action:pan-y;cursor:crosshair}
|
||||
.chtip{position:fixed;z-index:60;pointer-events:none;background:var(--ink);color:#fff;border-radius:8px;padding:6px 9px;font-size:11.5px;font-weight:700;box-shadow:0 4px 14px rgba(0,0,0,.3);min-width:130px}
|
||||
.chtip[hidden],.chcur[hidden]{display:none}
|
||||
.chtip div{display:flex;align-items:center;gap:6px;margin-top:2px}
|
||||
.chtip div span{margin-left:auto;padding-left:10px;font-variant-numeric:tabular-nums}
|
||||
.chtip i{width:9px;height:9px;border-radius:3px;border:1px solid #fff}
|
||||
.chtip .tot{border-top:1px solid rgba(255,255,255,.35);margin-top:4px;padding-top:3px}
|
||||
.chcur{position:fixed;z-index:59;pointer-events:none;width:0;border-left:1px dashed var(--ink)}
|
||||
.mix[data-mix]{cursor:help}
|
||||
.nw-chart[data-ch]{touch-action:pan-y;cursor:crosshair}
|
||||
.noc-window .chtip{border:1px solid #3A4A78}
|
||||
.noc-window .chcur{border-left-color:#E8EEFA}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/* The NOC window (?noc=<slot>): a dark wallboard for a second display, and the dashboard's own tabs under Details. */
|
||||
body.noc-window{background:#0B1224;overflow:auto}
|
||||
#nocBoard{color:#E8EEFA}
|
||||
body.noc-window>*:not(#nocBoard):not(#dash):not(#toasts):not(script){display:none !important}
|
||||
body.noc-window>*:not(#nocBoard):not(#dash):not(#toasts):not(.chtip):not(.chcur):not(script){display:none !important}
|
||||
body.noc-window #dash{position:static;background:none;overflow:visible;padding:0 12px 16px}
|
||||
body.noc-window #toasts{z-index:20}
|
||||
body.noc-window [data-act="dashClose"]{display:none}
|
||||
|
|
|
|||
95
tests/chart-legend.test.js
Normal file
95
tests/chart-legend.test.js
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const start = "ACT.start({});S.nextFail=1e9;S.nextEvent=1e9;S.hist=[];for(let d=1;d<=40;d++)S.hist.push({d,dem:100+d,srv:90+d,c:10,p:20,ix:30,t:40+d,l2:5,rev:1000+d*10,cost:900+d*5})";
|
||||
const dash = ev => ev("(renderDash(),$('dash').innerHTML)");
|
||||
|
||||
test('NOC legend entries hide and show a series, and the scale follows the rest', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start); ev("$('dash').hidden=false");
|
||||
let h = dash(ev);
|
||||
assert.match(h, /data-ch="traffic"/);
|
||||
assert.match(h, /data-ch="money"/);
|
||||
assert.equal((h.match(/class="lg"/g) || []).length, 8, 'six traffic entries and two money ones, all on');
|
||||
const stacked = html => (html.match(/fill-opacity="\.85"/g) || []).length;
|
||||
assert.equal(stacked(h), 5);
|
||||
ev("ACT.chartToggle({c:'traffic',k:'t'})");
|
||||
h = ev("$('dash').innerHTML");
|
||||
assert.equal(stacked(h), 4, 'transit is gone from the stack');
|
||||
assert.match(h, /class="lg off" aria-pressed="false"[^>]*data-args="[^"]*"k":"t"/);
|
||||
ev("ACT.chartToggle({c:'traffic',k:'ix'})");
|
||||
assert.equal(stacked(ev("$('dash').innerHTML")), 3, 'several at once');
|
||||
ev("ACT.chartToggle({c:'traffic',k:'t'})");
|
||||
assert.equal(stacked(ev("$('dash').innerHTML")), 4, 'a second click brings it back');
|
||||
// Hiding the last visible series shows everything again instead of an empty chart.
|
||||
ev("UI.chartOff={}");
|
||||
for (const k of ['c', 'p', 'ix', 'l2', 'dem']) ev(`ACT.chartToggle({c:'traffic',k:'${k}'})`);
|
||||
assert.equal(stacked(ev("$('dash').innerHTML")), 1, 'only transit left');
|
||||
ev("ACT.chartToggle({c:'traffic',k:'t'})");
|
||||
assert.equal(stacked(ev("$('dash').innerHTML")), 5);
|
||||
// Nonsense is ignored, and the other chart is untouched.
|
||||
ev("ACT.chartToggle({c:'nope',k:'t'});ACT.chartToggle({c:'money',k:'zzz'})");
|
||||
assert.equal(ev("JSON.stringify(UI.chartOff.money||{})"), '{}');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('hovering a NOC chart shows the day and every visible series; leaving hides it', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
const doc = dom.window.document;
|
||||
ev(start); ev("$('dash').hidden=false;renderDash()");
|
||||
const svg = doc.querySelector('svg.chart[data-ch="traffic"]');
|
||||
svg.getBoundingClientRect = () => ({ left: 0, top: 0, width: 600, height: 180, right: 600, bottom: 180 });
|
||||
const move = (t, x) => t.dispatchEvent(new dom.window.MouseEvent('pointermove', { clientX: x, clientY: 60, bubbles: true }));
|
||||
move(svg, 50 + 542); // the right edge of the plot: the newest day
|
||||
const tip = doc.querySelector('.chtip');
|
||||
assert.ok(tip && !tip.hidden, 'tooltip appears');
|
||||
assert.match(tip.textContent, /Y1 · /);
|
||||
assert.match(tip.textContent, /Transit/);
|
||||
assert.match(tip.textContent, /Demand/);
|
||||
assert.match(tip.textContent, /Total/);
|
||||
assert.equal(tip.textContent.includes('80.0 Gbps'), true, 'newest transit 40+40 Gbps');
|
||||
ev("ACT.chartToggle({c:'traffic',k:'t'})");
|
||||
move(doc.querySelector('svg.chart[data-ch="traffic"]'), 50);
|
||||
assert.doesNotMatch(tip.textContent, /Transit/, 'hidden series are left out');
|
||||
assert.match(tip.textContent, /Gbps/);
|
||||
move(doc.body, 10);
|
||||
assert.equal(tip.hidden, true, 'moving away hides it');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the "how it arrives" bars on the Traffic tab show the same tip with each way in and its share', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
const doc = dom.window.document;
|
||||
ev("ACT.start({});S.cash=1e8;S.nextFail=1e9;S.nextEvent=1e9;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'});ACT.buyTransit({city:'fra',net:'cog',tier:1});compute();UI.dtab='traffic';$('dash').hidden=false;renderDash()");
|
||||
const bars = [...doc.querySelectorAll('.mix[data-mix]')].filter(b => Object.keys(JSON.parse(b.dataset.mix)).length);
|
||||
assert.ok(bars.length, 'a network with traffic has a bar');
|
||||
assert.equal(bars[0].hasAttribute('title'), false, 'no plain browser tooltip next to ours');
|
||||
assert.match(bars[0].getAttribute('aria-label'), /Gbps/);
|
||||
bars[0].dispatchEvent(new dom.window.MouseEvent('pointermove', { clientX: 100, clientY: 100, bubbles: true }));
|
||||
const tip = doc.querySelector('.chtip');
|
||||
assert.ok(tip && !tip.hidden);
|
||||
assert.match(tip.textContent, /Transit.*Gbps · \d+%/);
|
||||
assert.equal(doc.querySelector('.chcur').hidden, true, 'no cursor line for a bar');
|
||||
doc.body.dispatchEvent(new dom.window.MouseEvent('pointermove', { clientX: 5, clientY: 5, bubbles: true }));
|
||||
assert.equal(tip.hidden, true);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the Traffic tab legend picks which ways in count, and the table follows', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
const doc = dom.window.document;
|
||||
ev("ACT.start({});S.cash=1e8;S.nextFail=1e9;S.nextEvent=1e9;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'});ACT.buyTransit({city:'fra',net:'cog',tier:1});ACT.buyIx({city:'fra',tier:1,signed:true});ACT.rs({city:'fra'});compute();UI.dtab='traffic';$('dash').hidden=false;renderDash()");
|
||||
const rows = () => doc.querySelectorAll('.tbl tbody tr').length;
|
||||
const kinds = () => new Set([...doc.querySelectorAll('.tbl .mix[data-mix]')].flatMap(b => Object.keys(JSON.parse(b.dataset.mix))));
|
||||
const all = rows();
|
||||
assert.ok(kinds().has('t'), 'transit carries something');
|
||||
assert.equal(doc.querySelectorAll('.legend .lg').length, 4, 'one entry per way in');
|
||||
ev("ACT.chartToggle({c:'mix',k:'t'})");
|
||||
assert.equal(kinds().has('t'), false, 'transit is out of every bar');
|
||||
assert.ok(rows() < all, 'networks that only came in over transit are gone');
|
||||
assert.equal(doc.querySelectorAll('.legend .lg.off').length, 1);
|
||||
ev("ACT.chartToggle({c:'mix',k:'t'})");
|
||||
assert.equal(rows(), all, 'switching it back restores the table');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
@ -313,3 +313,34 @@ test('the board\'s light text stays on the board: Details is the game\'s own das
|
|||
assert.doesNotMatch(body, /(^|;)\s*color:/, 'a colour on body would be inherited by the white dashboard card and its toasts');
|
||||
assert.match(css, /#nocBoard\{color:/);
|
||||
});
|
||||
|
||||
test('the wallboard charts have the same tooltip, and the Details legend works in the window', async (t) => {
|
||||
const { G, W } = await pair(t);
|
||||
G.ev("S.hist=[];for(let d=1;d<=40;d++)S.hist.push({d,dem:100+d,srv:90+d,c:10,p:20,ix:30,t:40+d,l2:5,rev:1000+d*10,cost:900+d*5})");
|
||||
G.ev('NOC.dirty=true');pump(G);
|
||||
await settle(W.ev, '(S.hist||[]).length===40', 'the window got the history');
|
||||
W.ev('nocRender()');
|
||||
const doc = W.dom.window.document;
|
||||
const svg = doc.querySelector('svg.nw-chart[data-ch="traffic"]');
|
||||
assert.ok(svg, 'the wallboard traffic chart is tagged');
|
||||
assert.ok(doc.querySelector('svg.nw-chart[data-ch="money"]'), 'and so is the money chart');
|
||||
svg.getBoundingClientRect = () => ({ left: 0, top: 0, width: 900, height: 260, right: 900, bottom: 260 });
|
||||
svg.dispatchEvent(new W.dom.window.MouseEvent('pointermove', { clientX: 900 - 8, clientY: 100, bubbles: true })); // the newest day
|
||||
const tip = doc.querySelector('.chtip');
|
||||
assert.ok(tip && !tip.hidden, 'the tooltip appears in the window');
|
||||
assert.match(tip.textContent, /Transit/);
|
||||
assert.equal(tip.textContent.includes('80.0 Gbps'), true, 'newest transit 40+40 Gbps');
|
||||
W.ev("nocView('details')");
|
||||
W.ev("UI.dtab='traffic';renderDash()");
|
||||
W.ev("ACT.chartToggle({c:'traffic',k:'t'})");
|
||||
assert.equal(W.ev("!!(UI.chartOff&&UI.chartOff.traffic&&UI.chartOff.traffic.t)"), true, "the legend changes the window's own view");
|
||||
assert.equal(G.ev("!!(UI.chartOff&&UI.chartOff.traffic)"), false, 'and does not travel to the game');
|
||||
});
|
||||
|
||||
test('the stylesheet of the window leaves the chart tooltip and its cursor line alone', () => {
|
||||
const css = require('node:fs').readFileSync(require('node:path').join(__dirname, '..', 'src', 'styles', '45-noc-window.css'), 'utf8');
|
||||
const hide = css.split('\n').find((l) => l.startsWith('body.noc-window>*:not(#nocBoard)'));
|
||||
assert.ok(hide, 'the rule that hides the game page is there');
|
||||
assert.ok(hide.includes(':not(.chtip)'), 'the tooltip stays');
|
||||
assert.ok(hide.includes(':not(.chcur)'), 'and so does its cursor line');
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue