-
const svg = d3.create("svg")
.attr("viewBox", [-padding, 0, width, width]);
+
const svg = d3.create("svg").attr("viewBox", [-padding, 0, width, width]);
-
svg.append("style")
.text(`circle.hidden { fill: #000; fill-opacity: 1; r: 1px; }`);
+
svg
.append("style")
.text(
`rect.hidden { fill: #000; fill-opacity: 1; width: 1px; height: 1px;}`
);
-
svg.append("g")
.call(xAxis);
+
svg.append("g").call(xAxis);
-
svg.append("g")
.call(yAxis);
+
svg.append("g").call(yAxis);
-
const cell = svg.append("g")
+
const cell = svg
.append("g")
.selectAll("g")
.data(d3.cross(d3.range(columns.length), d3.range(columns.length)))
.join("g")
-
.attr("transform", ([i, j]) => `translate(${i * size},${j * size})`);
+
.attr("transform", ([i, j]) => `translate(${i * size},${j * size})`);
-
cell.append("rect")
.attr("fill", "none")
.attr("stroke", "#aaa")
.attr("x", padding / 2 + 0.5)
.attr("y", padding / 2 + 0.5)
.attr("width", size - padding)
.attr("height", size - padding);
+
cell
.append("rect")
.attr("fill", "none")
.attr("stroke", "#aaa")
.attr("x", padding / 2 + 0.5)
.attr("y", padding / 2 + 0.5)
.attr("width", size - padding)
.attr("height", size - padding);
cell.each(function([i, j]) {
-
d3.select(this).selectAll("circle")
+
d3.select(this)
.selectAll("rect")
.data(data.filter(d => !isNaN(d[columns[i]]) && !isNaN(d[columns[j]])))
-
.join("circle")
.attr("cx", d => x[i](d[columns[i]]))
.attr("cy", d => y[j](d[columns[j]]));
+
.join("rect")
.attr("x", d => x[i](d[columns[i]]))
.attr("y", d => y[j](d[columns[j]]));
-
const circle = cell.selectAll("circle")
.attr("r", 3.5)
.attr("fill-opacity", 0.7)
.attr("fill", d => z(d.species));
+
const circle = cell
.selectAll("rect")
.attr("width", 3.5)
.attr("height", 3.5)
.attr("fill-opacity", 0.7)
.attr("fill", d => z(d.species));
cell.call(brush, circle, svg);
-
svg.append("g")
.style("font", "bold 10px sans-serif")
.style("pointer-events", "none")
+
svg
.append("g")
.style("font", "bold 10px sans-serif")
.style("pointer-events", "none")
.selectAll("text")
.data(columns)
.join("text")
-
.attr("transform", (d, i) => `translate(${i * size},${i * size})`)
.attr("x", padding)
.attr("y", padding)
.attr("dy", ".71em")
.text(d => d);
+
.attr("transform", (d, i) => `translate(${i * size},${i * size})`)
.attr("x", padding)
.attr("y", padding)
.attr("dy", ".71em")
.text(d => d);
-
svg.property("value", [])
+
svg.property("value", []);