File size: 4,406 Bytes
a5edae5
 
3fa2f6d
 
 
 
a5edae5
dbf818a
a5edae5
 
 
 
 
19d4224
a5edae5
 
 
19d4224
5c9ff26
 
 
 
 
 
a5edae5
 
5204149
a5edae5
 
 
 
 
 
5c9ff26
a5edae5
 
8a83db9
a5edae5
 
5c9ff26
a5edae5
5c9ff26
 
 
776762a
5204149
 
 
 
 
a5edae5
 
19d4224
3fa2f6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a5edae5
 
19d4224
a5edae5
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
async function drawProgress() {
  const status = document.getElementById("progress-status");
  const chart = document.getElementById("progress-chart");
  const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)");
  const animateOnScroll = !reducedMotion.matches && "IntersectionObserver" in window;
  if (animateOnScroll) chart.classList.add("awaiting-reveal");
  try {
    const response = await fetch("api/progress", {cache: "no-store"});
    if (!response.ok) throw new Error("Progress data unavailable");
    const data = await response.json();
    const points = data.points;
    const extent = [points[0].revision, points[points.length - 1].revision];
    const traces = [{
      type: "scatter", mode: "lines", name: "PyBot",
      x: points.map(p => p.revision), y: points.map(p => p.score),
      customdata: points.map(p => p.commit),
      line: {color: "#eb6834", width: 2},
      hovertemplate: "PyBot · revision %{x:,}<br>Win rate: %{y:.2f}%<br>Commit %{customdata}<extra></extra>"
    }, {
      type: "scatter", mode: "lines", name: "Lines of code", yaxis: "y2",
      x: points.map(p => p.revision), y: points.map(p => p.lines_of_code),
      customdata: points.map(p => p.commit),
      line: {color: "#287a9b", width: 2},
      hovertemplate: "Revision %{x:,}<br>Lines of code: %{y:,}<br>Python source in bot/ (including blanks and comments)<br>Commit %{customdata}<extra></extra>"
    }, ...data.baselines.map((baseline, index) => ({
      type: "scatter", mode: "lines",
      name: baseline.name,
      x: extent, y: [baseline.score, baseline.score],
      line: {color: ["#999999", "#555555", "#000000"][index], width: 1.5,
             dash: ["dot", "dash", "dashdot"][index]},
      hovertemplate: `${baseline.name}<br>Win rate: %{y:.2f}%<extra></extra>`
    }))];
    await Plotly.newPlot("progress-chart", traces, {
      margin: {l: 60, r: 72, t: 30, b: 60},
      paper_bgcolor: "#ffffff", plot_bgcolor: "#ffffff",
      font: {family: "'Letter Gothic', monospace", size: 12, color: "#000000"},
      xaxis: {title: {text: "PyBot commit", standoff: 12},
              range: extent, gridcolor: "#eeeeee", zeroline: false, automargin: true},
      yaxis: {title: {text: "Win rate (%)", standoff: 10}, rangemode: "tozero",
              color: "#eb6834",
              gridcolor: "#eeeeee", zerolinecolor: "#dddddd", automargin: true},
      yaxis2: {title: {text: "Lines of code", standoff: 10}, overlaying: "y", side: "right",
               rangemode: "tozero", color: "#287a9b", tickformat: "~s",
               showgrid: false, zeroline: false, automargin: true},
      showlegend: false,
      annotations: data.baselines.map(baseline => ({
        text: baseline.name, x: 1, xref: "paper", y: baseline.score, yref: "y",
        xanchor: "right", yanchor: "bottom", yshift: 4, showarrow: false,
        font: {size: 11, color: "#000000"}, bgcolor: "#ffffff", borderpad: 2
      })),
      hoverlabel: {bgcolor: "#ffffff", bordercolor: "#000000"}
    }, {responsive: true, displayModeBar: false, displaylogo: false});
    status.hidden = true;
    if (animateOnScroll) {
      const observer = new IntersectionObserver(entries => {
        if (!entries.some(entry => entry.isIntersecting && entry.intersectionRatio >= 0.3)) return;
        observer.disconnect();
        // Reveal the rendered SVG traces, keeping both axes and all data fixed.
        // This avoids redrawing thousands of points on every animation frame.
        chart.classList.remove("awaiting-reveal");
        if (reducedMotion.matches) return;
        const animations = [...chart.querySelectorAll(".scatterlayer .trace")].map(trace =>
          trace.animate([
            {clipPath: "inset(-10px 100% -10px 0)"},
            {clipPath: "inset(-10px 0% -10px 0)"}
          ], {duration: 1800, easing: "cubic-bezier(0.22, 1, 0.36, 1)"}));
        const finish = () => animations.forEach(animation => animation.finish());
        reducedMotion.addEventListener("change", finish, {once: true});
        Promise.all(animations.map(animation => animation.finished)).finally(() =>
          reducedMotion.removeEventListener("change", finish));
      }, {threshold: 0.3});
      observer.observe(chart);
    }
  } catch (error) {
    document.getElementById("progress-chart").hidden = true;
    status.textContent = "The progress chart is currently unavailable.";
  }
}
drawProgress();