Merge pull request #5726 from mempool/mononaut/close-time-rift

Fix time traveling balance charts
This commit is contained in:
softsimon 2025-01-17 10:56:22 +07:00 committed by GitHub
commit 341da85c77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -478,25 +478,30 @@ export class AddressGraphComponent implements OnChanges, OnDestroy {
}
extendSummary(summary) {
let extendedSummary = summary.slice();
const extendedSummary = summary.slice();
// Add a point at today's date to make the graph end at the current time
extendedSummary.unshift({ time: Date.now() / 1000, value: 0 });
extendedSummary.reverse();
let oneHour = 60 * 60;
let maxTime = Date.now() / 1000;
const oneHour = 60 * 60;
// Fill gaps longer than interval
for (let i = 0; i < extendedSummary.length - 1; i++) {
let hours = Math.floor((extendedSummary[i + 1].time - extendedSummary[i].time) / oneHour);
if (extendedSummary[i].time > maxTime) {
extendedSummary[i].time = maxTime - 30;
}
maxTime = extendedSummary[i].time;
const hours = Math.floor((extendedSummary[i].time - extendedSummary[i + 1].time) / oneHour);
if (hours > 1) {
for (let j = 1; j < hours; j++) {
let newTime = extendedSummary[i].time + oneHour * j;
const newTime = extendedSummary[i].time - oneHour * j;
extendedSummary.splice(i + j, 0, { time: newTime, value: 0 });
}
i += hours - 1;
}
}
return extendedSummary.reverse();
return extendedSummary;
}
}