Skip to content

Commit

Permalink
player stats stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed Mar 4, 2024
1 parent 800a660 commit 6372bcb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
25 changes: 16 additions & 9 deletions src/components/PlayerStats.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@
---

<canvas class="player-stats" width="500" height="300"></canvas>
<div class="bg-quardiary-darker p-8 rounded-xl max-w-paragraph">
<canvas class="player-stats"></canvas>
</div>

<script>
import { Chart } from 'chart.js/auto';

const data = await (await fetch(
'https://globed.dankmeme.dev/public/players?period=hour',
{
mode: 'no-cors'
}
)).json();
const data = (await (await fetch('https://globed.dankmeme.dev/public/players?period=hour')).json()).data as [{
log_time: number,
count: number,
}];
document.querySelectorAll('.player-stats').forEach(canvas => {
const chart = new Chart(canvas as HTMLCanvasElement, {
type: 'line',
data: data,
data: {
labels: data.map(row => new Date(row.log_time).toDateString()),
datasets: [
{
label: 'Players',
data: data.map(row => row.count),
}
]
}
});
});

</script>
4 changes: 3 additions & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ const screenshots = (await Astro.glob('../images/screenshot-*.png')).map(file =>
</div>
</Content>

<!-- <PlayerStats/> -->
<PlayerStats />

<div class="h-20" />

<Donate />

Expand Down

0 comments on commit 6372bcb

Please sign in to comment.