I'm developing a legend toggling d3.js pie chart application using this jsFiddle as my latest version.I am aiming to get a streamlined working example where the legend can toggle the slices, trying to deactivate all slices - resorts in a reset which reactivates all the slices. Splitting up presentation and application layer logic.Tweening needs improvement too - as the slices pop into existence then re-tween smoothly.How do I improve/fix the various bugs in this code base?onLegendClick: function(dt, i){                    //_toggle rectangle in legendvar completeData = jQuery.extend(true, [], methods.currentDataSet);                    newDataSet = completeData;                                            if(methods.manipulatedData){                        newDataSet = methods.manipulatedData;                    }                    d3.selectAll('rect')                    .data([dt], function(d) {                         return d.data.label;                    })                    .style(fill-opacity, function(d, j) {                        var isActive = Math.abs(1-d3.select(this).style(fill-opacity));                        if(isActive){                            newDataSet[j].total = completeData[j].total;                                                        }else{                            newDataSet[j].total = 0;                                                    }                        return isActive;                    });                                                //animate slices                    methods.animateSlices(newDataSet);                    //stash manipulated data                    methods.manipulatedData = newDataSet;                }
d3.js dougnut pie chart legend toggling
javascript;d3.js