|
71 | 71 | applyTheme(resolveTheme()); |
72 | 72 |
|
73 | 73 | // Only the fastest and slowest few benchmarks fit; the rest collapse into a gap |
74 | | - var narrow = window.matchMedia('(max-width: 760px)'); |
| 74 | + // A phone counts as narrow even when the embedding page has no viewport |
| 75 | + // meta and lays itself (and so this frame) out at desktop width |
| 76 | + function isNarrow() { return Math.min(window.innerWidth, screen.width) <= 760; } |
| 77 | + var wasNarrow = isNarrow(); |
| 78 | + // Such a page is shrunk to fit the phone, so grow the text to match |
| 79 | + function fontScale() { |
| 80 | + return isNarrow() ? Math.min(2.5, Math.max(1, window.innerWidth / screen.width)) : 1; |
| 81 | + } |
75 | 82 | var plotData = null; |
76 | 83 |
|
77 | 84 | function renderplot(data) { |
|
114 | 121 |
|
115 | 122 | function drawChart() { |
116 | 123 | var rows = plotData.rows; |
117 | | - var keep = narrow.matches ? 10 : 20; |
| 124 | + var keep = isNarrow() ? 10 : 20; |
118 | 125 | var shown = rows; |
119 | 126 | if (rows.length > 2 * keep) { |
120 | 127 | shown = rows.slice(0, keep).concat([null], rows.slice(rows.length - keep)); |
|
123 | 130 | // Floating bars from the baseline at 1.0, so faster runs hang below it |
124 | 131 | var bars = shown.map(function(r) { return r ? [1, r.rel] : null; }); |
125 | 132 | var gap = shown.indexOf(null); |
| 133 | + var scale = fontScale(); |
| 134 | + Chart.defaults.font.size = Math.round(12 * scale); |
126 | 135 | // Mark the gap on the plot itself, not just on the axis |
127 | 136 | var gapMarker = { |
128 | 137 | id: 'gapMarker', |
129 | 138 | afterDatasetsDraw: function(chart) { |
130 | 139 | if (gap === -1) { return; } |
131 | 140 | var ctx = chart.ctx; |
132 | 141 | ctx.save(); |
133 | | - ctx.font = 'bold 32px sans-serif'; |
| 142 | + ctx.font = 'bold ' + Math.round(32 * scale) + 'px sans-serif'; |
134 | 143 | ctx.fillStyle = Chart.defaults.color; |
135 | 144 | ctx.textAlign = 'center'; |
136 | 145 | ctx.textBaseline = 'bottom'; |
|
185 | 194 | scales: { |
186 | 195 | x: {ticks: {maxRotation: 70, minRotation: 70, autoSkip: false, |
187 | 196 | font: function(c) { |
188 | | - return c.index === gap ? {size: 20, weight: 'bold'} : {size: 11}; |
| 197 | + return c.index === gap ? {size: Math.round(20 * scale), weight: 'bold'} |
| 198 | + : {size: Math.round(11 * scale)}; |
189 | 199 | }}}, |
190 | 200 | y: {type: 'logarithmic', |
191 | 201 | min: 0.005, max: 5, |
|
200 | 210 | } |
201 | 211 | }); |
202 | 212 | } |
203 | | - narrow.addEventListener('change', function() { if (plotData) { drawChart(); } }); |
| 213 | + window.addEventListener('resize', function() { |
| 214 | + if (plotData && isNarrow() !== wasNarrow) { wasNarrow = isNarrow(); drawChart(); } |
| 215 | + }); |
204 | 216 |
|
205 | 217 | $(function() { |
206 | 218 | $.getJSON("{% url 'gethistoricaldata' %}", {source: '{{ source }}'}, renderplot); |
|
0 commit comments