|
1 | 1 | <!DOCTYPE html> |
2 | 2 | <html> |
3 | | -<head><title>Web VPython Users</title></head> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <title>Web VPython Users</title> |
| 6 | + <style> |
| 7 | + body { font-family: sans-serif; margin: 20px; } |
| 8 | + #chart { width: 100%; height: 600px; } |
| 9 | + .no-data { color: #888; font-style: italic; margin-top: 40px; } |
| 10 | + </style> |
| 11 | +</head> |
4 | 12 | <body> |
5 | | -<script src="/package/plotlyVP7.min.js"></script> |
6 | | -{% if no_data %} |
7 | | -<p>No data yet — run the migration script first.</p> |
8 | | -{% else %} |
9 | | -<div id="chart"></div> |
10 | | -<script> |
11 | | -const points = {{ points | tojson }}; |
12 | | -const updated = {{ updated | tojson }}; |
13 | | -</script> |
14 | | -{% endif %} |
| 13 | + <script src="/package/plotlyVP7.min.js"></script> |
| 14 | + |
| 15 | + {% if no_data %} |
| 16 | + <p class="no-data">No data yet — run <code>buildUserHistory.py</code> first.</p> |
| 17 | + {% else %} |
| 18 | + <div id="chart"></div> |
| 19 | + <script> |
| 20 | + const points = {{ points | tojson }}; |
| 21 | + const updated = {{ updated | tojson }}; |
| 22 | + |
| 23 | + // Convert 'YYYY-MM' to decimal year, e.g. '2026-05' → 2026.333 |
| 24 | + function toDecimalYear(monthStr) { |
| 25 | + const [year, month] = monthStr.split('-').map(Number); |
| 26 | + return year + (month - 1) / 12; |
| 27 | + } |
| 28 | + |
| 29 | + const xs = points.map(p => toDecimalYear(p.month)); |
| 30 | + const ys = points.map(p => p.count); |
| 31 | + |
| 32 | + const lastPoint = points[points.length - 1]; |
| 33 | + const formattedDate = updated ? updated.replace(/-/g, '/') : ''; |
| 34 | + const formattedCount = lastPoint.count.toLocaleString(); |
| 35 | + const title = `As of ${formattedDate} there were ${formattedCount} Web VPython accounts.`; |
| 36 | + |
| 37 | + Plotly.newPlot('chart', [{ |
| 38 | + x: xs, |
| 39 | + y: ys, |
| 40 | + mode: 'lines+markers', |
| 41 | + type: 'scatter', |
| 42 | + marker: { color: 'red', size: 4 }, |
| 43 | + line: { color: 'red', width: 1 } |
| 44 | + }], { |
| 45 | + title: title, |
| 46 | + xaxis: { title: 'Year' }, |
| 47 | + yaxis: { title: 'Web VPython accounts' }, |
| 48 | + margin: { t: 60 } |
| 49 | + }); |
| 50 | + </script> |
| 51 | + {% endif %} |
15 | 52 | </body> |
16 | 53 | </html> |
0 commit comments