Skip to content Skip to sidebar Skip to footer

D3 Animating A Bubble Chart Within A Given Radius

//bubble chart base. http://jsfiddle.net/NYEaX/1450/ I am trying to animate the bubbles - via changing their scale -- and if possible fade them in and out. At some stage I need to

Solution 1:

These animated bubbles will be part of this overall chart - I need support in fine-tuning the animated arcs and bubbles accordingly. So the pie chart arcs should tween smoothly -- and the bubbles should fade in/out/grow in radius/reduce in radius

enter image description here

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

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

1.-- how to animate the arcs2.-- how to animate the bubbles3.-- 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);

Solution 2:

To animate the bubbles (grow in) use:

vis.enter()
      .insert("circle")
      .attr('transform', function(d) {
        return'translate(' + d.x + ',' + d.y + ')';
      })
      .attr('r',0)
      .transition()
      .duration(1000)
      .attr('r', function(d) {
        return d.r;
      })
      .style("fill", function(d) {
        return color(d.name);
      })
      .attr('class', function(d) {
        return d.className;
      });

I tried adding this code to the jsfiddle you posted above : http://jsfiddle.net/NYEaX/1450/

Post a Comment for "D3 Animating A Bubble Chart Within A Given Radius"