File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ interface DashboardPieChartProps {
1111}
1212
1313export const DashboardPieChart : React . FC < DashboardPieChartProps > = ( { entries} ) => {
14+ const total = entries . map ( ( e ) => e . timeSpendInSeconds ) . reduce ( ( x , y ) => x + y , 0 ) ;
1415 return (
1516 < ResponsiveContainer >
1617 < PieChart >
@@ -29,20 +30,25 @@ export const DashboardPieChart: React.FC<DashboardPieChartProps> = ({entries}) =
2930 < Cell key = { index } fill = { Colors [ index % Colors . length ] } />
3031 ) ) }
3132 </ Pie >
32- < Tooltip content = { < CustomTooltip /> } />
33+ < Tooltip content = { < CustomTooltip total = { total } /> } />
3334 < Legend />
3435 </ PieChart >
3536 </ ResponsiveContainer >
3637 ) ;
3738} ;
3839
39- const CustomTooltip = ( { active, payload} : TooltipProps ) => {
40+ interface CustomTooltipProps extends TooltipProps {
41+ total : number ;
42+ }
43+
44+ const CustomTooltip = ( { active, payload, total} : CustomTooltipProps ) => {
4045 if ( active && payload ) {
4146 const first = payload [ 0 ] ;
4247 return (
4348 < Paper style = { { padding : 10 } } elevation = { 4 } >
4449 < 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 ) } %)
4652 </ Typography >
4753 </ Paper >
4854 ) ;
You can’t perform that action at this time.
0 commit comments