I want to draw a rectangle for each data point, and also draw a dot on the center of each rectangle if certain value is true. Although I can draw another set of dots trivial way. But I want to access some attribute (e.g., x, y) of the (parent) rectangles while drawling the corresponding dots. I have illustrated in the attached image. Can you please help me her? Thanks.
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title> Icon </title>
<script type="text/javascript" src="lib/d3/d3.v3.js"></script>
</head>
<body>
<p id="icon">
<script>
var dataset = [
{"id": 1, "selection": true},
{"id": 2, "selection": true},
{"id": 3, "selection": true},
{"id": 4, "selection": false},
{"id": 5, "selection": false},
{"id": 6, "selection": true},
{"id": 7, "selection": false},
{"id": 8, "selection": true}
];
var svg = d3.select("#icon")
.append("svg")
.attr("height", 200)
.attr("width", 200);
var x = 10, y = 10;
svg.selectAll("rect")
.data(dataset).enter()
.append("rect")
.attr("width", 10)
.attr("height", 10)
.attr("x", function(d, i) { return x = x + 12; })
.attr("y", function(d, i) { return y; })
.style("fill", "yellow")
.style("stroke", "grey")
.style("stroke-width", ".5px");
</script>
</body>
</html>