mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-14 15:47:12 +00:00
Optimize the display of search totals by year (#228)
This commit is contained in:
parent
1a51ae5d23
commit
becceb545a
2 changed files with 10 additions and 7 deletions
|
@ -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);
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue