The svg code below plots four points, each with a different resulting level of transparency due to overlapping points.
The data consists of a position for a circle and the number of circles that will be at that position. The demo data here also demonstrates that this aggregation isn't perfect for various reasons - their may be two entries for the same position both indicating that a few circles are positioned there.
I would like to calculate and show the actual transparency as if I had been given the data in a completely un-aggregated form - e.g. in this example dataset the un-aggregated form would have three entries for the circle at position 3
and the transparency of the circle at position 3
would be the same as the transparency of the circle at the position 4
.
How could I calculate the alpha level I should use for each point to get this result? Note that I do not want to manipulate the data before hand to get the un-aggregated form, since the reason it is aggregated is to prevent huge numbers of svg elements being plotted, which would be very intensive to process.
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="http://d3js.org/d3.v3.min.js"></script>
</head>
<body>
<svg id="canvas"></svg>
<script>
var svg = d3.select("#canvas");
svg.selectAll("circle")
.data(
[
[1,1],
[2,6],
[3,1],
[3,2],
[4,1],
[4,1],
[4,1]
]
)
.enter().append("circle")
.attr("cy", 60)
.attr("cx", function(d) { return d[0] * 50; })
.attr("r", 20)
.attr("stroke-opacity", 0.3)
.attr("fill-opacity", 0.3);
</script>
</body>
</html>