feat: word cloud on stat page

This commit is contained in:
2026-01-27 18:37:42 +00:00
parent ecc1a62d24
commit dda1c1fee8
4 changed files with 166 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ import {
CartesianGrid,
ResponsiveContainer
} from "recharts";
import WordCloud from "../stats/WordCloud";
function PostsPerDay() {
const [data, setData] = useState([]);
@@ -19,7 +20,7 @@ function PostsPerDay() {
axios
.get("http://localhost:5000/stats/posts_per_day")
.then(res => {
setData(res.data);
setData(res.data.filter((item: any) => new Date(item.date) >= new Date("2025-06-01")));
setLoading(false);
})
.catch(err => {
@@ -35,7 +36,7 @@ function PostsPerDay() {
<div>
<h2>Posts per Day</h2>
<ResponsiveContainer width="100%" height={350}>
<ResponsiveContainer width={800} height={350}>
<LineChart data={data}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="date" />
@@ -48,6 +49,8 @@ function PostsPerDay() {
/>
</LineChart>
</ResponsiveContainer>
<WordCloud />
</div>
);
}

View File

@@ -0,0 +1,41 @@
import { ReactWordcloud } from '@cp949/react-wordcloud';
import { useEffect, useState } from 'react';
import axios from "axios";
type BackendWord = {
word: string;
frequency: number;
}
const WordCloud = () => {
const [words, setWords] = useState<{ text: string; value: number }[]>([]);
const [error, setError] = useState<string>('');
useEffect(() => {
axios
.get("http://localhost:5000/stats/word_frequencies")
.then(res => {
const mapped = res.data.map((d: BackendWord) => (
{text: d.word, value: d.frequency}
));
setWords(mapped);
})
.catch(err => {
setError(err);
});
}, [])
return (
<div>
<ReactWordcloud
words={words}
/>
<p>{error}</p>
</div>
);
};
export default WordCloud;