feat(noc): tooltips and clickable legends on the dashboard charts
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5b24282224
commit
bac645ed5b
18 changed files with 214 additions and 18 deletions
|
|
@ -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}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue