Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make fraction chart relative to its corresponding artifact #1775

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions site/frontend/src/pages/compare/compile/table/sections-chart.vue
Original file line number Diff line number Diff line change
@@ -7,16 +7,17 @@ const props = defineProps<{
after: CompilationSections;
}>();

const maxTotalDuration = computed(() => {
const before = calculateTotalSectionsDuration(props.before);
const after = calculateTotalSectionsDuration(props.after);
return Math.max(before, after);
});

function calculateTotalSectionsDuration(sections: CompilationSections): number {
return sections.sections.reduce((accum, section) => accum + section.value, 0);
}

const beforeTotalWidth = computed(() => {
return calculateTotalSectionsDuration(props.before);
});
const afterTotalWidth = computed(() => {
return calculateTotalSectionsDuration(props.after);
});

const SECTIONS_PALETTE = [
"#7768AE",
"#FFCf96",
@@ -29,8 +30,8 @@ function getSectionColor(index: number): string {
return SECTIONS_PALETTE[index % SECTIONS_PALETTE.length];
}

function calculate_width(value: number): string {
const fraction = value / maxTotalDuration.value;
function calculate_width(value: number, totalDuration: number): string {
const fraction = value / totalDuration;
return `${(fraction * 100).toFixed(2)}%`;
}

@@ -53,12 +54,16 @@ const chartRows: ComputedRef<Array<[string, CompilationSections]>> = computed(
]
);
const legendItems: ComputedRef<
Array<{section: CompilationSection; color: string}>
Array<{section: CompilationSection; label: string; color: string}>
> = computed(() => {
const items = [];
for (const section of props.before.sections) {
items.push({
section,
label: `${section.name} (${formatPercent(
props.before,
section.name
)} -> ${formatPercent(props.after, section.name)})`,
color: getSectionColor(items.length),
});
}
@@ -87,7 +92,10 @@ function deactivate() {
@mouseenter="activate(section.name)"
@mouseleave="deactivate"
:style="{
width: calculate_width(section.value),
width: calculate_width(
section.value,
rowIndex == 0 ? beforeTotalWidth : afterTotalWidth
),
backgroundColor: getSectionColor(index),
}"
>
@@ -118,7 +126,7 @@ function deactivate() {
:class="{color: true, active: activeSection === item.section.name}"
:style="{backgroundColor: item.color}"
></div>
<div class="name">{{ item.section.name }}</div>
<div class="name">{{ item.label }}</div>
</div>
</div>
</div>
@@ -147,7 +155,6 @@ function deactivate() {
width: calc(100% - 60px);
display: flex;
flex-direction: row;
border-right: 1px dashed #333333;

.section {
height: 30px;