feat: add fishing activity timeline
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
---
|
||||
import type { Catch } from "../lib/api";
|
||||
const { catches } = Astro.props as { catches: Catch[] };
|
||||
const now = Date.now();
|
||||
const step = 12 * 60 * 60 * 1000;
|
||||
const buckets = Array.from({ length: 6 }, (_, index) => ({ index, count: 0 }));
|
||||
for (const item of catches) {
|
||||
const timestamp = new Date(item.caught_at ?? item.reported_at).getTime();
|
||||
const age = Math.floor((now - timestamp) / step);
|
||||
if (age >= 0 && age < buckets.length) buckets[buckets.length - 1 - age].count += 1;
|
||||
}
|
||||
const max = Math.max(1, ...buckets.map(bucket => bucket.count));
|
||||
---
|
||||
<section class="activity-timeline" aria-labelledby="timeline-title">
|
||||
<header><div><span class="overline">Последние 72 часа</span><h2 id="timeline-title">Леска активности</h2></div><p>По показанным ниже уловам · шаг 12 часов</p></header>
|
||||
<div class="timeline-chart" role="img" aria-label={`Распределение ${catches.length} показанных уловов за последние 72 часа`}>
|
||||
{buckets.map((bucket, index) => <div class="timeline-slot"><span class="timeline-line" style={`--height:${Math.max(8, bucket.count / max * 100)}%`}><i></i></span><strong>{bucket.count}</strong><small>{index === 0 ? "−72 ч" : index === 5 ? "сейчас" : `−${(5-index)*12} ч`}</small></div>)}
|
||||
</div>
|
||||
</section>
|
||||
Reference in New Issue
Block a user