From e60e4065f147feaa303112815ec31273a53c3a66 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Mon, 16 Dec 2024 17:22:15 +0000 Subject: [PATCH 1/5] Toggle text entities --- .../AssistantNEResult.jsx | 163 +++++++++--------- src/redux/sagas/assistantSaga.jsx | 1 + 2 files changed, 86 insertions(+), 78 deletions(-) diff --git a/src/components/NavItems/Assistant/AssistantCheckResults/AssistantNEResult.jsx b/src/components/NavItems/Assistant/AssistantCheckResults/AssistantNEResult.jsx index c26a03cba..44a9d6116 100644 --- a/src/components/NavItems/Assistant/AssistantCheckResults/AssistantNEResult.jsx +++ b/src/components/NavItems/Assistant/AssistantCheckResults/AssistantNEResult.jsx @@ -2,6 +2,8 @@ import React, { useState } from "react"; import { useSelector } from "react-redux"; import Box from "@mui/material/Box"; +import Button from "@mui/material/Button"; +import ButtonGroup from "@mui/material/ButtonGroup"; import Card from "@mui/material/Card"; import { CardHeader, Grid2, ListItemButton } from "@mui/material"; import CardContent from "@mui/material/CardContent"; @@ -31,11 +33,22 @@ const AssistantNEResult = () => { const neLoading = useSelector((state) => state.assistant.neLoading); const [selectedIndex, setSelectedIndex] = useState(null); - //console.log("neResult ", neResult); - //console.log("neResultCount ", neResultCount); const handleCollapse = (index) => { index === selectedIndex ? setSelectedIndex(null) : setSelectedIndex(index); }; + const [visibleCategories, setVisibleCategories] = useState( + neResult.reduce((acc, key) => { + acc[key.category.toLowerCase()] = false; + return acc; + }, {}), + ); + + const toggleCategory = (category) => { + setVisibleCategories({ + ...visibleCategories, + [category]: !visibleCategories[category], + }); + }; function getCallback(callback) { return function (word, event) { @@ -61,16 +74,16 @@ const AssistantNEResult = () => { const callbacks = { getWordColor: (word) => { - switch (word.category) { - case "Person": + switch (word.category.toLowerCase()) { + case "person": return "blue"; - case "Location": + case "location": return "red"; - case "Organization": + case "organization": return "green"; - case "Hashtag": + case "hashtag": return "orange"; - case "UserId": + case "userid": return "purple"; default: return "black"; @@ -84,20 +97,36 @@ const AssistantNEResult = () => { onWordMouseOver: getCallback("onWordMouseOver"), }; - function getWordColor(tag) { - switch (tag.category) { - case "Person": - return "blue"; - case "Location": - return "red"; - case "Organization": - return "green"; - case "Hashtag": - return "orange"; - case "UserId": - return "purple"; + function getWordColor(tag, active = true) { + if (active) { + switch (tag.category.toLowerCase()) { + case "person": + return "blue"; + case "location": + return "red"; + case "organization": + return "green"; + case "hashtag": + return "orange"; + case "userid": + return "purple"; + default: + return "black"; + } + } + switch (tag.category.toLowerCase()) { + case "person": + return "darkblue"; + case "location": + return "darkred"; + case "organization": + return "darkgreen"; + case "hashtag": + return "darkorange"; + case "userid": + return "darkpurple"; default: - return "black"; + return "gray"; } } @@ -106,6 +135,7 @@ const AssistantNEResult = () => { verticalAlign: "middle", display: "inline-block", }; + const customRenderer = (tag, size, color) => { const { className, style, ...props } = tag.props || {}; const fontSize = size + "px"; @@ -113,19 +143,31 @@ const AssistantNEResult = () => { const tagStyle = { ...styles, color: getWordColor(tag), + textDecorationColor: getWordColor(tag), + visibility: visibleCategories[tag.category.toLowerCase()] + ? "hidden" + : "visible", fontSize, ...style, }; + console.log(tag.value, tag.category, tagStyle); let tagClassName = "tag-cloud-tag"; if (className) { tagClassName += " " + className; } return ( - + {tag.value} - + ); }; @@ -138,64 +180,29 @@ const AssistantNEResult = () => { /> {neLoading && } + + {neResult.map((tag, index) => ( + + ))} + - - - {neResult.map((value, index) => ( - - handleCollapse(index)} - > - - - {value["category"]} - - - } - /> - {index === selectedIndex ? ( - - ) : ( - - )} - - - - {value["words"].map((v, k) => ( - - - - {v.value}   - - ({v.count}) - - - ))} - - - - ))} - - - - - - - {/**/} + Date: Tue, 17 Dec 2024 11:57:05 +0000 Subject: [PATCH 2/5] added a key for the buttons --- .../Assistant/AssistantCheckResults/AssistantNEResult.jsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/components/NavItems/Assistant/AssistantCheckResults/AssistantNEResult.jsx b/src/components/NavItems/Assistant/AssistantCheckResults/AssistantNEResult.jsx index 44a9d6116..7207778c9 100644 --- a/src/components/NavItems/Assistant/AssistantCheckResults/AssistantNEResult.jsx +++ b/src/components/NavItems/Assistant/AssistantCheckResults/AssistantNEResult.jsx @@ -13,9 +13,6 @@ import { ExpandLess, ExpandMore } from "@mui/icons-material"; import LinearProgress from "@mui/material/LinearProgress"; import Typography from "@mui/material/Typography"; import Link from "@mui/material/Link"; -import ListItem from "@mui/material/ListItem"; -import List from "@mui/material/List"; -import ListItemText from "@mui/material/ListItemText"; //import ReactWordcloud from "react-wordcloud"; import { TagCloud } from "react-tagcloud"; import { select } from "d3-selection"; @@ -151,7 +148,6 @@ const AssistantNEResult = () => { ...style, }; - console.log(tag.value, tag.category, tagStyle); let tagClassName = "tag-cloud-tag"; if (className) { tagClassName += " " + className; @@ -191,6 +187,7 @@ const AssistantNEResult = () => { !visibleCategories[tag.category.toLowerCase()], ), }} + key={tag.category} onClick={() => toggleCategory(tag.category.toLowerCase())} > {tag.category} From e254323bae52d9c072a0d3369ffe76ba092f421b Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 6 Jan 2025 13:49:41 +0000 Subject: [PATCH 3/5] Wordcloud new colours with overlay when hidden --- .../AssistantNEResult.jsx | 93 ++++--------------- .../Shared/MaterialUiStyles/useMyStyles.jsx | 25 +++++ 2 files changed, 44 insertions(+), 74 deletions(-) diff --git a/src/components/NavItems/Assistant/AssistantCheckResults/AssistantNEResult.jsx b/src/components/NavItems/Assistant/AssistantCheckResults/AssistantNEResult.jsx index d369a2ff6..5a0bd9956 100644 --- a/src/components/NavItems/Assistant/AssistantCheckResults/AssistantNEResult.jsx +++ b/src/components/NavItems/Assistant/AssistantCheckResults/AssistantNEResult.jsx @@ -56,83 +56,26 @@ const AssistantNEResult = () => { }); }; - function getCallback(callback) { - return function (word, event) { - const isActive = callback !== "onWordMouseOut"; - const element = event.target; - const text = select(element); - text - .on("click", () => { - if (isActive) { - window.open(`https://google.com/search?q=${word.text}`, "_blank"); - } - }) - .transition() - .attr("text-decoration", isActive ? "underline" : "none"); - }; - } - - const options = { - rotations: 1, - rotationAngles: [0], - fontSizes: [15, 60], - }; - - const callbacks = { - getWordColor: (word) => { - switch (word.category.toLowerCase()) { - case "person": - return "blue"; - case "location": - return "red"; - case "organization": - return "green"; - case "hashtag": - return "orange"; - case "userid": - return "purple"; - default: - return "black"; - } - }, - getWordTooltip: (word) => { - return word.text + " (" + word.category + "): " + word.value; - }, - onWordClick: getCallback("onWordClick"), - onWordMouseOut: getCallback("onWordMouseOut"), - onWordMouseOver: getCallback("onWordMouseOver"), - }; - - function getWordColor(tag, active = true) { - if (active) { - switch (tag.category.toLowerCase()) { - case "person": - return "blue"; - case "location": - return "red"; - case "organization": - return "green"; - case "hashtag": - return "orange"; - case "userid": - return "purple"; - default: - return "black"; - } - } + function getWordColor(tag) { switch (tag.category.toLowerCase()) { case "person": - return "darkblue"; + return "#648FFF"; + // return "blue"; case "location": - return "darkred"; + return "#DC267F"; + // return "red"; case "organization": - return "darkgreen"; + return "#FFB000"; + // return "green"; case "hashtag": - return "darkorange"; + return "#FE6100"; + // return "orange"; case "userid": - return "darkpurple"; + return "#785EF0"; + // return "purple"; default: - return "gray"; + return "black"; + // return "black"; } } @@ -203,13 +146,15 @@ const AssistantNEResult = () => { {neResult.map((tag, index) => (