Optimize the display of search totals by year (#228)

This commit is contained in:
zxg 2022-12-12 23:00:31 +08:00 committed by GitHub
parent 1a51ae5d23
commit becceb545a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View file

@ -59,11 +59,14 @@ function calculateSavedTime(times) {
}
}
function renderSearchTimes(length = 0) {
function renderSearchTimes(length = 0, searchTime) {
let searchTimes = document.querySelector(".search-time");
let frequency = searchTimes.querySelectorAll("b");
frequency[0].textContent = `${length}`;
frequency[1].textContent = calculateSavedTime(length);
if(searchTime) {
frequency[1].textContent = `${searchTime}`;
}
frequency[2].textContent = calculateSavedTime(length);
}
function renderHeatmap(data, now, yearAgo) {
@ -200,7 +203,7 @@ function renderTopCratesChart(topCratesObj) {
}
async function renderCharts(now, yearAgo) {
async function renderCharts(now, yearAgo, searchTime) {
const { timeline } = await Statistics.load();
const data = timeline.filter(([time]) => {
@ -244,7 +247,7 @@ async function renderCharts(now, yearAgo) {
}
});
renderSearchTimes(data.length);
renderSearchTimes(data.length, searchTime);
renderHeatmap(heatMapData, now, yearAgo);
renderHistogram(weeksObj, datesObj, hoursObj)
renderSearchStats(typeDataObj, typeTotal);
@ -277,14 +280,14 @@ async function renderYearList() {
const time = moment(e.target.innerText);
const now = time.endOf('year').valueOf();
const yearAgo = time.startOf('year').valueOf();
await renderCharts(now, yearAgo);
await renderCharts(now, yearAgo, moment(yearAgo).format('YYYY'));
}
});
}
(async () => {
await tryMigrateLegacyStatisticsToTimeline();
const now = moment().valueOf();
const yearAgo = moment().startOf('day').subtract(1, 'year').valueOf();
await renderCharts(now, yearAgo);

View file

@ -15,7 +15,7 @@
<div class="chart-heatmap"></div>
</div>
<div class="search-time" style="text-align: center;font-size: 20px;">
<b>0</b> searches in total since the first day, approximately saved <b>0 seconds</b>.
<b>0</b> searches in total in <b>the last year</b>, approximately saved <b>0 seconds</b>.
<b aria-label="We consider one search save 5 seconds in average, just an estimated value." data-balloon-pos="up" data-balloon-length="large" style="vertical-align: middle" class="tooltip-color">
<img src="../assets/info.svg" alt="info">
</b>