Skip to content

Instantly share code, notes, and snippets.

@tarvaina
Created August 1, 2013 09:20
Show Gist options
  • Save tarvaina/6129825 to your computer and use it in GitHub Desktop.
Save tarvaina/6129825 to your computer and use it in GitHub Desktop.
Text alignment practice
{"description":"Text alignment practice","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/Trd99Uk.png"}
var data = d3.range(1, 11);
var svg = d3.select("svg");
var groups = svg.selectAll("g").data(data).enter().append("g");
var colorScale = d3.scale.linear()
.domain([0, data.length - 1])
.interpolate(d3.interpolateHsl)
.range(["#FF0000", "#00FF00"]);
groups.attr("transform", function(d, i) {
var x = i * 38 + 30;
var y = i * 32 + 30;
return "translate(" + x + ", " + y + ")";
});
var circles = groups
.append("circle")
.attr({
r: 17,
fill: function(d, i) { return colorScale(i); },
stroke: "#000000",
"stroke-width": 2
});
var labels = groups
.append("text")
.text(function(d, i) { return d; })
.attr({
"font-size": 15,
"alignment-baseline": "middle",
"text-anchor": "middle"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment