Skip to content

Commit

Permalink
Merge pull request #67 from newrelic/kav/fixTimelineWidgetGaps
Browse files Browse the repository at this point in the history
fix: status timeline widget gaps #58
  • Loading branch information
Kav91 authored Jul 14, 2024
2 parents 0452f18 + 205e030 commit ba07099
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions visualizations/status-timeline-widget/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ export const buildOrderedData = (data, nrqlQuery, thresholds) => {

if (metricName) {
const value = d?.data?.[0]?.[metricName] || 0;

const y = d.metadata.groups[1].value;
const x = d.metadata.groups[2].value;
xLabels.push(x);
Expand All @@ -206,40 +205,28 @@ export const buildOrderedData = (data, nrqlQuery, thresholds) => {

xLabels = [...new Set(xLabels)];

// allow additional sorting for hourOf and dateOf
if (query) {
if (query.includes('hourOf(')) {
xLabels = xLabels.sort((a, b) => a.split(':')[0] - b.split(':')[0]);
xLabels.sort((a, b) => {
const hourA = parseInt(a.split(':')[0], 10);
const hourB = parseInt(b.split(':')[0], 10);
return hourA - hourB;
});
} else if (query.includes('dateOf(')) {
xLabels = xLabels.sort(
(a, b) => new Date(a).getTime() - new Date(b).getTime()
);
xLabels.sort((a, b) => new Date(a) - new Date(b));
}
}

const orderedHeatMapData = {};
Object.keys(unorderedHeatMapData)
.sort()
.forEach(key => {
orderedHeatMapData[key] = unorderedHeatMapData[key];
});

const heatmapData = [];
const yLabels = [];

Object.keys(orderedHeatMapData).forEach(key => {
yLabels.push(key);
const metricData = orderedHeatMapData[key];
const dataArr = [];
xLabels.forEach(label => {
if (label in metricData) {
dataArr.push(metricData[label]);
} else {
dataArr.push(0);
}
const metricData = unorderedHeatMapData[key];
orderedHeatMapData[key] = {};
xLabels.forEach(label => {
orderedHeatMapData[key][label] = label in metricData ? metricData[label] : 0;
});
});
heatmapData.push(dataArr);
});

return { orderedData: orderedHeatMapData, xLabels };
};
Expand Down

0 comments on commit ba07099

Please sign in to comment.