Skip to content

Commit 21bf94e

Browse files
committed
adapt to mobile
1 parent dd3b1ba commit 21bf94e

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

‎speed_pypy/templates/embed_comparison.html‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@
7171
applyTheme(resolveTheme());
7272

7373
// 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+
}
7582
var plotData = null;
7683

7784
function renderplot(data) {
@@ -114,7 +121,7 @@
114121

115122
function drawChart() {
116123
var rows = plotData.rows;
117-
var keep = narrow.matches ? 10 : 20;
124+
var keep = isNarrow() ? 10 : 20;
118125
var shown = rows;
119126
if (rows.length > 2 * keep) {
120127
shown = rows.slice(0, keep).concat([null], rows.slice(rows.length - keep));
@@ -123,14 +130,16 @@
123130
// Floating bars from the baseline at 1.0, so faster runs hang below it
124131
var bars = shown.map(function(r) { return r ? [1, r.rel] : null; });
125132
var gap = shown.indexOf(null);
133+
var scale = fontScale();
134+
Chart.defaults.font.size = Math.round(12 * scale);
126135
// Mark the gap on the plot itself, not just on the axis
127136
var gapMarker = {
128137
id: 'gapMarker',
129138
afterDatasetsDraw: function(chart) {
130139
if (gap === -1) { return; }
131140
var ctx = chart.ctx;
132141
ctx.save();
133-
ctx.font = 'bold 32px sans-serif';
142+
ctx.font = 'bold ' + Math.round(32 * scale) + 'px sans-serif';
134143
ctx.fillStyle = Chart.defaults.color;
135144
ctx.textAlign = 'center';
136145
ctx.textBaseline = 'bottom';
@@ -185,7 +194,8 @@
185194
scales: {
186195
x: {ticks: {maxRotation: 70, minRotation: 70, autoSkip: false,
187196
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)};
189199
}}},
190200
y: {type: 'logarithmic',
191201
min: 0.005, max: 5,
@@ -200,7 +210,9 @@
200210
}
201211
});
202212
}
203-
narrow.addEventListener('change', function() { if (plotData) { drawChart(); } });
213+
window.addEventListener('resize', function() {
214+
if (plotData && isNarrow() !== wasNarrow) { wasNarrow = isNarrow(); drawChart(); }
215+
});
204216

205217
$(function() {
206218
$.getJSON("{% url 'gethistoricaldata' %}", {source: '{{ source }}'}, renderplot);

‎speed_pypy/templates/home.html‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ <h4>{{ label }} benchmarks</h4>
139139
});
140140
});
141141

142+
// Phones lay this page out at desktop width and shrink it, so the comparison
143+
// frames grow their text; give the taller rotated labels room
144+
if (Math.min(window.innerWidth, screen.width) <= 760) {
145+
$('#historical iframe').css('height', '650px');
146+
}
147+
142148
function renderplot(source, data) {
143149
var $plot = $("#historical-plot-" + source);
144150
if (data === null || data.length === 0) {

0 commit comments

Comments
 (0)