File tree 1 file changed +9
-3
lines changed
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ interface DashboardPieChartProps {
11
11
}
12
12
13
13
export const DashboardPieChart : React . FC < DashboardPieChartProps > = ( { entries} ) => {
14
+ const total = entries . map ( ( e ) => e . timeSpendInSeconds ) . reduce ( ( x , y ) => x + y , 0 ) ;
14
15
return (
15
16
< ResponsiveContainer >
16
17
< PieChart >
@@ -29,20 +30,25 @@ export const DashboardPieChart: React.FC<DashboardPieChartProps> = ({entries}) =
29
30
< Cell key = { index } fill = { Colors [ index % Colors . length ] } />
30
31
) ) }
31
32
</ Pie >
32
- < Tooltip content = { < CustomTooltip /> } />
33
+ < Tooltip content = { < CustomTooltip total = { total } /> } />
33
34
< Legend />
34
35
</ PieChart >
35
36
</ ResponsiveContainer >
36
37
) ;
37
38
} ;
38
39
39
- const CustomTooltip = ( { active, payload} : TooltipProps ) => {
40
+ interface CustomTooltipProps extends TooltipProps {
41
+ total : number ;
42
+ }
43
+
44
+ const CustomTooltip = ( { active, payload, total} : CustomTooltipProps ) => {
40
45
if ( active && payload ) {
41
46
const first = payload [ 0 ] ;
42
47
return (
43
48
< Paper style = { { padding : 10 } } elevation = { 4 } >
44
49
< Typography >
45
- { first . payload . key } :{ first . payload . value } : { prettyMs ( first . payload . timeSpendInSeconds * 1000 ) }
50
+ { first . payload . key } :{ first . payload . value } : { prettyMs ( first . payload . timeSpendInSeconds * 1000 ) } (
51
+ { ( ( first . payload . timeSpendInSeconds / total ) * 100 ) . toFixed ( 2 ) } %)
46
52
</ Typography >
47
53
</ Paper >
48
54
) ;
You can’t perform that action at this time.
0 commit comments