From 34ec9a62ac0b65665f15f6e80729495e2558547f Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Tue, 24 Nov 2020 14:26:26 +0530 Subject: Refactoring and Improvements in chart report --- modern/src/common/chartTypes.js | 7 +++++++ modern/src/common/formatter.js | 25 ++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 modern/src/common/chartTypes.js (limited to 'modern/src/common') diff --git a/modern/src/common/chartTypes.js b/modern/src/common/chartTypes.js new file mode 100644 index 00000000..fa868a96 --- /dev/null +++ b/modern/src/common/chartTypes.js @@ -0,0 +1,7 @@ +import t from '../common/localization'; + +export const chartTypes = [ + { id: 'speed', name: t('positionSpeed') }, + { id: 'accuracy', name: t('positionAccuracy') }, + { id: 'altitude', name: t('positionAltitude') }, +]; diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js index 8ef00400..b2f305a0 100644 --- a/modern/src/common/formatter.js +++ b/modern/src/common/formatter.js @@ -9,7 +9,7 @@ export const formatPosition = (value, key) => { case 'fixTime': case 'deviceTime': case 'serverTime': - return moment(value).format('YYYY-MM-DD HH:mm'); + return moment(value).format('LLL'); case 'latitude': case 'longitude': return value.toFixed(5); @@ -80,3 +80,26 @@ export const formatVolume = (value, unit) => { export const formatHours = (value) => { return moment.duration(value).humanize(); }; + +const speedConverter = (value, unit) => { + switch (unit) { + case 'kmh': + return (value * 1.852).toFixed(2); + case 'mph': + return (value * 1.15078).toFixed(2); + case 'kn': + default: + return (value * 1).toFixed(2); + } +}; + +export const getConverter = (key) => { + switch (key) { + case 'speed': + return speedConverter; + default: + return function (value) { + return value; + } + } +}; -- cgit v1.2.3