1

I have added labels to the Zoomable Icicle Layout example provided here: http://bl.ocks.org/mbostock/1005873

I rotate the labels based on available space using the following:

.attr("transform", function (d) {
     return (x(d.x + d.dx) - x(d.x)) > 50 ?
          ("translate(" + (x(d.x + d.dx / 2)) + "," + (y(d.y + d.dy / 2)) + ")rotate(0)") :
          ("translate(" + (x(d.x + d.dx / 2)) + "," + (y(d.y + d.dy / 2)) + ")rotate(90)"); })

which rotates the label 90' if the space is too small to keep it horizontal.

What I would like to know is how to get the rotation value of each d?

VividD
  • 10,456
  • 6
  • 64
  • 111
sim1
  • 457
  • 1
  • 7
  • 26
  • I'm not sure if I understand the question. You're setting the rotation, so you would know what it is, wouldn't you? – Lars Kotthoff Dec 16 '13 at 21:25
  • Apologies, I would like to get the value of the rotation for each d later in another function. – sim1 Dec 17 '13 at 06:18

1 Answers1

0

You can abstract out the code which determines the rotation angle simplify the expression as:

function rotation(d, x) {
    return (x(d.x + d.dx) - x(d.x)) > 50 ? 0 : 90;
}

// ...
.attr("transform", function (d) {  
      return "translate(" + [(x(d.x + d.dx / 2)), (y(d.y + d.dy / 2))] + ")" +  
             "rotate(" + rotation(d, x) + ")";
})

Then whenever you need the value of rotation of a point which is bound to data d, call rotation(d, x).

musically_ut
  • 34,028
  • 8
  • 94
  • 106