Skip to content

Commit 025f64b

Browse files
authored
Merge pull request #1988 from s7tya/expand-if-only-one-graph-selected
Expand when only one graph is selected
2 parents ce77826 + 56613af commit 025f64b

File tree

5 files changed

+57
-20
lines changed

5 files changed

+57
-20
lines changed

site/frontend/src/graph/render.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ function normalizeData(data: CompileGraphData) {
400400
export type GraphRenderOpts = {
401401
// Width of the graph
402402
width: number;
403+
// Height of the graph
404+
height: number;
403405
// Render a title above the graph
404406
renderTitle?: boolean;
405407
// Function that can be used to hook into the rendering process
@@ -416,7 +418,7 @@ export function renderPlots(
416418
) {
417419
const renderTitle = opts.renderTitle ?? true;
418420
const hooks = opts.hooks ?? {};
419-
const width = opts.width;
421+
const {width, height} = opts;
420422

421423
normalizeData(data);
422424

@@ -504,7 +506,7 @@ export function renderPlots(
504506

505507
let plotOpts = genPlotOpts({
506508
width,
507-
height: 300,
509+
height,
508510
yAxisLabel,
509511
series: seriesOpts,
510512
commits: data.commits,
@@ -534,7 +536,7 @@ export function renderRuntimePlots(
534536
) {
535537
const renderTitle = opts.renderTitle ?? true;
536538
const hooks = opts.hooks ?? {};
537-
const width = opts.width;
539+
const {width, height} = opts;
538540

539541
const benchNames = Object.keys(data.benchmarks).sort();
540542

@@ -610,7 +612,7 @@ export function renderRuntimePlots(
610612

611613
let plotOpts = genPlotOpts({
612614
width,
613-
height: 300,
615+
height,
614616
yAxisLabel,
615617
series: seriesOpts,
616618
commits: data.commits,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ async function renderGraph(
120120
) {
121121
const opts: GraphRenderOpts = {
122122
width: Math.min(window.innerWidth - 40, 465),
123+
height: 300,
123124
renderTitle: false,
124125
};
125126
if (date !== null) {

site/frontend/src/pages/compare/runtime/benchmark-detail-graph.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ async function renderGraph(
109109
) {
110110
const opts: GraphRenderOpts = {
111111
width: Math.min(window.innerWidth - 40, 465),
112+
height: 300,
112113
renderTitle: false,
113114
};
114115
if (date !== null) {

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

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,30 @@ async function loadGraphData(selector: GraphsSelector, loading: Ref<boolean>) {
6868
// Then draw the plots.
6969
await nextTick();
7070
71-
const width = Math.max(Math.floor(window.innerWidth / 4) - 40, 380);
72-
const opts = {width};
71+
const countGraphs = Object.keys(graphData.benchmarks)
72+
.map((benchmark) => Object.keys(graphData.benchmarks[benchmark]).length)
73+
.reduce((sum, item) => sum + item, 0);
74+
75+
const parentWidth = wrapperRef.value.clientWidth;
76+
let columns = countGraphs === 1 ? 1 : 4;
77+
78+
// Small display, reduce column count to 1
79+
if (parentWidth < 1000) {
80+
columns = 1;
81+
}
82+
83+
// Calculate the width of each column.
84+
// Provide a 10px buffer to avoid wrapping if the size is just at the limit
85+
// of the parent.
86+
const width = Math.floor(wrapperRef.value.clientWidth / columns) - 10;
87+
88+
const top = wrapperRef.value.getBoundingClientRect().top;
89+
const height = countGraphs === 1 ? window.innerHeight - top - 100 : 300;
90+
91+
const opts = {
92+
width,
93+
height,
94+
};
7395
7496
// If we select a smaller subset of benchmarks, then just show them.
7597
if (hasSpecificSelection(selector)) {
@@ -115,8 +137,10 @@ function updateSelection(params: SelectionParams) {
115137
const info: BenchmarkInfo = await loadBenchmarkInfo();
116138
117139
const loading = ref(true);
140+
const wrapperRef = ref(null);
118141
119142
const selector: GraphsSelector = loadSelectorFromUrl(getUrlParams());
143+
120144
loadGraphData(selector, loading);
121145
</script>
122146

@@ -138,21 +162,29 @@ loadGraphData(selector, loading);
138162
interpolated due to missing data. Interpolated data is simply the last known
139163
data point repeated until another known data point is found.
140164
</div>
141-
<div v-if="loading">
142-
<h2>Loading &amp; rendering data..</h2>
143-
<h3>This may take a while!</h3>
144-
</div>
145-
<div v-else>
146-
<div id="charts"></div>
147-
<div
148-
v-if="!hasSpecificSelection(selector)"
149-
style="margin-top: 50px; border-top: 1px solid #ccc"
150-
>
151-
<div style="padding: 20px 0">
152-
<strong>Benchmarks optimized for small binary size</strong>
165+
<div class="wrapper" ref="wrapperRef">
166+
<div v-if="loading">
167+
<h2>Loading &amp; rendering data..</h2>
168+
<h3>This may take a while!</h3>
169+
</div>
170+
<div v-else>
171+
<div id="charts"></div>
172+
<div
173+
v-if="!hasSpecificSelection(selector)"
174+
style="margin-top: 50px; border-top: 1px solid #ccc"
175+
>
176+
<div style="padding: 20px 0">
177+
<strong>Benchmarks optimized for small binary size</strong>
178+
</div>
179+
<div id="size-charts"></div>
153180
</div>
154-
<div id="size-charts"></div>
181+
<AsOf :info="info" />
155182
</div>
156-
<AsOf :info="info" />
157183
</div>
158184
</template>
185+
186+
<style lang="scss" scoped>
187+
.wrapper {
188+
width: 100%;
189+
}
190+
</style>

site/frontend/templates/pages/graphs.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
margin: 0;
4444
}
4545
</style>
46+
<link rel="stylesheet" type="text/css" href="scripts/graphs.css">
4647
{% endblock %}
4748
{% block content %}
4849
<div id="app"></div>

0 commit comments

Comments
 (0)