Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

fix live chart bar width problem #116

Merged
merged 3 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Jack Mazanec
Mihir Soni
Chris Swierczewski
Yaliang Wu
Yizhe Liu
Tyler Ohlsen
Hanguang Zhang
Jing Zhang
Pavani Baddepudi
Expand Down
80 changes: 60 additions & 20 deletions public/pages/utils/anomalyResultUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const sampleMaxAnomalyGrade = (anomalies: any[]): any[] => {
export const prepareDataForChart = (
data: any[],
dateRange: DateRange,
interval?: number,
interval: number = 1,
getFloorPlotTime?: any
) => {
if (!data || data.length === 0) {
Expand All @@ -124,32 +124,72 @@ export const prepareDataForChart = (
if (anomalies.length > MAX_DATA_POINTS) {
anomalies = sampleMaxAnomalyGrade(anomalies);
}

anomalies.push({
startTime: dateRange.startDate,
endTime: dateRange.startDate,
plotTime: interval
? dateRange.startDate - MIN_IN_MILLI_SECS * interval
: dateRange.startDate,
confidence: null,
anomalyGrade: null,
});
anomalies.unshift({
startTime: dateRange.endDate,
endTime: dateRange.endDate,
plotTime: interval
? dateRange.endDate + MIN_IN_MILLI_SECS * interval
: dateRange.endDate,
confidence: null,
anomalyGrade: null,
});
if (getFloorPlotTime) {
// we need to get floor plot time for bar chart
anomalies = anomalies.map(anomaly => {
return {
...anomaly,
plotTime: getFloorPlotTime(anomaly.plotTime),
};
});
let startTime =
anomalies.length > 0
? anomalies[anomalies.length - 1].plotTime
: getFloorPlotTime(dateRange.startDate);
let endTime =
anomalies.length > 0
? anomalies[0].plotTime
: getFloorPlotTime(dateRange.endDate);

while (endTime < dateRange.endDate) {
// make sure the end of plot time is big enough to cover NOW annotation, which is at dateRange.endDate
endTime += MIN_IN_MILLI_SECS * interval;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comment saying why we need this, such as: "make sure the end of plot time is big enough to cover NOW annotation, which is at dateRange.endDate"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

}
if (anomalies.length === 0) {
for (
let time = endTime;
time > startTime;
time -= MIN_IN_MILLI_SECS * interval
) {
anomalies.push({
startTime: time,
endTime: time,
plotTime: time,
confidence: null,
anomalyGrade: null,
});
}
}

anomalies.push({
startTime: dateRange.startDate,
endTime: dateRange.startDate,
plotTime: startTime - MIN_IN_MILLI_SECS * interval,
confidence: null,
anomalyGrade: null,
});
anomalies.unshift({
startTime: dateRange.endDate,
endTime: dateRange.endDate,
plotTime: endTime,
confidence: null,
anomalyGrade: null,
});
} else {
anomalies.push({
startTime: dateRange.startDate,
endTime: dateRange.startDate,
plotTime: dateRange.startDate,
confidence: null,
anomalyGrade: null,
});
anomalies.unshift({
startTime: dateRange.endDate,
endTime: dateRange.endDate,
plotTime: dateRange.endDate,
confidence: null,
anomalyGrade: null,
});
yizheliu-amazon marked this conversation as resolved.
Show resolved Hide resolved
}
return anomalies;
};
Expand Down