Skip to content

Commit c5966b7

Browse files
authored
Merge pull request #1717 from Kobzol/benchmark-detail-graph
Improve benchmark detail graph on mobile
2 parents 36c3684 + c151f05 commit c5966b7

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

site/frontend/src/graph/render.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,11 @@ function normalizeData(data: GraphData) {
395395
}
396396

397397
export type GraphRenderOpts = {
398+
// Width of the graph
399+
width: number;
400+
// Render a title above the graph
398401
renderTitle?: boolean;
402+
// Function that can be used to hook into the rendering process
399403
hooks?: {drawSeries: (uPlot, number) => void};
400404
};
401405

@@ -405,10 +409,11 @@ export function renderPlots(
405409
data: GraphData,
406410
selector: GraphsSelector,
407411
plotElement: HTMLElement,
408-
opts?: GraphRenderOpts
412+
opts: GraphRenderOpts
409413
) {
410-
const renderTitle = opts?.renderTitle ?? true;
411-
const hooks = opts?.hooks ?? {};
414+
const renderTitle = opts.renderTitle ?? true;
415+
const hooks = opts.hooks ?? {};
416+
const width = opts.width;
412417

413418
normalizeData(data);
414419

@@ -487,7 +492,7 @@ export function renderPlots(
487492
cacheStates[Object.keys(cacheStates)[0]].interpolated_indices;
488493

489494
let plotOpts = genPlotOpts({
490-
width: Math.floor(window.innerWidth / 4) - 40,
495+
width,
491496
height: 300,
492497
yAxisLabel,
493498
series: seriesOpts,

site/frontend/src/pages/compare/compile/table/benchmark-detail.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ async function renderGraph() {
112112
};
113113
const graphData = await GRAPH_RESOLVER.loadGraph(selector);
114114
const opts: GraphRenderOpts = {
115+
width: Math.min(window.innerWidth - 40, 480),
115116
renderTitle: false,
116117
};
117118
if (date !== null) {

site/frontend/src/pages/graphs/page.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@ async function loadGraphData(selector: GraphsSelector, loading: Ref<boolean>) {
6868
// Then draw the plots.
6969
await nextTick();
7070
71+
const width = Math.floor(window.innerWidth / 4) - 40;
72+
const opts = {width};
73+
7174
// If we select a smaller subset of benchmarks, then just show them.
7275
if (hasSpecificSelection(selector)) {
73-
renderPlots(graphData, selector, document.getElementById("charts"));
76+
renderPlots(graphData, selector, document.getElementById("charts"), opts);
7477
} else {
7578
// If we select all of them, we expect that there will be a regular grid.
7679
@@ -81,15 +84,20 @@ async function loadGraphData(selector: GraphsSelector, loading: Ref<boolean>) {
8184
graphData,
8285
(benchName) => !benchName.endsWith("-tiny")
8386
);
84-
renderPlots(withoutTiny, selector, document.getElementById("charts"));
87+
renderPlots(withoutTiny, selector, document.getElementById("charts"), opts);
8588
8689
// Then, render only the size-related ones in their own dedicated section as they are less
8790
// important than having the better grouping. So, we only include the benchmarks ending in
8891
// "-tiny" and render them in the appropriate section.
8992
const onlyTiny = filterBenchmarks(graphData, (benchName) =>
9093
benchName.endsWith("-tiny")
9194
);
92-
renderPlots(onlyTiny, selector, document.getElementById("size-charts"));
95+
renderPlots(
96+
onlyTiny,
97+
selector,
98+
document.getElementById("size-charts"),
99+
opts
100+
);
93101
}
94102
}
95103

0 commit comments

Comments
 (0)