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}
)}