aboutsummaryrefslogtreecommitdiff
path: root/modern
diff options
context:
space:
mode:
authorAshutosh Bishnoi <mail2bishnoi@gmail.com>2020-11-25 14:07:59 +0530
committerAshutosh Bishnoi <mail2bishnoi@gmail.com>2020-11-25 14:07:59 +0530
commit032d1a787384430a5bd93a3caf7e92bb0a5fa8aa (patch)
tree87a3fc0b466b37108c8f5c6a4a0a6787fa8293fb /modern
parent34ec9a62ac0b65665f15f6e80729495e2558547f (diff)
downloadtrackermap-web-032d1a787384430a5bd93a3caf7e92bb0a5fa8aa.tar.gz
trackermap-web-032d1a787384430a5bd93a3caf7e92bb0a5fa8aa.tar.bz2
trackermap-web-032d1a787384430a5bd93a3caf7e92bb0a5fa8aa.zip
Improvements and minor refactoring in chart report
Diffstat (limited to 'modern')
-rw-r--r--modern/src/reports/ChartReportPage.js22
-rw-r--r--modern/src/reports/ReportLayoutPage.js24
2 files changed, 26 insertions, 20 deletions
diff --git a/modern/src/reports/ChartReportPage.js b/modern/src/reports/ChartReportPage.js
index e37f7ca1..5aefca15 100644
--- a/modern/src/reports/ChartReportPage.js
+++ b/modern/src/reports/ChartReportPage.js
@@ -1,15 +1,12 @@
import React, { useState } from 'react';
-import { Box, Paper, FormControl, InputLabel, Select, MenuItem } from '@material-ui/core';
+import { Box, Paper } from '@material-ui/core';
import ReportFilter from './ReportFilter';
import ReportLayoutPage from './ReportLayoutPage';
-import t from '../common/localization';
-import { chartTypes } from '../common/chartTypes';
import { useAttributePreference } from '../common/preferences';
import { getConverter, formatDate } from '../common/formatter';
-
import {LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
-const ReportFilterForm = ({ setItems, setType }) => {
+const ReportFilterForm = ({ setItems }) => {
const speedUnit = useAttributePreference('speedUnit');
@@ -20,7 +17,7 @@ const ReportFilterForm = ({ setItems, setType }) => {
const data = await response.json();
let formattedData = data.map((obj)=>{
return Object.assign(obj,
- {speed: getConverter('speed')(obj.speed, speedUnit)},
+ {speed: Number(getConverter('speed')(obj.speed, speedUnit))},
{fixTime: formatDate(obj.fixTime)}
);
})
@@ -29,16 +26,7 @@ const ReportFilterForm = ({ setItems, setType }) => {
}
return (
- <ReportFilter handleSubmit={handleSubmit} showOnly >
- <FormControl variant="filled" margin="normal" fullWidth>
- <InputLabel>{t('reportChartType')}</InputLabel>
- <Select defaultValue="speed" onChange={e => setType(e.target.value)}>
- {chartTypes.map(item => (
- <MenuItem key={item.id} value={item.id}>{item.name}</MenuItem>
- ))}
- </Select>
- </FormControl>
- </ReportFilter>
+ <ReportFilter handleSubmit={handleSubmit} showOnly />
)
};
@@ -58,7 +46,7 @@ const ChartReportPage = () => {
const [type, setType] = useState('speed');
return (
- <ReportLayoutPage reportFilterForm={ReportFilterForm} setItems={setItems} setType={setType}>
+ <ReportLayoutPage reportFilterForm={ReportFilterForm} setItems={setItems} setType={setType} showChartType>
<Paper>
<Box height={400}>
<ResponsiveContainer>
diff --git a/modern/src/reports/ReportLayoutPage.js b/modern/src/reports/ReportLayoutPage.js
index e4219bfd..53b7039a 100644
--- a/modern/src/reports/ReportLayoutPage.js
+++ b/modern/src/reports/ReportLayoutPage.js
@@ -1,6 +1,8 @@
import React from 'react';
-import { Grid, Paper, makeStyles } from '@material-ui/core';
+import { Grid, Paper, makeStyles, FormControl, InputLabel, Select, MenuItem } from '@material-ui/core';
import MainToolbar from '../MainToolbar';
+import { chartTypes } from '../common/chartTypes';
+import t from '../common/localization';
const useStyles = makeStyles(theme => ({
root: {
@@ -16,9 +18,13 @@ const useStyles = makeStyles(theme => ({
form: {
padding: theme.spacing(1, 2, 2),
},
+ chart: {
+ padding: theme.spacing(1, 2, 2),
+ marginTop: theme.spacing(1),
+ },
}));
-const ReportLayoutPage = ({ reportFilterForm:ReportFilterForm, setItems, setType, children }) => {
+const ReportLayoutPage = ({ reportFilterForm:ReportFilterForm, setItems, setType, showChartType, children }) => {
const classes = useStyles();
return (
<div className={classes.root}>
@@ -27,8 +33,20 @@ const ReportLayoutPage = ({ reportFilterForm:ReportFilterForm, setItems, setType
<Grid container spacing={2}>
<Grid item xs={12} md={3} lg={2}>
<Paper className={classes.form}>
- <ReportFilterForm setItems={ setItems } setType={ setType }/>
+ <ReportFilterForm setItems={ setItems } />
</Paper>
+ {showChartType && (
+ <Paper className={classes.chart}>
+ <FormControl variant="filled" margin="normal" fullWidth>
+ <InputLabel>{t('reportChartType')}</InputLabel>
+ <Select defaultValue="speed" onChange={e => setType(e.target.value)}>
+ {chartTypes.map(item => (
+ <MenuItem key={item.id} value={item.id}>{item.name}</MenuItem>
+ ))}
+ </Select>
+ </FormControl>
+ </Paper>
+ )}
</Grid>
<Grid item xs={12} md={9} lg={10}>
{children}