Skip to content

Commit 2d336b1

Browse files
authored
Merge pull request #1775 from Kobzol/fraction-chart-relative
Make fraction chart relative to its corresponding artifact
2 parents dc2ac6a + 215ebff commit 2d336b1

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

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

+19-12
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ const props = defineProps<{
77
after: CompilationSections;
88
}>();
99
10-
const maxTotalDuration = computed(() => {
11-
const before = calculateTotalSectionsDuration(props.before);
12-
const after = calculateTotalSectionsDuration(props.after);
13-
return Math.max(before, after);
14-
});
15-
1610
function calculateTotalSectionsDuration(sections: CompilationSections): number {
1711
return sections.sections.reduce((accum, section) => accum + section.value, 0);
1812
}
1913
14+
const beforeTotalWidth = computed(() => {
15+
return calculateTotalSectionsDuration(props.before);
16+
});
17+
const afterTotalWidth = computed(() => {
18+
return calculateTotalSectionsDuration(props.after);
19+
});
20+
2021
const SECTIONS_PALETTE = [
2122
"#7768AE",
2223
"#FFCf96",
@@ -29,8 +30,8 @@ function getSectionColor(index: number): string {
2930
return SECTIONS_PALETTE[index % SECTIONS_PALETTE.length];
3031
}
3132
32-
function calculate_width(value: number): string {
33-
const fraction = value / maxTotalDuration.value;
33+
function calculate_width(value: number, totalDuration: number): string {
34+
const fraction = value / totalDuration;
3435
return `${(fraction * 100).toFixed(2)}%`;
3536
}
3637
@@ -53,12 +54,16 @@ const chartRows: ComputedRef<Array<[string, CompilationSections]>> = computed(
5354
]
5455
);
5556
const legendItems: ComputedRef<
56-
Array<{section: CompilationSection; color: string}>
57+
Array<{section: CompilationSection; label: string; color: string}>
5758
> = computed(() => {
5859
const items = [];
5960
for (const section of props.before.sections) {
6061
items.push({
6162
section,
63+
label: `${section.name} (${formatPercent(
64+
props.before,
65+
section.name
66+
)} -> ${formatPercent(props.after, section.name)})`,
6267
color: getSectionColor(items.length),
6368
});
6469
}
@@ -87,7 +92,10 @@ function deactivate() {
8792
@mouseenter="activate(section.name)"
8893
@mouseleave="deactivate"
8994
:style="{
90-
width: calculate_width(section.value),
95+
width: calculate_width(
96+
section.value,
97+
rowIndex == 0 ? beforeTotalWidth : afterTotalWidth
98+
),
9199
backgroundColor: getSectionColor(index),
92100
}"
93101
>
@@ -118,7 +126,7 @@ function deactivate() {
118126
:class="{color: true, active: activeSection === item.section.name}"
119127
:style="{backgroundColor: item.color}"
120128
></div>
121-
<div class="name">{{ item.section.name }}</div>
129+
<div class="name">{{ item.label }}</div>
122130
</div>
123131
</div>
124132
</div>
@@ -147,7 +155,6 @@ function deactivate() {
147155
width: calc(100% - 60px);
148156
display: flex;
149157
flex-direction: row;
150-
border-right: 1px dashed #333333;
151158
152159
.section {
153160
height: 30px;

0 commit comments

Comments
 (0)