Skip to content

Commit fbc368e

Browse files
committedDec 8, 2024
changed bubble colors to match topic modeling colors
1 parent aead4f6 commit fbc368e

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed
 

‎app/src/app/components/ui/themesTransition.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const ThemesTransition: React.FC = () => {
6363
<svg
6464
xmlns="http://www.w3.org/2000/svg"
6565
viewBox="0 0 24 24"
66-
fill="currentColor"
66+
fill={theme.color} // can change to "currentcolor" to get pink theme color if multicolor is ugly
6767
className="w-5 h-5 text-pink-300 group-hover:text-pink-500 transition duration-200"
6868
>
6969
<path d="M12 4.248C8.852-1.154 0 .423 0 7.192c0 4.661 5.571 9.427 12 15.808 6.429-6.381 12-11.147 12-15.808 0-6.792-8.875-8.306-12-2.944z" />

‎app/src/app/components/visualizations/p2/bubble-chart.js

+25-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@ import * as d3 from "d3";
33

44
const HorizontalBarChart = () => {
55
const [data, setData] = useState([]);
6+
const [topicsData, setTopicsData] = useState([]);
67

78
useEffect(() => {
89
const fetchData = async () => {
910
try {
11+
// fetch post data
1012
const response = await fetch("/data/consolidated_posts.json");
1113
const json = await response.json();
1214

15+
// fetch topics data
16+
const responseTopics = await fetch(
17+
"/data/topic-modeling/results/topics_NMF_15.json"
18+
);
19+
const topicsJson = await responseTopics.json();
20+
console.log("bubble fetched topics: ", topicsJson);
21+
setTopicsData(topicsJson);
22+
1323
// Parse and aggregate data
1424
const parsedData = Object.entries(json)
1525
.map(([, post]) => ({
@@ -31,10 +41,17 @@ const HorizontalBarChart = () => {
3141
);
3242

3343
setData(
34-
aggregatedData.map(([topic, stats]) => ({
35-
topic,
36-
...stats,
37-
}))
44+
aggregatedData.map(([topic, stats]) => {
45+
// find corresponding topic color from topicsJson
46+
const topicData = topicsJson.find((t) => t.label === topic);
47+
const color = topicData ? topicData.color : "#000000"; // Default to black if no match
48+
49+
return {
50+
topic,
51+
...stats,
52+
color, // Add color to each aggregated data entry
53+
};
54+
})
3855
);
3956
} catch (error) {
4057
console.error("Error fetching data:", error);
@@ -45,6 +62,7 @@ const HorizontalBarChart = () => {
4562
}, []);
4663

4764
const createBubbleChart = (chartData, containerId) => {
65+
console.log("data structure in bubble", data);
4866
d3.select(`#${containerId}`).select("svg").remove();
4967

5068
const margin = { top: 60, right: 300, bottom: 60, left: 100 };
@@ -155,7 +173,8 @@ const HorizontalBarChart = () => {
155173
.attr("cx", (d) => xScale(d.numPosts)) // X-axis is number of posts
156174
.attr("cy", (d) => yScale(d.avgLength)) // Y-axis is average word length
157175
.attr("r", (d) => sizeScale(d.avgSentiment)) // Bubble size is sentiment
158-
.attr("fill", (d) => colorScale(d.topic)) // Color represents topic
176+
// .attr("fill", (d) => colorScale(d.topic)) // Color represents topic
177+
.attr("fill", (d) => d.color)
159178
.attr("opacity", 0.5)
160179
.on("mouseover", (event, d) => {
161180
tooltip.transition().duration(200).style("opacity", 1);
@@ -218,7 +237,7 @@ const HorizontalBarChart = () => {
218237
.attr("cx", 10)
219238
.attr("cy", 20 + i * 20)
220239
.attr("r", 5)
221-
.attr("fill", colorScale(d.topic));
240+
.attr("fill", d.color);
222241

223242
legend
224243
.append("text")

0 commit comments

Comments
 (0)
Please sign in to comment.