Created
October 12, 2012 21:52
-
-
Save kardeiz/3881758 to your computer and use it in GitHub Desktop.
starting point for my labels...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://d3js.org/d3.v2.js"></script> | |
<script type="text/javascript" src="https://raw.github.com/ZJONSSON/d3-plugins/master/force_labels/force_labels.js"></script> | |
<style> | |
.anchor { fill:blue} | |
.labelbox { fill:black;opacity:0.8} | |
.labeltext { fill:white;font-weight:bold;text-anchor:middle;font-size:16;font-family: serif} | |
.link { stroke:gray;stroke-width:0.35} | |
</style> | |
</head> | |
<body> | |
<div id="div1"></div> | |
<script type="text/javascript"> | |
var w=960,h=500, | |
x_mean = w/2, | |
x_std = w/10, | |
y_mean = h/2, | |
y_std = h/10, | |
labelBox,link; | |
var width = 400, | |
height = 400, | |
outerRadius = Math.min(width, height) / 2, | |
innerRadius = outerRadius * .6, | |
data = d3.range(10).map(Math.random), | |
color = d3.scale.category20(), | |
donut = d3.layout.pie(), | |
arc = d3.svg.arc().innerRadius(innerRadius).outerRadius(outerRadius); | |
var myData = [{text: "hello", size: 2},{text: "hello2", size: 27},{text: "hello3", size: 7},{text: "hello4", size: 2},{text: "hello5", size: 1},{text: "hello6", size: 1}] | |
var vis = d3.select("#div1") | |
.append("svg") | |
.data([myData]) | |
.attr("width", width) | |
.attr("height", height); | |
var arcs = vis.selectAll("g.arc") | |
.data(donut.value(function(d) { return d.size; })) | |
.enter().append("g") | |
.attr("class", "arc") | |
.attr("transform", "translate(" + outerRadius + "," + outerRadius + ")"); | |
arcs.append("path") | |
.attr("fill", function(d, i) { return color(i); }) | |
.attr("d", arc); | |
var div_1019 = arcs.append("rect") | |
.attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; }) | |
.attr("dy", ".35em"); | |
div_1019.append("text") | |
.attr("text-anchor", "middle") | |
.text(function(d, i) { return myData[i].text == "" ? "no response" : myData[i].text }); | |
div_1019.append("text") | |
.attr("text-anchor", "middle") | |
.text(function(d, i) { return d.value.toFixed(0) }); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment