diff options
author | Ashutosh Bishnoi <mail2bishnoi@gmail.com> | 2020-11-28 13:23:13 +0530 |
---|---|---|
committer | Ashutosh Bishnoi <mail2bishnoi@gmail.com> | 2020-11-28 13:23:13 +0530 |
commit | 7a431062aa79ac9c9524638e60cb4b06323ea697 (patch) | |
tree | 30bb8992d0a74d5a12faaac36fbb89c3d478edf1 /modern/src | |
parent | 9c2dbcf00b944cca546875af4f0bcab695119a40 (diff) | |
download | trackermap-web-7a431062aa79ac9c9524638e60cb4b06323ea697.tar.gz trackermap-web-7a431062aa79ac9c9524638e60cb4b06323ea697.tar.bz2 trackermap-web-7a431062aa79ac9c9524638e60cb4b06323ea697.zip |
Chart report code improvements and refactoring
Diffstat (limited to 'modern/src')
-rw-r--r-- | modern/src/common/converter.js | 13 | ||||
-rw-r--r-- | modern/src/reports/ChartReportPage.js | 19 |
2 files changed, 11 insertions, 21 deletions
diff --git a/modern/src/common/converter.js b/modern/src/common/converter.js index 8fdb4b86..e48b0760 100644 --- a/modern/src/common/converter.js +++ b/modern/src/common/converter.js @@ -1,4 +1,4 @@ -const speedConverter = (value, unit) => { +export const speedConverter = (value, unit) => { let factor; switch (unit) { case 'kmh': @@ -11,14 +11,3 @@ const speedConverter = (value, unit) => { } return (value * factor).toFixed(2); }; - -export const getConverter = (key) => { - switch (key) { - case 'speed': - return speedConverter; - default: - return function (value) { - return value; - } - } -};
\ No newline at end of file diff --git a/modern/src/reports/ChartReportPage.js b/modern/src/reports/ChartReportPage.js index 19ec9c12..21c069ca 100644 --- a/modern/src/reports/ChartReportPage.js +++ b/modern/src/reports/ChartReportPage.js @@ -4,7 +4,7 @@ import ReportFilter from './ReportFilter'; import ReportLayoutPage from './ReportLayoutPage'; import { useAttributePreference } from '../common/preferences'; import { formatDate } from '../common/formatter'; -import { getConverter } from '../common/converter'; +import { speedConverter } from '../common/converter'; import {LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts'; const ReportFilterForm = ({ setItems }) => { @@ -16,17 +16,18 @@ const ReportFilterForm = ({ setItems }) => { const response = await fetch(`/api/reports/route?${query.toString()}`, { headers }); if (response.ok) { - const data = await response.json(); + const positions = await response.json(); - let formattedData = data.map(obj => { - return Object.assign( - obj, - {speed: Number(getConverter('speed')(obj.speed, speedUnit))}, - {fixTime: formatDate(obj.fixTime)} - ); + let formattedPositions = positions.map(position => { + return { + speed:Number(speedConverter(position.speed, speedUnit)), + altitude:position.altitude, + accuracy:position.accuracy, + fixTime:formatDate(position.fixTime) + } }); - setItems(formattedData); + setItems(formattedPositions); } } |