Skip to content

Instantly share code, notes, and snippets.

@35degrees
Last active June 20, 2017 18:01
Show Gist options
  • Save 35degrees/1096d5c4e2e2765fd169d4a3d34cd11a to your computer and use it in GitHub Desktop.
Save 35degrees/1096d5c4e2e2765fd169d4a3d34cd11a to your computer and use it in GitHub Desktop.
opacity vs. fill-opacity example
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
.dot {fill: IndianRed; stroke: LimeGreen; stroke-width: 3px}
.dot:hover {r: 12; stroke-width: 5px}
</style>
</head>
<body>
<script>
// Feel free to change or delete any of the code you see in this editor!
var holder = d3.select("body")
.append("svg")
.attr("width",450)
.attr("height",400);
holder.append("circle")
.attr("cx",100)
.attr("cy",100)
.attr("r",50)
.attr("fill-opacity","0.5")
.style("fill","MidnightBlue")
.style("stroke","Red")
.style("stroke-width","5px");
holder.append("circle")
.attr("cx",200)
.attr("cy",100)
.attr("r",50)
.attr("opacity","0.5")
.style("fill","MidnightBlue")
.style("stroke","Red")
.style("stroke-width","5px");
holder.append("circle")
.attr("cx",300)
.attr("cy",100)
.attr("r",50)
.attr("stroke-opacity","0.3")
.attr("fill-opacity","0.8")
.style("fill","MidnightBlue")
.style("stroke","Red")
.style("stroke-width","5px");
holder.append("polyline")
.style("fill","none")
.style("stroke","MidnightBlue")
.attr("points"," 200,25, 200,300");
holder.append("polyline")
.style("fill","none")
.style("stroke","MidnightBlue")
.style("stroke-dasharray","5,3")
.attr("points"," 25,200, 300,200");
holder.append("line")
.style("fill","none")
.style("stroke","MidnightBlue")
.style("stroke-width","15px")
.style("stroke-linecap","Round")
.attr("x1",50)
.attr("y1",220)
.attr("x2",250)
.attr("y2",220);
holder.append("line")
.style("fill","none")
.style("stroke","MidnightBlue")
.style("stroke-width","15px")
.style("stroke-linecap","Butt")
.attr("x1",50)
.attr("y1",250)
.attr("x2",250)
.attr("y2",250);
holder.append("polyline")
.style("fill","none")
.style("stroke","MidnightBlue")
.style("stroke-width","15px")
.style("stroke-linecap","Round")
.style("stroke-linejoin","Bevel")
.attr("points","260,200, 320,275, 380,200")
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment