function bayHandoffSparkline(samples){var valid=samples.filter(function(sample){return sample.valid;});if(!valid.length)return '<div class="bay-control-empty">Awaiting handoff history.</div>';var width=430,height=46,left=27,right=3,top=3,bottom=3;var first=Date.parse(samples[0].at),last=Date.parse(samples[samples.length-1].at),span=Math.max(1,last-first);var values=valid.flatMap(function(sample){return [sample.pending,sample.dispatching,sample.leased].filter(function(value){return Number.isFinite(value);});});var maximum=bayNiceMaximum(Math.max.apply(null,values));var plotWidth=width-left-right,plotHeight=height-top-bottom;var pathFor=function(field){var previous=null;return samples.map(function(sample){var value=sample.valid?sample[field]:null;if(!Number.isFinite(value)){previous=null;return "";}var at=Date.parse(sample.at);var point={x:left+(at-first)/span*plotWidth,y:height-bottom-(value/maximum)*plotHeight};var connected=previous!==null&&at-previous<=12*60000;previous=at;return (connected?"L":"M")+point.x.toFixed(1)+" "+point.y.toFixed(1);}).filter(Boolean).join(" ");};return '<div class="bay-handoff-chart"><svg viewBox="0 0 '+width+' '+height+'" role="img" aria-label="Pending, dispatching, and leased queue handoffs over '+esc(bayRangeLabel())+'"><line class="bay-control-grid" x1="'+left+'" x2="'+(width-right)+'" y1="'+top+'" y2="'+top+'"></line><line class="bay-control-grid" x1="'+left+'" x2="'+(width-right)+'" y1="'+(height-bottom)+'" y2="'+(height-bottom)+'"></line><text class="bay-control-axis-label" x="'+(left-3)+'" y="'+(top+3)+'" text-anchor="end">'+maximum+'</text><text class="bay-control-axis-label" x="'+(left-3)+'" y="'+(height-bottom+1)+'" text-anchor="end">0</text><path class="bay-handoff-line pending" d="'+pathFor("pending")+'"></path><path class="bay-handoff-line dispatching" d="'+pathFor("dispatching")+'"></path><path class="bay-handoff-line leased" d="'+pathFor("leased")+'"></path></svg><div class="bay-handoff-legend"><span><i></i>pending</span><span class="dispatching"><i></i>dispatching</span><span class="leased"><i></i>leased</span></div></div>';}
0 commit comments