Skip to content

Commit c1ecbf7

Browse files
authored
Merge pull request #185 from Minnowo/issue_154
Add percentage to pie chart tooltip
2 parents ff789f5 + b15ef9e commit c1ecbf7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

ui/src/dashboard/Entry/DashboardPieChart.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface DashboardPieChartProps {
1111
}
1212

1313
export 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
);

0 commit comments

Comments
 (0)