diff --git a/fittrackee_client/src/components/App.css b/fittrackee_client/src/components/App.css index 3b9826f7..ec986f13 100644 --- a/fittrackee_client/src/components/App.css +++ b/fittrackee_client/src/components/App.css @@ -181,6 +181,20 @@ label { font-size: 0.8em; } +.custom-tooltip { + background-color: #fff; + border: 1px solid lightgrey; + padding: 10px; +} + +.custom-tooltip p { + margin: 5px; +} + +.custom-tooltip-label { + font-weight: bold; +} + .dashboard, .history { margin-top: 30px; } diff --git a/fittrackee_client/src/components/Dashboard/Statistics.jsx b/fittrackee_client/src/components/Dashboard/Statistics.jsx index 17109fa1..2980a502 100644 --- a/fittrackee_client/src/components/Dashboard/Statistics.jsx +++ b/fittrackee_client/src/components/Dashboard/Statistics.jsx @@ -7,6 +7,7 @@ import { import { getStats } from '../../actions/stats' import { activityColors, formatDuration, formatStats } from '../../utils' +import CustomTooltip from '../Others/CustomTooltip' class Statistics extends React.Component { @@ -94,17 +95,16 @@ class Statistics extends React.Component { : value } /> - + + } + /> {sports.map((s, i) => ( displayedData === 'duration' - ? format(formatDuration(value), 'HH:mm') - : displayedData === 'distance' - ? value.toFixed(3) - : value - } stackId="a" fill={activityColors[i]} unit={displayedData === 'distance' ? ' km' : ''} diff --git a/fittrackee_client/src/components/Others/CustomTooltip.jsx b/fittrackee_client/src/components/Others/CustomTooltip.jsx new file mode 100644 index 00000000..565c6474 --- /dev/null +++ b/fittrackee_client/src/components/Others/CustomTooltip.jsx @@ -0,0 +1,39 @@ +import React from 'react' +import { format } from 'date-fns' + +import { formatDuration } from '../../utils' + +const formatValue = (displayedData, value) => displayedData === 'duration' + ? format(formatDuration(value), 'HH:mm') + : displayedData === 'distance' + ? value.toFixed(3) + : value + + +/** + * @return {null} + */ +export default function CustomTooltip (props) { + const { active } = props + if (active) { + const { displayedData, payload, label } = props + let total = 0 + payload.map(p => total += p.value) + return ( + + {label} + {payload.map(p => ( + + {p.name}: {formatValue(displayedData, p.value)} {p.unit} + )) + } + {payload.length > 0 && ( + + Total: {formatValue(displayedData, total)} {payload[0].unit} + + )} + + ) + } + return null +}
{label}
+ {p.name}: {formatValue(displayedData, p.value)} {p.unit} +
+ Total: {formatValue(displayedData, total)} {payload[0].unit} +