Skip to content

Commit 195f4a4

Browse files
authored
Merge pull request #18 from com-480-data-visualization/fuentes-gendre-genre-scatter
changes
2 parents 401fa52 + b77ff33 commit 195f4a4

1 file changed

Lines changed: 10 additions & 26 deletions

File tree

  • website/content/visualizations/gender-genre-scatter

website/content/visualizations/gender-genre-scatter/index.md

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ tags: ["d3", "visualization"]
55
layout: "simple"
66
---
77

8-
This scatterplot compares average book price and average rating for male and non-male author groups across genres or author nationalities.
8+
This scatterplot compares average book price and average rating for male and female author groups across genres or author nationalities.
99

1010
Each point summarizes one category, making it easier to see whether rating and price patterns differ between gender groups for the same part of the dataset.
1111

12-
Use the group selector and the minimum-books slider to clean up the cloud of points, then hover around to spot the categories that behave a little differently from the rest.
12+
Use the group selector and category filters to clean up the cloud of points, then hover around to spot the categories that behave a little differently from the rest.
1313

1414
<!-- prettier-ignore-start -->
1515
{{< d3 >}}
@@ -46,6 +46,11 @@ const symbolByGender = {
4646
"Male authors": d3.symbolCircle,
4747
"Non-male authors": d3.symbolDiamond,
4848
};
49+
const genderLabels = {
50+
"Male authors": "Male authors",
51+
"Non-male authors": "Female authors",
52+
};
53+
const minimumBooks = 2;
4954

5055
const scatterLayout = scatterRoot.append("div")
5156
.style("display", "grid")
@@ -82,21 +87,6 @@ scatterMode.selectAll("option")
8287
.attr("value", d => d.value)
8388
.text(d => d.label);
8489

85-
const scatterMinWrap = scatterControls.append("label")
86-
.style("display", "grid")
87-
.style("gap", "7px")
88-
.style("font-size", "13px")
89-
.style("font-weight", 650);
90-
const scatterMinLabel = scatterMinWrap.append("span");
91-
const scatterMin = scatterMinWrap.append("input")
92-
.attr("type", "range")
93-
.attr("min", 2)
94-
.attr("max", 50)
95-
.attr("value", 5)
96-
.attr("step", 1)
97-
.style("width", "100%")
98-
.style("accent-color", "#bd93f9");
99-
10090
const genderLegend = scatterControls.append("div");
10191
genderLegend.append("div")
10292
.style("font-size", "13px")
@@ -123,7 +113,7 @@ const genderOptions = genderLegend.append("div")
123113
.attr("fill", genderColors[group])
124114
.attr("stroke", scatterTheme.pointStroke)
125115
.attr("stroke-width", 1);
126-
label.append("span").text(group);
116+
label.append("span").text(genderLabels[group]);
127117
});
128118

129119
const genreFilter = scatterControls.append("fieldset")
@@ -200,14 +190,13 @@ const scatterYTitle = scatterChart.append("text");
200190

201191
function eligibleAttributes(data) {
202192
const attributeType = scatterMode.property("value");
203-
const minimum = +scatterMin.property("value");
204193
const grouped = d3.group(
205194
data.filter(d => d.attribute_type === attributeType),
206195
d => d.attribute
207196
);
208197
return new Set(Array.from(grouped, ([attribute, rows]) => {
209198
const counts = new Map(rows.map(d => [d.gender_group, d.books]));
210-
return counts.get("Male authors") >= minimum && counts.get("Non-male authors") >= minimum
199+
return counts.get("Male authors") >= minimumBooks && counts.get("Non-male authors") >= minimumBooks
211200
? attribute
212201
: null;
213202
}).filter(Boolean));
@@ -315,7 +304,6 @@ function drawScatter(data) {
315304

316305
const totalBooks = d3.sum(visible, d => d.books);
317306
const selectedCount = visible.length ? d3.max(visible, d => d.attributes) : 0;
318-
scatterMinLabel.text(`Minimum books in each gender group: ${scatterMin.property("value")}`);
319307
scatterSummary.text(`${selectedCount} ${attributeType === "genre" ? "genres" : "author nationalities"} combined - ${d3.format(",")(totalBooks)} priced records`);
320308

321309
const points = scatterChart.selectAll(".scatter-point")
@@ -340,7 +328,7 @@ function drawScatter(data) {
340328
.style("opacity", 1)
341329
.style("left", `${left + 14}px`)
342330
.style("top", `${top - 36}px`)
343-
.html(`<strong style="color: #111318; font-weight: 750;">${d.gender_group}</strong><br/>Selected categories: ${d.attributes}<br/>Average price: $${d.average_price.toFixed(2)}<br/>Average rating: ${d.average_rating.toFixed(2)}<br/>Books: ${d3.format(",")(d.books)}`);
331+
.html(`<strong style="color: #111318; font-weight: 750;">${genderLabels[d.gender_group]}</strong><br/>Selected categories: ${d.attributes}<br/>Average price: $${d.average_price.toFixed(2)}<br/>Average rating: ${d.average_rating.toFixed(2)}<br/>Books: ${d3.format(",")(d.books)}`);
344332
})
345333
.on("mouseout", () => scatterTooltip.style("opacity", 0))
346334
.transition()
@@ -379,10 +367,6 @@ d3.csv("{{< asset-url "data/gender_price_scatter.csv" >}}", d3.autoType).then(da
379367
populateAttributes(data);
380368
drawScatter(data);
381369
});
382-
scatterMin.on("input", () => {
383-
populateAttributes(data);
384-
drawScatter(data);
385-
});
386370
resetGenres.on("click", () => {
387371
genreOptions.selectAll("input").property("checked", true);
388372
drawScatter(data);

0 commit comments

Comments
 (0)