Skip to content

Commit 76f85ff

Browse files
committed
Allow switching relative and absolute scale of the fraction chart
1 parent 03e4bd1 commit 76f85ff

File tree

2 files changed

+118
-43
lines changed

2 files changed

+118
-43
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,20 @@ onMounted(() => {
279279
});
280280
loadSections().then((d) => {
281281
sectionsDetail.value = d;
282+
sectionsDetail.value.before = {
283+
sections: [
284+
{name: "Frontend", value: 20},
285+
{name: "Backend", value: 15},
286+
{name: "Linker", value: 15},
287+
],
288+
};
289+
sectionsDetail.value.after = {
290+
sections: [
291+
{name: "Frontend", value: 20},
292+
{name: "Backend", value: 30},
293+
{name: "Linker", value: 50},
294+
],
295+
};
282296
});
283297
});
284298
</script>

site/frontend/src/pages/compare/compile/table/sections-chart.vue

Lines changed: 104 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ const props = defineProps<{
77
after: CompilationSections;
88
}>();
99
10+
enum CompareMode {
11+
/// Useful for comparing the fractional parts of sections
12+
Fractional,
13+
/// Useful for comparing the absolute durations of sections
14+
Absolute,
15+
}
16+
1017
function calculateTotalSectionsDuration(sections: CompilationSections): number {
1118
return sections.sections.reduce((accum, section) => accum + section.value, 0);
1219
}
@@ -18,6 +25,10 @@ const afterTotalWidth = computed(() => {
1825
return calculateTotalSectionsDuration(props.after);
1926
});
2027
28+
const maxTotalWidth = computed(() => {
29+
return Math.max(beforeTotalWidth.value, afterTotalWidth.value);
30+
});
31+
2132
const SECTIONS_PALETTE = [
2233
"#7768AE",
2334
"#FFCf96",
@@ -58,6 +69,18 @@ function formatPercent(
5869
return `${percent.toFixed(2)}%`;
5970
}
6071
72+
function getRowWidth(row: number): number {
73+
if (compareMode.value === CompareMode.Fractional) {
74+
if (row === 0) {
75+
return beforeTotalWidth.value;
76+
} else {
77+
return afterTotalWidth.value;
78+
}
79+
} else {
80+
return maxTotalWidth.value;
81+
}
82+
}
83+
6184
const chartRows: ComputedRef<Array<[string, CompilationSections]>> = computed(
6285
() => [
6386
["Before", props.before],
@@ -89,66 +112,88 @@ function activate(section: string) {
89112
function deactivate() {
90113
activeSection.value = null;
91114
}
115+
116+
const compareMode = ref(CompareMode.Absolute);
92117
</script>
93118

94119
<template>
95-
<div class="wrapper">
96-
<div class="chart-wrapper">
97-
<div class="chart" v-for="([label, sections], rowIndex) in chartRows">
98-
<span class="label">{{ label }}</span>
99-
<div class="section-wrapper">
100-
<div
101-
v-for="(section, index) in sections.sections"
102-
:class="{section: true, active: activeSection === section.name}"
103-
@mouseenter="activate(section.name)"
104-
@mouseleave="deactivate"
105-
:style="{
106-
width: calculate_width(
107-
section.value,
108-
rowIndex == 0 ? beforeTotalWidth : afterTotalWidth
109-
),
110-
backgroundColor: getSectionColor(index),
111-
}"
112-
>
120+
<div>
121+
<div class="wrapper">
122+
<div class="chart-wrapper">
123+
<div class="chart" v-for="([label, sections], rowIndex) in chartRows">
124+
<span class="label">{{ label }}</span>
125+
<div class="section-wrapper">
113126
<div
114-
class="description"
115-
v-if="rowIndex == 1 && activeSection === section.name"
127+
v-for="(section, index) in sections.sections"
128+
:class="{section: true, active: activeSection === section.name}"
129+
@mouseenter="activate(section.name)"
130+
@mouseleave="deactivate"
131+
:style="{
132+
width: calculate_width(section.value, getRowWidth(rowIndex)),
133+
backgroundColor: getSectionColor(index),
134+
}"
116135
>
117-
<div>
118-
<b>{{ section.name }}</b>
119-
</div>
120-
<div>
136+
<div
137+
class="description"
138+
v-if="rowIndex == 1 && activeSection === section.name"
139+
>
121140
<div>
122-
{{ formatPercent(props.before, section.name) }} ->
123-
{{ formatPercent(props.after, section.name) }}
141+
<b>{{ section.name }}</b>
124142
</div>
125143
<div>
126-
{{
127-
getSectionByName(props.before, section.name)?.value ?? "??"
128-
}}
129-
->
130-
{{
131-
getSectionByName(props.after, section.name)?.value ?? "??"
132-
}}
144+
<div>
145+
{{ formatPercent(props.before, section.name) }} ->
146+
{{ formatPercent(props.after, section.name) }}
147+
</div>
148+
<div>
149+
{{
150+
getSectionByName(props.before, section.name)?.value ??
151+
"??"
152+
}}
153+
->
154+
{{
155+
getSectionByName(props.after, section.name)?.value ?? "??"
156+
}}
157+
</div>
133158
</div>
134159
</div>
135160
</div>
136161
</div>
137162
</div>
138163
</div>
164+
<div class="legend">
165+
<div
166+
class="item"
167+
v-for="item in legendItems"
168+
@mouseenter="activate(item.section.name)"
169+
@mouseleave="deactivate"
170+
>
171+
<div
172+
:class="{color: true, active: activeSection === item.section.name}"
173+
:style="{backgroundColor: item.color}"
174+
></div>
175+
<div class="name">{{ item.label }}</div>
176+
</div>
177+
</div>
139178
</div>
140-
<div class="legend">
179+
<div class="controls">
141180
<div
142-
class="item"
143-
v-for="item in legendItems"
144-
@mouseenter="activate(item.section.name)"
145-
@mouseleave="deactivate"
181+
:class="{control: true, selected: compareMode === CompareMode.Absolute}"
182+
@click="compareMode = CompareMode.Absolute"
183+
title="Normalize chart width to the duration of the longer collection. Useful for comparing absolute durations of sections."
146184
>
147-
<div
148-
:class="{color: true, active: activeSection === item.section.name}"
149-
:style="{backgroundColor: item.color}"
150-
></div>
151-
<div class="name">{{ item.label }}</div>
185+
Absolute
186+
</div>
187+
&nbsp;/&nbsp;
188+
<div
189+
:class="{
190+
control: true,
191+
selected: compareMode === CompareMode.Fractional,
192+
}"
193+
@click="compareMode = CompareMode.Fractional"
194+
title="Normalize chart width to the duration of its collection. Useful for comparing percentual fractions of sections."
195+
>
196+
Relative
152197
</div>
153198
</div>
154199
</div>
@@ -223,4 +268,20 @@ function deactivate() {
223268
}
224269
}
225270
}
271+
272+
.controls {
273+
display: flex;
274+
justify-content: center;
275+
276+
.control {
277+
cursor: pointer;
278+
279+
&:hover {
280+
text-decoration: underline;
281+
}
282+
&.selected {
283+
font-weight: bold;
284+
}
285+
}
286+
}
226287
</style>

0 commit comments

Comments
 (0)