The problem here is that you're adding svg:text elements directly to a
DIV. SVG elements have to be inside an svg:svg container (conceptually
it represents an SVG "image"); they can't be interspersed with HTML
elements.
The two possible approaches are:
1. HTML, using CSS3 transforms.
2. SVG, using SVG's "transform" attribute.
Here's an example of #1, using -webkit-transform:
d3.select("body").style("-webkit-transform", "rotateZ(5deg)");
The -webkit-transform origin defaults to the center of the element. So
if you want to rotate text inside of an HTML div this way, you'll need
to add a child div that is centered both horizontally and vertically,
and then rotated. This is, of course, a giant pain in CSS:
d3.select("body").append("div")
.style("position", "absolute")
.style("display", "table-row")
.style("top", "50px")
.style("left", "50px")
.style("background", "steelblue")
.append("div")
.style("display", "table-cell")
.style("vertical-align", "middle")
.style("text-align", "center")
.style("-webkit-transform", "rotateZ(90deg)")
.style("width", "200px")
.style("height", "200px")
.style("color", "white")
.text("Hello, world!");
Also, since -webkit-transform is only supported on WebKit, and all the
browsers that support the other vendor-specific CSS3 transforms
support SVG, I'd recommend approach #2: implement your treemap in SVG
rather than HTML. Here's an example:
You can then modify this example to apply a "transform" attribute to
the svg:text elements when you append them. You'll want to replace the
"x" and "y" attributes with the "transform" attribute: translate(x,y)
then rotate(90) for vertical text.
Mike