Skip to content

Instantly share code, notes, and snippets.

@mwdchang
Created December 20, 2014 04:49
Show Gist options
  • Save mwdchang/d4b890107d2ed52b5864 to your computer and use it in GitHub Desktop.
Save mwdchang/d4b890107d2ed52b5864 to your computer and use it in GitHub Desktop.
Slight variation on bostock's clipping venn

Add outline and interactions to bostock's clipping venn

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<style type="text/css">
body {
background: #FFF;
}
</style>
</head>
<body>
<script type="text/javascript">
// Modified
// See: https://gist.github.com/mbostock/1067636
var w = 960,
h = 600;
var svg = d3.select("body").append("svg:svg")
.attr("width", w)
.attr("height", h);
var defs = svg.append("svg:defs");
defs.append("svg:clipPath")
.attr("id", "circle1")
.append("svg:circle")
.attr("cx", 350)
.attr("cy", 200)
.attr("r", 180);
defs.append("svg:clipPath")
.attr("id", "circle2")
.append("svg:circle")
.attr("cx", 550)
.attr("cy", 200)
.attr("r", 180);
defs.append("svg:clipPath")
.attr("id", "circle3")
.append("svg:circle")
.attr("cx", 450)
.attr("cy", 360)
.attr("r", 180);
defs.append("svg:clipPath")
.attr("id", "circle1_out")
.append("svg:circle")
.attr("cx", 350)
.attr("cy", 200)
.attr("r", 185);
defs.append("svg:clipPath")
.attr("id", "circle2_out")
.append("svg:circle")
.attr("cx", 550)
.attr("cy", 200)
.attr("r", 185);
defs.append("svg:clipPath")
.attr("id", "circle3_out")
.append("svg:circle")
.attr("cx", 450)
.attr("cy", 360)
.attr("r", 185);
svg.append("svg:rect")
.attr("clip-path", "url(#circle1_out)")
.attr("width", w)
.attr("height", h)
.style("fill", "#000000");
svg.append("svg:rect")
.attr("clip-path", "url(#circle2_out)")
.attr("width", w)
.attr("height", h)
.style("fill", "#000000");
svg.append("svg:rect")
.attr("clip-path", "url(#circle3_out)")
.attr("width", w)
.attr("height", h)
.style("fill", "#000000");
svg.append("svg:rect")
.attr("clip-path", "url(#circle1)")
.attr("class", "inner")
.attr("width", w)
.attr("height", h)
.style("fill", "#ff0000");
svg.append("svg:rect")
.attr("class", "inner")
.attr("clip-path", "url(#circle2)")
.attr("width", w)
.attr("height", h)
.style("fill", "#00ff00");
svg.append("svg:rect")
.attr("class", "inner")
.attr("clip-path", "url(#circle3)")
.attr("width", w)
.attr("height", h)
.style("fill", "#0000ff");
svg.append("svg:g")
.attr("clip-path", "url(#circle1_out)")
.append("svg:rect")
.attr("clip-path", "url(#circle2_out)")
.attr("width", w)
.attr("height", h)
.style("fill", "#000000");
svg.append("svg:g")
.attr("clip-path", "url(#circle1)")
.append("svg:rect")
.attr("class", "inner")
.attr("clip-path", "url(#circle2)")
.attr("width", w)
.attr("height", h)
.style("fill", "#ffff00");
svg.append("svg:g")
.attr("clip-path", "url(#circle2_out)")
.append("svg:rect")
.attr("clip-path", "url(#circle3_out)")
.attr("width", w)
.attr("height", h)
.style("fill", "#000000");
svg.append("svg:g")
.attr("clip-path", "url(#circle2_out)")
.append("svg:rect")
.attr("clip-path", "url(#circle3_out)")
.attr("width", w)
.attr("height", h)
.style("fill", "#000000");
svg.append("svg:g")
.attr("clip-path", "url(#circle2)")
.append("svg:rect")
.attr("class", "inner")
.attr("clip-path", "url(#circle3)")
.attr("width", w)
.attr("height", h)
.style("fill", "#00ffff");
svg.append("svg:g")
.attr("clip-path", "url(#circle3_out)")
.append("svg:rect")
.attr("clip-path", "url(#circle1_out)")
.attr("width", w)
.attr("height", h)
.style("fill", "#000000");
svg.append("svg:g")
.attr("clip-path", "url(#circle3)")
.append("svg:rect")
.attr("class", "inner")
.attr("clip-path", "url(#circle1)")
.attr("width", w)
.attr("height", h)
.style("fill", "#ff00ff");
svg.append("svg:g")
.attr("clip-path", "url(#circle3_out)")
.append("svg:g")
.attr("clip-path", "url(#circle2_out)")
.append("svg:rect")
.attr("clip-path", "url(#circle1_out)")
.attr("width", w)
.attr("height", h)
.style("fill", "#000000");
svg.append("svg:g")
.attr("clip-path", "url(#circle3)")
.append("svg:g")
.attr("clip-path", "url(#circle2)")
.append("svg:rect")
.attr("class", "inner")
.attr("clip-path", "url(#circle1)")
.attr("width", w)
.attr("height", h)
.style("fill", "#eeeeee");
</script>
</body>
<script>
d3.selectAll('.inner').each(function(d) {
var c = d3.select(this).style('fill');
d3.select(this).datum({col:c});
d3.select(this).style('opacity', 0.4);
});
d3.selectAll('.inner').on('mouseover', function() {
d3.select(this).style('opacity', 0.9);
}).on('mouseout', function(d) {
d3.select(this).style('opacity', 0.4);
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment