From c41aa7369496b8f295c970061f7b4acc4202eeb7 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Wed, 25 Nov 2020 00:17:35 -0800 Subject: [PATCH] Move util function to top of file --- web/pages/components/chart.tsx | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/web/pages/components/chart.tsx b/web/pages/components/chart.tsx index 6f74277b2..98acb55d4 100644 --- a/web/pages/components/chart.tsx +++ b/web/pages/components/chart.tsx @@ -21,6 +21,16 @@ interface ChartProps { dataCollections?: any[], } +function createGraphDataset(dataArray) { + var dataValues = {}; + dataArray.forEach(item => { + const dateObject = new Date(item.time); + const dateString = dateObject.getFullYear() + '-' + dateObject.getMonth() + '-' + dateObject.getDay() + ' ' + dateObject.getHours() + ':' + dateObject.getMinutes(); + dataValues[dateString] = item.value; + }) + return dataValues; +} + export default function Chart({ data, title, color, unit, dataCollections }: ChartProps) { var renderData = []; @@ -28,13 +38,13 @@ export default function Chart({ data, title, color, unit, dataCollections }: Cha renderData.push({ name: title, color: color, - data: createGraphDatasetFromObject(data) + data: createGraphDataset(data) }); } dataCollections.forEach(collection => { renderData.push( - {name: collection.name, data: createGraphDatasetFromObject(collection.data), color: collection.color} + {name: collection.name, data: createGraphDataset(collection.data), color: collection.color} ) }); @@ -57,13 +67,3 @@ Chart.defaultProps = { data: [], title: '', }; - -function createGraphDatasetFromObject(dataArray) { - var dataValues = {}; - dataArray.forEach(item => { - const dateObject = new Date(item.time); - const dateString = dateObject.getFullYear() + '-' + dateObject.getMonth() + '-' + dateObject.getDay() + ' ' + dateObject.getHours() + ':' + dateObject.getMinutes(); - dataValues[dateString] = item.value; - }) - return dataValues; -} \ No newline at end of file