2021-05-21 15:35:33 +00:00
|
|
|
import React, { useMemo } from "react"
|
2021-05-15 16:05:13 +00:00
|
|
|
import BoxFull from "../base/BoxFull"
|
2021-05-17 15:05:19 +00:00
|
|
|
import ReactWordcloud from "@steffo/nest-react-wordcloud"
|
2021-05-20 09:39:40 +00:00
|
|
|
import Style from "./BoxWordcloud.module.css"
|
2021-05-15 16:05:13 +00:00
|
|
|
|
|
|
|
|
2021-05-16 21:14:28 +00:00
|
|
|
/**
|
2021-05-21 15:35:33 +00:00
|
|
|
* A {@link BoxFull} which displays a wordcloud.
|
2021-05-16 21:14:28 +00:00
|
|
|
*
|
|
|
|
* @param words - A list of word objects, made of a string "text" and a number "value"
|
2021-05-21 15:35:33 +00:00
|
|
|
* @param options - Additional options to pass to {@link ReactWordcloud}.
|
2021-05-16 21:14:28 +00:00
|
|
|
* @param props - Additional props to pass to the box.
|
|
|
|
* @returns {JSX.Element}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2021-05-21 15:35:33 +00:00
|
|
|
export default function BoxWordcloud({ words, callbacks = {}, ...props }) {
|
|
|
|
const wordcloud = useMemo(
|
|
|
|
() => (
|
|
|
|
<ReactWordcloud
|
|
|
|
options={{
|
|
|
|
colors: [
|
|
|
|
"var(--fg-primary)",
|
|
|
|
],
|
|
|
|
fontFamily: "Bree Serif",
|
|
|
|
fontSizes: [8, 64],
|
|
|
|
size: undefined,
|
|
|
|
deterministic: true,
|
|
|
|
rotations: 0,
|
|
|
|
rotationAngles: [0, 0],
|
|
|
|
enableOptimizations: true,
|
|
|
|
enableTooltip: false,
|
|
|
|
}}
|
|
|
|
words={words}
|
|
|
|
callbacks={callbacks}
|
|
|
|
/>
|
|
|
|
),
|
2021-05-21 17:52:56 +00:00
|
|
|
[words],
|
2021-05-21 15:35:33 +00:00
|
|
|
)
|
|
|
|
|
2021-05-15 16:05:13 +00:00
|
|
|
return (
|
2021-05-20 09:39:40 +00:00
|
|
|
<BoxFull {...props}>
|
|
|
|
<div className={Style.WordcloudContainer}>
|
2021-05-21 15:35:33 +00:00
|
|
|
{wordcloud}
|
2021-05-15 16:05:13 +00:00
|
|
|
</div>
|
|
|
|
</BoxFull>
|
|
|
|
)
|
|
|
|
}
|