From 636181965da6d32ed966d20d259a27e297e7694f Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 15 May 2022 11:30:10 -0700 Subject: Improve chart layout --- modern/src/reports/ChartReportPage.js | 58 ++++++++++++++++++++++++++++------ modern/src/reports/components/Graph.js | 43 ------------------------- 2 files changed, 49 insertions(+), 52 deletions(-) delete mode 100644 modern/src/reports/components/Graph.js (limited to 'modern/src/reports') diff --git a/modern/src/reports/ChartReportPage.js b/modern/src/reports/ChartReportPage.js index 57c7c689..7056dc70 100644 --- a/modern/src/reports/ChartReportPage.js +++ b/modern/src/reports/ChartReportPage.js @@ -1,9 +1,11 @@ import React, { useState } from 'react'; import { - FormControl, InputLabel, Select, MenuItem, + FormControl, InputLabel, Select, MenuItem, makeStyles, } from '@material-ui/core'; +import { + CartesianGrid, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis, +} from 'recharts'; import ReportFilter, { useFilterStyles } from './components/ReportFilter'; -import Graph from './components/Graph'; import { useAttributePreference } from '../common/util/preferences'; import { formatDate } from '../common/util/formatter'; import { speedFromKnots } from '../common/util/converter'; @@ -11,8 +13,23 @@ import { useTranslation } from '../common/components/LocalizationProvider'; import PageLayout from '../common/components/PageLayout'; import ReportsMenu from './components/ReportsMenu'; +const typesArray = [ + ['speed', 'positionSpeed'], + ['accuracy', 'positionAccuracy'], + ['altitude', 'positionAltitude'], +]; +const typesMap = new Map(typesArray); + +const useStyles = makeStyles(() => ({ + chart: { + flexGrow: 1, + overflow: 'hidden', + }, +})); + const ChartReportPage = () => { - const classes = useFilterStyles(); + const classes = useStyles(); + const filterClasses = useFilterStyles(); const t = useTranslation(); const speedUnit = useAttributePreference('speedUnit'); @@ -20,6 +37,12 @@ const ChartReportPage = () => { const [items, setItems] = useState([]); const [type, setType] = useState('speed'); + const dataRange = (() => { + const values = items.map((it) => it[type]); + const result = Math.max(...values) - Math.min(...values); + return result; + })(); + const handleSubmit = async (deviceId, from, to, mail, headers) => { const query = new URLSearchParams({ deviceId, from, to, mail, @@ -31,7 +54,7 @@ const ChartReportPage = () => { speed: Number(speedFromKnots(position.speed, speedUnit)), altitude: position.altitude, accuracy: position.accuracy, - fixTime: formatDate(position.fixTime), + fixTime: formatDate(position.fixTime, 'HH:mm:ss'), })); setItems(formattedPositions); } @@ -40,18 +63,35 @@ const ChartReportPage = () => { return ( } breadcrumbs={['reportTitle', 'reportChart']}> -
+
{t('reportChartType')}
- + {items.length > 0 && ( +
+ + + + + + [value, t(typesMap.get(name))]} /> + + + +
+ )} ); }; diff --git a/modern/src/reports/components/Graph.js b/modern/src/reports/components/Graph.js deleted file mode 100644 index 88b51493..00000000 --- a/modern/src/reports/components/Graph.js +++ /dev/null @@ -1,43 +0,0 @@ -import React from 'react'; -import { makeStyles } from '@material-ui/core'; -import { - LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, -} from 'recharts'; - -const CustomizedAxisTick = ({ x, y, payload }) => { - if (!payload.value) { - return payload.value; - } - const parts = payload.value.split(' '); - return ( - - {parts[0]} - {parts[1]} - - ); -}; - -const useStyles = makeStyles((theme) => ({ - chart: { - backgroundColor: theme.palette.colors.white, - }, -})); - -const Graph = ({ type, items }) => { - const classes = useStyles(); - - return ( - - - } height={60} /> - - - - - - - - ); -}; - -export default Graph; -- cgit v1.2.3