Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/v0.11.1 #1564

Merged
merged 17 commits into from
Sep 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: make widget plot work with missing data points (#1559)
  • Loading branch information
srikanthccv committed Sep 12, 2022
commit 0ccd7777bfc7bd530c88a43d2979b2e77aaacfa1
27 changes: 25 additions & 2 deletions frontend/src/lib/getChartData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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),
};
});
},
Expand Down