Skip to content

Commit d79d693

Browse files
author
kim
committed
feat: change wordcloud package
1 parent 638dd90 commit d79d693

File tree

4 files changed

+329
-161
lines changed

4 files changed

+329
-161
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
"@tanstack/react-query": "4.40.1",
2525
"@tanstack/react-query-devtools": "4.40.1",
2626
"@uiw/react-codemirror": "4.23.13",
27+
"@visx/scale": "3.12.0",
28+
"@visx/wordcloud": "3.12.0",
2729
"date-fns": "4.1.0",
2830
"file-saver": "2.0.5",
2931
"i18next": "24.2.3",
@@ -38,7 +40,6 @@
3840
"react-markdown": "9.1.0",
3941
"react-mde": "12.0.8",
4042
"react-toastify": "11.0.5",
41-
"react-wordcloud": "1.2.7",
4243
"remark-breaks": "4.0.0",
4344
"remark-gfm": "4.0.1",
4445
"stopword": "3.1.5"

src/modules/analytics/WordCloud.tsx

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
import type { MinMaxPair } from 'react-wordcloud';
2-
import ReactWordcloud from 'react-wordcloud';
3-
41
import { Dialog } from '@mui/material';
52

3+
import { scaleLog } from '@visx/scale';
4+
import { Wordcloud as VWordCloud } from '@visx/wordcloud';
5+
66
import { ANALYTICS_WORDS_CLOUD_MODAL_ID } from '@/config/selectors';
77

8+
type WordData = {
9+
text: string;
10+
value: number;
11+
};
12+
13+
const colors = ['#143059', '#2F6B9A', '#82a6c2'];
14+
const fixedValueGenerator = () => 2.5;
15+
816
type Props = {
917
wordCounts: { [key: string]: number };
1018
open: boolean;
@@ -20,15 +28,45 @@ function WordCloud({
2028
value,
2129
}));
2230

23-
const options = {
24-
fontSizes: [20, 50] as MinMaxPair,
25-
rotations: 2.5,
26-
rotationAngles: [0, 45] as [number, number],
27-
};
31+
const fontScale = scaleLog({
32+
domain: [
33+
Math.min(...words.map((w) => w.value)),
34+
Math.max(...words.map((w) => w.value)),
35+
],
36+
range: [20, 50],
37+
});
38+
const fontSizeSetter = (datum: WordData) => fontScale(datum.value);
2839

2940
return (
3041
<Dialog open={open} onClose={onClose} id={ANALYTICS_WORDS_CLOUD_MODAL_ID}>
31-
<ReactWordcloud words={words} options={options} size={[600, 400]} />
42+
<div className="wordcloud">
43+
<VWordCloud
44+
words={words}
45+
width={600}
46+
height={400}
47+
fontSize={fontSizeSetter}
48+
font={'Nunito'}
49+
padding={2}
50+
spiral={'archimedean'}
51+
rotate={0}
52+
random={fixedValueGenerator}
53+
>
54+
{(cloudWords) =>
55+
cloudWords.map((w, i) => (
56+
<text
57+
key={w.text}
58+
color={colors[i % colors.length]}
59+
textAnchor={'middle'}
60+
transform={`translate(${w.x}, ${w.y}) rotate(${w.rotate})`}
61+
fontSize={w.size}
62+
fontFamily={w.font}
63+
>
64+
{w.text}
65+
</text>
66+
))
67+
}
68+
</VWordCloud>
69+
</div>
3270
</Dialog>
3371
);
3472
}

src/modules/common/useSendMessage.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useCallback } from 'react';
22

3+
import { AppActionsType } from '@/config/appActions';
34
import { AppDataTypes } from '@/config/appData';
45
import { mutations } from '@/config/queryClient';
56

@@ -10,6 +11,7 @@ import { mutations } from '@/config/queryClient';
1011
export const useSendMessage = () => {
1112
const { mutateAsync: postAppDataAsync, isLoading } =
1213
mutations.usePostAppData();
14+
const { mutateAsync: postAppActionAsync } = mutations.usePostAppAction();
1315

1416
const sendMessage = useCallback(
1517
async (newUserComment: string) => {
@@ -21,9 +23,14 @@ export const useSendMessage = () => {
2123
type: AppDataTypes.UserComment,
2224
});
2325

26+
await postAppActionAsync({
27+
type: AppActionsType.Reply,
28+
data: { content: newUserComment },
29+
});
30+
2431
return userMessage;
2532
},
26-
[postAppDataAsync],
33+
[postAppDataAsync, postAppActionAsync],
2734
);
2835

2936
return { sendMessage, isLoading };

0 commit comments

Comments
 (0)