d3 js - clustering bubbles to segments

后端 未结 2 1556
庸人自扰
庸人自扰 2021-01-17 03:18

**** LATEST FIDDLE --- https://jsfiddle.net/tk5xog0g/8/

-- 2nd fiddle with a custom chart -- randomly placing the bubbles closer to region zones but can not account

2条回答
  •  不知归路
    2021-01-17 03:54

    Latest fiddle. http://jsfiddle.net/NYEaX/1505/

    ( http://jsfiddle.net/NYEaX/1506/ )- refactored

     1. -- how to animate the arcs
     2. -- how to animate the bubbles
     3. -- adding back the randomise button to test with 2 dummy data sets.
    

    this is the old pie animations and worked very well

                    /* ------- 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 -------*/
    

    //this is the current pie arcs - but when I try and animate the pie in the same manner - it fails.

    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);
    

提交回复
热议问题