The redesigned pie chart animations in d3 are experiencing glitches

Previously, I had a pie chart with fantastic animations. You can view it here: https://jsfiddle.net/tk5xog0g/29/

I tried to rebuild the chart and improve it based on my needs, but the animations no longer work as intended. I suspect this might be due to changes in the structure of arcs and slice paths within different g elements.

You can see my current progress here: http://jsfiddle.net/NYEaX/1507/


The original pie animations worked flawlessly:


/* ------- ANIMATE PIE SLICES -------*/
var slice = doughpie.select(".slices").selectAll("path.slice")
  .data(pie(data), key);

slice.enter()
  .insert("path")
  .style("fill", function(d) {
    return color(d.data.label);
  })
  .style("transform", function(d, i){
    //return "translate(0, 0)";
  })
  .attr("class", "slice");

slice
  .transition().duration(1000)
  .attrTween("d", function(d) {
    this._current = this._current || d;
    var interpolate = d3.interpolate(this._current, d);
    this._current = interpolate(0);
    return function(t) {
      return arc(interpolate(t));
    };
  })

slice.exit()
  .remove();
/* ------- ANIMATE PIE SLICES -------*/

However, when I attempted to apply similar animations to the current pie arcs, they do not function correctly:


var g = svg.selectAll(".arc")
  .data(pie(data))
  .enter().append("g")
  .attr("class", "arc");

g.append("path")
  .attr("d", arc)
  .style("fill", function(d) {
    return color(d.data.label);
  });

arc
  .outerRadius(radius - 10)
  .innerRadius(0);

Answer №1

Seems like the randomize function is not functioning properly, but the animations are working as intended.

var width = 800,
  height = 600,
  radius = Math.min(width, height) / 2;

var color = d3.scale.ordinal()
  .range(["#46a2de", "#7b3cc9", "#31d89c", "#de5942", "#ffa618"]);

var arc = d3.svg.arc()
  .outerRadius(radius - 66)
  .innerRadius(radius - 70);

var pie = d3.layout.pie()
  .sort(null)
  .value(function(d) {
    return d.value;
  });

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

// The rest of the JavaScript code remains unchanged...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Strategies for Effectively Managing Null Checks in Your JavaScript Project

When retrieving data from the BE API, it is in the format: { "details": { "address": { "street": "123/4", "city": "Banglore" } } } In our React project, we access this dat ...

Feeling puzzled about the next() function in Node.js?

https://github.com/hwz/chirp/blob/master/module-5/completed/routes/api.js function isAuthenticated (req, res, next) { // If the user is authenticated in the session, call the next() to proceed to the next request handler // Passport adds this met ...

Having difficulty locating audio files within a Next.js project

I am facing challenges when trying to import my audio files into a redux slice. Currently, I am attempting to retrieve my audio files from the app > public > audio directory. I have made efforts to access my audio files through 2 different director ...

Encountering an error when trying to use this.setState

I'm currently working on developing a simple react application that consists of a component. In this component, I am attempting to adjust the state when a link is clicked. However, I'm encountering an issue where the setState function is not bein ...

Function that yields promise result

I need help figuring out how to make this recursive function return a promise value. I've attempted various approaches, but they all resulted in the search variable ending up as undefined. public search(message: Message) { let searchResult: strin ...

Issues with rendering HTML5 drag and drop styles are not visible on a Windows Server 2003 platform

I am currently developing a file upload tool utilizing Valum's Ajax-Uploader as the foundation. The concept is reminiscent of how attaching files works in Gmail. Users should be able to simply drag and drop a file from their desktop into the browser w ...

Error encountered: "Instance variable for Apex chart not defined while attempting to update charts with updateOptions."

I have integrated Apexcharts to create charts within my application. The initial data loads perfectly upon onload, but when applying a filter, I face an issue where the charts need to be refreshed or updated with the new filtered data. I attempted to use t ...

Tips to minimize a responsive Bootstrap 4 menu by clicking elsewhere

When using my bootstrap nav menu on desktop, it closes when clicking outside of it. However, this feature doesn't work on mobile devices. I attempted to modify some code from a codepen to match the classes on my website, but it didn't work. Bel ...

Ways to avoid the browser from storing a JSON file in its cache

Hey there, I'm working on a project and running into some issues with caching. The problem I'm facing is that the browser keeps holding onto the json file containing save data even after I update it elsewhere. This means that the browser is readi ...

Display the latest distinct records in Vue.js

I've hit a roadblock in my project. @StephenThomas kindly assisted me with this issue: Vue.js only show objects with a unique property but I still need to make some adjustments. My current task involves creating a leaderboard for a game using Firest ...

Finding the Row Number of an HTML Table by Clicking on the Table - Utilizing JQuery

Seeking assistance to tackle this issue. I currently have an HTML table with a clickable event that triggers a dialog box. My goal is to also retrieve the index of the row that was clicked, but the current output is not what I anticipated. //script for the ...

What causes the image to not appear at the center bottom of the page when using IE for loading?

Why does the loading image not appear at the center bottom of the page in IE? This function loads content when the page is loaded and also loads content when scrolled to the bottom. When you load the page index.php, you will see the loading image at the ...

Is it possible for jQuery UI Tabs to load entire new HTML pages?

In my index.html file, I have set up 3 different tabs. Using the jQuery UI function tabs(), I am attempting to load an HTML page via Ajax. Each HTML page includes the jQuery library and contains the following code: <link type="text/css" href="css/redmo ...

Ensure that the HTML link is valid and authenticated using SESSIONS

When creating a website, one of the initial tasks I like to tackle is adding links at the bottom of the page for checking valid HTML and CSS: HTML5  •   CSS <div> <a href="http://validator.w3.org/check?uri=referer" ...

Loading Jquery Image Swapping

Is there a simpler way to change the src attribute of a group of images to match their respective title attributes? <img src="" title="images/1.png" class="images" /> <img src="" title="images/2.png" class="images" /> <img src=" ...

Understanding the fundamentals of event handling in JavaScript

Is there a way to access the object that called the event handler within the event handler function itself? For example: marker.on('dragend', onDragEnd); In this case, marker is the object that triggers the ondragEnd function on the Dragend eve ...

Utilize lodash to trim the object key

I am looking for a solution to remove occurrences of the object key y_ and achieve an output similar to useroutput: var user =[{"data":"2","y_data1":1},{"data":"4","y_data1":3,"y_data2":3}] var useroutput=[{"data":"2","data1":1},{"data":"4","data1":3, ...

AddThis plugin in Wordpress is unresponsive when used with a theme that relies heavily

I've been struggling to properly set up the AddThis Wordpress plugin to display share buttons below each post in an AJAX theme. After inserting this code into the custom button field on the settings page: <div class="addthis_toolbox addthis_defa ...

Tips on accessing a function or variable within a script executed using $.getScript

After running a script with $.getScript, is there a way to access the namespace of that script? I expected to be able to do so since the plugin function is defined in the global scope. index.js $.getScript('plugin.js').then((...result) => co ...

Caution: It is not possible to make updates on a component while inside the function body of another component, specifically in TouchableOpacity

I encountered this issue: Warning: Trying to update a component from within the function body of another component. Any suggestions on how to resolve this? Interestingly, the error disappears when I remove the touchable opacity element. ...