@@ -7,16 +7,17 @@ const props = defineProps<{
7
7
after: CompilationSections ;
8
8
}>();
9
9
10
- const maxTotalDuration = computed (() => {
11
- const before = calculateTotalSectionsDuration (props .before );
12
- const after = calculateTotalSectionsDuration (props .after );
13
- return Math .max (before , after );
14
- });
15
-
16
10
function calculateTotalSectionsDuration(sections : CompilationSections ): number {
17
11
return sections .sections .reduce ((accum , section ) => accum + section .value , 0 );
18
12
}
19
13
14
+ const beforeTotalWidth = computed (() => {
15
+ return calculateTotalSectionsDuration (props .before );
16
+ });
17
+ const afterTotalWidth = computed (() => {
18
+ return calculateTotalSectionsDuration (props .after );
19
+ });
20
+
20
21
const SECTIONS_PALETTE = [
21
22
" #7768AE" ,
22
23
" #FFCf96" ,
@@ -29,8 +30,8 @@ function getSectionColor(index: number): string {
29
30
return SECTIONS_PALETTE [index % SECTIONS_PALETTE .length ];
30
31
}
31
32
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 ;
34
35
return ` ${(fraction * 100 ).toFixed (2 )}% ` ;
35
36
}
36
37
@@ -53,12 +54,16 @@ const chartRows: ComputedRef<Array<[string, CompilationSections]>> = computed(
53
54
]
54
55
);
55
56
const legendItems: ComputedRef <
56
- Array <{section: CompilationSection ; color: string }>
57
+ Array <{section: CompilationSection ; label : string ; color: string }>
57
58
> = computed (() => {
58
59
const items = [];
59
60
for (const section of props .before .sections ) {
60
61
items .push ({
61
62
section ,
63
+ label: ` ${section .name } (${formatPercent (
64
+ props .before ,
65
+ section .name
66
+ )} -> ${formatPercent (props .after , section .name )}) ` ,
62
67
color: getSectionColor (items .length ),
63
68
});
64
69
}
@@ -87,7 +92,10 @@ function deactivate() {
87
92
@mouseenter =" activate(section.name)"
88
93
@mouseleave =" deactivate"
89
94
:style =" {
90
- width: calculate_width(section.value),
95
+ width: calculate_width(
96
+ section.value,
97
+ rowIndex == 0 ? beforeTotalWidth : afterTotalWidth
98
+ ),
91
99
backgroundColor: getSectionColor(index),
92
100
}"
93
101
>
@@ -118,7 +126,7 @@ function deactivate() {
118
126
:class =" {color: true, active: activeSection === item.section.name}"
119
127
:style =" {backgroundColor: item.color}"
120
128
></div >
121
- <div class =" name" >{{ item.section.name }}</div >
129
+ <div class =" name" >{{ item.label }}</div >
122
130
</div >
123
131
</div >
124
132
</div >
@@ -147,7 +155,6 @@ function deactivate() {
147
155
width : calc (100% - 60px );
148
156
display : flex ;
149
157
flex-direction : row ;
150
- border-right : 1px dashed #333333 ;
151
158
152
159
.section {
153
160
height : 30px ;
0 commit comments