const translate=(t,a)=>`translate(${t}, ${a})`,yLabels=["5 μs","10 μs","25 μs","50 μs","75 μs","100 μs","250 μs","500 μs","750 μs","1.0 ms","2.5 ms","5.0 ms","7.5 ms","10 ms","+Inf"],drawHeatmap=(t,a,e={})=>{void 0===e.margin&&(e.margin={});const r={top:e.margin.top||5,right:e.margin.right||45,bottom:e.margin.bottom||20,left:e.margin.left||25},n=e.height||340,s=e.colorScheme||d3.interpolateInferno,i=(e.timeTickInterval,Math.min(15,Math.ceil(a.length/20))),o=[],d=[],l=[],c=[];for(let t=0;t<a.length;t++){const e=a[t];d.push(e.avgTime),l.push({x:t,c:e.clients});const r=new Date(e.ts);if(t%i==0){const a=String(r.getHours()).padStart(2,"0"),e=String(r.getMinutes()).padStart(2,"0");o.push({x:t,t:`${a}:${e}`})}for(let a=0;a<15;a++){const r="number"==typeof e.buckets[a]?e.buckets[a]:0;c.push({x:t,y:a,freq:r})}}const m=t.offsetWidth,p=d3.scaleSequential(s).domain([0,1]),g=d3.create("svg").attr("viewBox",[0,0,m,n]),h=d3.scaleBand().domain(d3.range(a.length)).range([r.left,m-r.right]),f=d3.axisBottom(h).tickValues(o.map((t=>t.x))).tickFormat(((t,a)=>o[a].t));g.append("g").attr("transform",translate(0,n-r.bottom)).attr("id","x-axis").attr("class","axis").call(f);const x=d3.scaleBand().domain(d3.range(yLabels.length)).range([n-r.bottom,r.top]),u=d3.axisRight(x).tickFormat(((t,a)=>""+yLabels[a]));g.append("g").attr("transform",translate(m-r.right-3,0)).attr("id","y-axis").attr("class","axis").call(u),g.selectAll("rect").data(c).enter().append("rect").filter((t=>"number"==typeof t.freq)).attr("x",((t,a)=>h(t.x))).attr("y",((t,a)=>x(t.y))).attr("width",h.bandwidth()).attr("height",x.bandwidth()).attr("fill",(t=>p(t.freq))).attr("stroke",(t=>p(t.freq)));const b=Math.round(x.bandwidth()/2),k=d3.scaleLinear().domain([0,d3.max(l.map((t=>t.c)))]).range([n-r.bottom-b,r.top+b]);g.append("g").attr("transform",translate(r.left-1.5,0)).attr("id","y2-axis").attr("class","axis").call(d3.axisLeft(k));const y=d3.line().defined((t=>!isNaN(t.c))).x((t=>h(t.x)+2)).y((t=>k(t.c)));g.append("path").datum(l).attr("fill","none").attr("stroke","black").attr("stroke-width",6).attr("stroke-linejoin","round").attr("stroke-linecap","round").attr("d",y),g.append("path").datum(l).attr("fill","none").attr("stroke"," rgb(204, 203, 203)").attr("stroke-width",2).attr("stroke-linejoin","round").attr("stroke-linecap","round").attr("d",y),t.innerHTML="",t.append(g.node())};export{drawHeatmap};