Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active February 9, 2016 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbostock/57d620285395dae5a2ff to your computer and use it in GitHub Desktop.
Save mbostock/57d620285395dae5a2ff to your computer and use it in GitHub Desktop.
Counterclockwise Arc
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<style>
path {
fill: #ccc;
stroke: #000;
stroke-width: 1.5px;
}
text {
font: 500 15px "Helvetica Neue";
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 500,
radius = height / 2 - 20;
var arc = d3.svg.arc()
.innerRadius(0)
.outerRadius(radius);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var g = svg.selectAll("g")
.data([
{startAngle: Math.PI / 4, endAngle: 3 * Math.PI / 4, text: "This is a clockwise arc."},
{startAngle: 3 * Math.PI / 4, endAngle: Math.PI / 4, text: "This is a counterclockwise arc."}
])
.enter().append("g")
.attr("transform", function(d, i) { return "translate(" + ((i + .5) * width / 3) + "," + height / 2 + ")"; });
g.append("path")
.attr("d", arc)
.attr("id", function(d, i) { return "arc-" + i; });
g.append("text")
.attr("dx", 5)
.attr("dy", -5)
.append("textPath")
.attr("xlink:href", function(d, i) { return "#arc-" + i; })
.text(function(d) { return d.text; });
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment