Skip to content

Commit 15e477b

Browse files
authored
Merge pull request #153 from chnm/feature/architecture
This PR fixes a display issue for the word cloud causes
2 parents f1b598c + 3d1341e commit 15e477b

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

bom-website/assets/visualizations/wordcloud/wordcloud.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ export default class WordCloudChart extends Visualization {
2323
const causes = d3
2424
.rollups(
2525
this.data.causes,
26-
(v) => d3.sum(v, (d) => d.count),
26+
(v) => ({
27+
size: d3.sum(v, (d) => d.count),
28+
count: d3.sum(v, (d) => d.count), // Ensure count is correctly calculated
29+
}),
2730
(d) => d.death,
2831
)
29-
.map(([text, size]) => ({ text, size }));
32+
.map(([text, { size, count }]) => ({ text, size, count }));
3033

3134
const wordcloud = WordCloud(causes, {
3235
size: (group) => {
@@ -66,8 +69,7 @@ function WordCloud(
6669
.rollups(words, size, (w) => w)
6770
.sort(([, a], [, b]) => d3.descending(a, b))
6871
.slice(0, maxWords)
69-
.map(([key, size]) => ({ text: word(key), size }));
70-
72+
.map(([key, size]) => ({ text: word(key), size, count: key.count })); // Ensure count is included
7173

7274
const svg = d3
7375
.create("svg")
@@ -109,7 +111,7 @@ function WordCloud(
109111
textElements
110112
.on("mouseover", function (event, d) {
111113
infoText.html(
112-
`Cause of death: <strong>${d.text}</strong>, Count: <strong>${d.size}</strong>`,
114+
`Cause of death: <strong>${d.text}</strong>, Total causes: <strong>${d.count}</strong>`,
113115
);
114116
})
115117
.on("mouseout", function () {

bom-website/package.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
{
2+
"author": "Roy Rosenzweig Center for History and New Media",
3+
"description": "Website and visualizations for the Death by Numbers project at RRCHNM.",
4+
"name": "bom",
5+
"private": true,
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/chnm/bom.git"
9+
},
210
"dependencies": {
311
"@alpinejs/collapse": "^3.14.1",
412
"@observablehq/plot": "^0.6.16",
513
"alpinejs": "^3.14.1",
614
"d3": "^7.9.0",
715
"d3-cloud": "^1.2.5",
816
"d3-scale-chromatic": "^3.1.0"
9-
}
17+
},
18+
"devDependencies": {
19+
"autoprefixer": "^10.3.1",
20+
"browser-sync": "^2.27.7",
21+
"css-loader": "^5.2.7",
22+
"eslint": "^7.30.0",
23+
"eslint-config-airbnb-base": "^14.2.1",
24+
"eslint-plugin-import": "^2.23.4",
25+
"style-loader": "^3.1.0"
26+
},
27+
"version": "1.0.0"
1028
}

0 commit comments

Comments
 (0)