From 2a2d3e02ab8d0a20e36b4302a32003da215d4c95 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 4 Jan 2019 19:17:16 +0100 Subject: [PATCH] start and end dates can be updated on stats graph --- .../components/Common/Stats/CustomLabel.jsx | 6 ++ .../components/Common/Stats/StatsChart.jsx | 3 + .../src/components/Common/Stats/index.jsx | 6 +- .../src/components/Dashboard/Statistics.jsx | 2 +- .../src/components/Statistics/index.jsx | 55 +++++++++++++++++++ 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/fittrackee_client/src/components/Common/Stats/CustomLabel.jsx b/fittrackee_client/src/components/Common/Stats/CustomLabel.jsx index 6d85d0c2..e640e463 100644 --- a/fittrackee_client/src/components/Common/Stats/CustomLabel.jsx +++ b/fittrackee_client/src/components/Common/Stats/CustomLabel.jsx @@ -2,8 +2,14 @@ import React from 'react' import { formatValue } from '../../../utils/stats' +/** + * @return {null} + */ export default function CustomLabel (props) { const { displayedData, x, y, width, value } = props + if (!value) { + return null + } const radius = 10 const formattedValue = formatValue(displayedData, value) diff --git a/fittrackee_client/src/components/Common/Stats/StatsChart.jsx b/fittrackee_client/src/components/Common/Stats/StatsChart.jsx index d706e7e1..42b495f0 100644 --- a/fittrackee_client/src/components/Common/Stats/StatsChart.jsx +++ b/fittrackee_client/src/components/Common/Stats/StatsChart.jsx @@ -79,6 +79,9 @@ export default class StatsCharts extends React.PureComponent { /> {sports.map((s, i) => (
- +
) diff --git a/fittrackee_client/src/components/Statistics/index.jsx b/fittrackee_client/src/components/Statistics/index.jsx index 2766c13f..e537f264 100644 --- a/fittrackee_client/src/components/Statistics/index.jsx +++ b/fittrackee_client/src/components/Statistics/index.jsx @@ -4,7 +4,12 @@ import { endOfYear, startOfMonth, startOfYear, + startOfWeek, + addMonths, + addWeeks, + addYears, subMonths, + subWeeks, subYears } from 'date-fns' import React from 'react' @@ -70,6 +75,37 @@ class Statistics extends React.Component { } } + handleOnClickArrows(forward) { + const { start, end, duration } = this.state.statsParams + let newStart, newEnd + if (forward) { + newStart = duration === 'year' + ? startOfYear(subYears(start, 1)) + : duration === 'week' + ? startOfWeek(subWeeks(start, 1)) + : startOfMonth(subMonths(start, 1)) + newEnd = duration === 'year' + ? endOfYear(subYears(end, 1)) + : duration === 'week' + ? endOfWeek(subWeeks(end, 1)) + : endOfMonth(subMonths(end, 1)) + } else { + newStart = duration === 'year' + ? startOfYear(addYears(start, 1)) + : duration === 'week' + ? startOfWeek(addWeeks(start, 1)) + : startOfMonth(addMonths(start, 1)) + newEnd = duration === 'year' + ? endOfYear(addYears(end, 1)) + : duration === 'week' + ? endOfWeek(addWeeks(end, 1)) + : endOfMonth(addMonths(end, 1)) + } + this.setState({ statsParams: + { duration, end: newEnd, start: newStart, type: 'by_time' } + }) + } + render() { const { displayedSports, statsParams } = this.state const { sports } = this.props @@ -81,6 +117,15 @@ class Statistics extends React.Component {
+
+

+