Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9140749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:33:25+00:00 2026-06-17T09:33:25+00:00

I’m trying to add text to the partition-sunburst example . I have followed a

  • 0

I’m trying to add text to the partition-sunburst example. I have followed a hint given on Google Group and I was able to add the text. Now I want to rotate it. The new angles seem to be correct, but all the text get gathered in one point.

This is the piece of code where I add and rotate the text:

var text = vis.data([json]).selectAll("text")
    .data(partition.nodes)
      .enter().append("svg:text")
        .attr("x", function(d) { return radius * Math.cos(d.x + d.dx/2); } )
        .attr("y", function(d) { return radius * Math.sin(d.x + d.dx/2); } )
        .attr("dy", ".31em")
        .style("font-size", "5px")
        .attr("transform", function(d) {
          var angle = (2 * Math.PI - d.x) * (180/Math.PI);
          var rotation = "rotate(" + angle + ")";
          console.log(rotation);
          console.log("d.x=" + d.x + ", d.y=" + d.y);
          return rotation;
        })
        .text(function(d) { return d.name; });

This is an image of what I get:

enter image description here

and this is the full script:

var width = 1000,
    height = 1000,
    radius = 350,
    x = d3.scale.linear().range([0, 2 * Math.PI]),
    y = d3.scale.pow().exponent(1.3).domain([0, 1]).range([0, radius]),
    padding = 5,
    color = d3.scale.category20c();

var vis = d3.select("#chart").append("svg")
    .attr("width", width)
    .attr("height", height)
  .append("g")
    .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");

var partition = d3.layout.partition()
    .sort(null)
    .size([2 * Math.PI, radius * radius])
    .value(function(d) { return 1; });

var arc = d3.svg.arc()
    .startAngle(function(d) { return d.x; })
    .endAngle(function(d) { return d.x + d.dx; })
    .innerRadius(function(d) { return Math.sqrt(d.y); })
    .outerRadius(function(d) { return Math.sqrt(d.y + d.dy); });

d3.json("fracking.json", function(json) {
  var path = vis.data([json]).selectAll("path")
      .data(partition.nodes)
    .enter().append("svg:path")
      .attr("display", function(d) { return d.depth ? null : "none"; })
      // hide inner ring
      .attr("d", arc)
      .attr("fill-rule", "evenodd")
      .style("stroke", "#fff")
      .style("fill", function(d) { return color((d.children ? d : d.parent).name); })
  .each(stash);

   var text = vis.data([json]).selectAll("text")
    .data(partition.nodes)
      .enter().append("svg:text")
        .attr("x", function(d) { return radius * Math.cos(d.x + d.dx/2); } )
        .attr("y", function(d) { return radius * Math.sin(d.x + d.dx/2); } )
        .attr("dy", ".31em")
        .style("font-size", "5px")
        .attr("transform", function(d) {
          var angle = (2 * Math.PI - d.x) * (180/Math.PI);
          var rotation = "rotate(" + angle + ")";
          console.log(rotation);
          console.log("d.x=" + d.x + ", d.y=" + d.y);
          return rotation;
        })
        .text(function(d) { return d.name; });

  d3.select("#size").on("click", function() {
    path
        .data(partition.value(function(d) { return d.size; }))
      .transition()
        .duration(1500)
        .attrTween("d", arcTween);
    d3.select("#size").classed("active", true);
    d3.select("#count").classed("active", false);
  });
  d3.select("#count").on("click", function() {
    path
        .data(partition.value(function(d) { return 1; }))
      .transition()
        .duration(1500)
        .attrTween("d", arcTween);
    d3.select("#size").classed("active", false);
    d3.select("#count").classed("active", true);
  });
});

// Stash the old values for transition.
function stash(d) {
  d.x0 = d.x;
  d.dx0 = d.dx;
}

// Interpolate the arcs in data space.
function arcTween(a) {
  var i = d3.interpolate({x: a.x0, dx: a.dx0}, a);
  return function(t) {
    var b = i(t);
    a.x0 = b.x;
    a.dx0 = b.dx;
    return arc(b);
  };
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:33:26+00:00Added an answer on June 17, 2026 at 9:33 am

    I think you need to specify the center of rotation. Try this:

    var text = vis.data([json]).selectAll("text")
    .data(partition.nodes)
      .enter().append("svg:text")
        .attr("x", function(d) { return radius * Math.cos(d.x + d.dx/2); } )
        .attr("y", function(d) { return radius * Math.sin(d.x + d.dx/2); } )
        .attr("dy", ".31em")
        .style("font-size", "5px")
        .attr("transform", function(d) {
          var angle = (2 * Math.PI - d.x) * (180/Math.PI);
          var rotation = "rotate(" + angle + "," + d3.select(this).attr("x") + "," d3.select(this).attr("y") +")";
          console.log(rotation);
          console.log("d.x=" + d.x + ", d.y=" + d.y);
          return rotation;
        })
        .text(function(d) { return d.name; });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
this is what i have right now Drawing an RSS feed into the php,
I'm trying to select an H1 element which is the second-child in its group
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.