mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-01 06:52:00 +08:00
fix: make widget plot work with missing data points (#1559)
This commit is contained in:
parent
ac86d840f9
commit
0ccd7777bf
@ -6,6 +6,16 @@ import convertIntoEpoc from './covertIntoEpoc';
|
|||||||
import { colors } from './getRandomColor';
|
import { colors } from './getRandomColor';
|
||||||
|
|
||||||
const getChartData = ({ queryData }: GetChartDataProps): ChartData => {
|
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(
|
const response = queryData.map(
|
||||||
({ queryData, query: queryG, legend: legendG }) => {
|
({ queryData, query: queryG, legend: legendG }) => {
|
||||||
return queryData.map((e) => {
|
return queryData.map((e) => {
|
||||||
@ -22,11 +32,24 @@ const getChartData = ({ queryData }: GetChartDataProps): ChartData => {
|
|||||||
second: Number(parseFloat(second)),
|
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 {
|
return {
|
||||||
label: labelNames !== 'undefined' ? labelNames : '',
|
label: labelNames !== 'undefined' ? labelNames : '',
|
||||||
first: dataValue.map((e) => e.first),
|
first: filledDataValues.map((e) => e.first),
|
||||||
second: dataValue.map((e) => e.second),
|
second: filledDataValues.map((e) => e.second),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user