From 7d33126e07d173c75d149812c2bb32d305f9e847 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 29 Jul 2018 14:55:57 +0200 Subject: [PATCH] display total on current month statistics - fix #22 --- fittrackee_client/src/components/App.css | 14 +++++++ .../src/components/Dashboard/Statistics.jsx | 14 +++---- .../src/components/Others/CustomTooltip.jsx | 39 +++++++++++++++++++ 3 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 fittrackee_client/src/components/Others/CustomTooltip.jsx 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 +}