From c1af957e50e7d4e3c10e21c980ef8848726f3c2c Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 29 May 2018 11:35:52 +0200 Subject: [PATCH] Client: checkbox for chart --- .../ActivityDisplay/ActivityCharts.jsx | 115 ++++++++++++------ 1 file changed, 79 insertions(+), 36 deletions(-) diff --git a/mpwo_client/src/components/Activities/ActivityDisplay/ActivityCharts.jsx b/mpwo_client/src/components/Activities/ActivityDisplay/ActivityCharts.jsx index 6e8f14a9..3bb958e1 100644 --- a/mpwo_client/src/components/Activities/ActivityDisplay/ActivityCharts.jsx +++ b/mpwo_client/src/components/Activities/ActivityDisplay/ActivityCharts.jsx @@ -13,6 +13,7 @@ class ActivityCharts extends React.Component { super(props, context) this.state = { displayDistance: true, + dataToHide: [] } } @@ -40,6 +41,22 @@ class ActivityCharts extends React.Component { }) } + handleLegendChange (e) { + const { dataToHide } = this.state + const name = e.target.name // eslint-disable-line prefer-destructuring + if (dataToHide.find(d => d === name)) { + dataToHide.splice(dataToHide.indexOf(name), 1) + } else { + dataToHide.push(name) + } + this.setState({ dataToHide }) + } + + displayData (name) { + const { dataToHide } = this.state + return !dataToHide.find(d => d === name) + } + render() { const { chartData } = this.props const { displayDistance } = this.state @@ -54,28 +71,50 @@ class ActivityCharts extends React.Component { } return (
-
- - -
{chartData && chartData.length > 0 ? (
+
+ + +
+
+
+ + +
+
- - + {this.displayData('elevation') && ( + + )} + {this.displayData('speed') && ( + + )} displayDistance ? `distance: ${value} km`