fix: make widget plot work with missing data points (#1559)

This commit is contained in:
Srikanth Chekuri 2022-09-12 16:11:55 +05:30 committed by GitHub
parent ac86d840f9
commit 0ccd7777bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,16 @@ import convertIntoEpoc from './covertIntoEpoc';
import { colors } from './getRandomColor';
const getChartData = ({ queryData }: GetChartDataProps): ChartData => {
const uniqueTimeLabels = new Set<number>();
queryData.forEach((data) => {
data.queryData.forEach((query) => {
query.values.forEach((value) => {
uniqueTimeLabels.add(value[0]);
});
});
});
const labels = Array.from(uniqueTimeLabels).sort((a, b) => a - b);
const response = queryData.map(
({ queryData, query: queryG, legend: legendG }) => {
return queryData.map((e) => {
@ -22,11 +32,24 @@ const getChartData = ({ queryData }: GetChartDataProps): ChartData => {
second: Number(parseFloat(second)),
};
});
// Fill the missing data with null
const filledDataValues = Array.from(labels).map((e) => {
const td1 = new Date(parseInt(convertIntoEpoc(e * 1000), 10));
const data = dataValue.find((e1) => {
return e1.first.getTime() === td1.getTime();
});
return (
data || {
first: new Date(parseInt(convertIntoEpoc(e * 1000), 10)),
second: null,
}
);
});
return {
label: labelNames !== 'undefined' ? labelNames : '',
first: dataValue.map((e) => e.first),
second: dataValue.map((e) => e.second),
first: filledDataValues.map((e) => e.first),
second: filledDataValues.map((e) => e.second),
};
});
},