Move util function to top of file
This commit is contained in:
parent
c3a51cbfe0
commit
c41aa73694
@ -21,6 +21,16 @@ interface ChartProps {
|
|||||||
dataCollections?: any[],
|
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) {
|
export default function Chart({ data, title, color, unit, dataCollections }: ChartProps) {
|
||||||
var renderData = [];
|
var renderData = [];
|
||||||
|
|
||||||
@ -28,13 +38,13 @@ export default function Chart({ data, title, color, unit, dataCollections }: Cha
|
|||||||
renderData.push({
|
renderData.push({
|
||||||
name: title,
|
name: title,
|
||||||
color: color,
|
color: color,
|
||||||
data: createGraphDatasetFromObject(data)
|
data: createGraphDataset(data)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
dataCollections.forEach(collection => {
|
dataCollections.forEach(collection => {
|
||||||
renderData.push(
|
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: [],
|
data: [],
|
||||||
title: '',
|
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;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user