Skip to content

Instantly share code, notes, and snippets.

@seliopou
Created April 1, 2013 18:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seliopou/5286876 to your computer and use it in GitHub Desktop.
Save seliopou/5286876 to your computer and use it in GitHub Desktop.

Instead of adding methods to d3.selection, make a transform its own object that you can define independently of a selection. So this...

d3.selectAll("g.label")
  .translate(function(d) { return [20,d.x*10]})
  .rotate(40)
  .scale(function(d) {return [d.size,2]})

... would turn into this:

var t = d3.transform()
    .translate(function(d) { return [20, d.x * 10]; })
    .rotate(40)
    .scale(function(d) { return [d.size, 2]; });

d3.select('g.label')
  .attr('transform', t);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment