Turning text paths in a d3.js chord diagram without the usual svg: text

I am trying to adapt this chord diagram by Mike Bostock:

I want the text labels to rotate outward, like this chord diagram:

http://bost.ocks.org/mike/uberdata/

enter image description here

There is an example here

http://bl.ocks.org/mbostock/910126

enter image description here

However, the conversion is done using svg: text:

  g.append("svg:text")
      .each(function(d) { d.angle = (d.startAngle + d.endAngle) / 2; })
      .attr("dy", ".35em")
      .attr("text-anchor", function(d) { return d.angle > Math.PI ? "end" : null; })
      .attr("transform", function(d) {
        return "rotate(" + (d.angle * 180 / Math.PI - 90) + ")"
            + "translate(" + (r0 + 26) + ")"
            + (d.angle > Math.PI ? "rotate(180)" : "");
      })
      .text(function(d) { return nameByIndex[d.index]; });

The one I'm trying to adapt uses "text" and "textPath", and I can't seem to just add the transform / rotate attribute. Adding this line

.attr("transform",function(d,i){return "rotate(90)";})

to the code below does nothing:

   // Add a text label.
        var groupText = group.append("text")
            .attr("x", 6)
            .attr("dy", 15);

            groupText.append("textPath")
            .attr("xlink:href",  function(d, i) { return "#group" + i; })

           .text(function(d, i) { return cities[i].country; });

Any ideas on how I can turn the text out, so the small text labels of the chord groups can be displayed without grouping or (like the original solution) completely disabled?

+5
1

,

, , :

// Add a text label.
// var groupText = group.append("text")
//     .attr("x", 6)
//     .attr("dy", 15);

//groupText.append("textPath")
//    .attr("xlink:href", function(d, i) { return "#group" + i; })
//    .text(function(d, i) { return cities[i].name; });

// Remove the labels that don't fit. :(
//groupText.filter(function(d, i) { return groupPath[0][i].getTotalLength() / 2 - 16 < this.getComputedTextLength(); })
//    .remove();

group.append("text")
  .each(function(d) { d.angle = (d.startAngle + d.endAngle) / 2; })
  .attr("dy", ".35em")
  .attr("transform", function(d) {
    return "rotate(" + (d.angle * 180 / Math.PI - 90) + ")"
        + "translate(" + (innerRadius + 26) + ")"
        + (d.angle > Math.PI ? "rotate(180)" : "");
  })
  .style("text-anchor", function(d) { return d.angle > Math.PI ? "end" : null; })
  .text(function(d, i) { return cities[i].name; });
+5

All Articles