misoproject / d3.chart

A framework for creating reusable charts with d3.js.
http://misoproject.com/d3-chart
MIT License
728 stars 87 forks source link

How to use livecycle events transition with d3.chart layer #44

Closed first-developer closed 10 years ago

first-developer commented 11 years ago

Hi, I'm trying to use events transition with d3.chart but it looks like it isn't working :'( http://jsfiddle.net/lioninho11/HH9SX/2/ Moreover, the documentation does only give definition for those transitions *:transtion but without giving few examples :) Please do you any idea or examples ?

Thanks a lot

jugglinmike commented 11 years ago

Hi there,

You appear to be using the :transition lifecycle event correctly in your example, but you are not declaring any attributes to be animated. Here's a simplified version of your chart:

  // ...
  dataBind: function(data) {
    return this.selectAll("path")
      .data(data);
  },            
  insert: function() {
    return this.append("path");
  },
  "enter:transition" : function() {
    var chart = this.chart();
    return this.duration(2000)
      .delay(2000);
  }
  // ...

This could be written in "plain" d3.js as:

base.selectAll("path")
  .data(data).append("path")
    .enter().transition()
      .duration(2000).delay(2000);

...which might make it more obvious why you aren't seeing any animations.

If you set an animate-able attribute on the enter:transition lifecycle event, then d3.js will animate it. For example, this is how you would update your handler to animate the stroke-width:

  // ...
  "enter:transition" : function() {
    var chart = this.chart();
    return this.duration(2000)
-     .delay(2000);
+     .delay(2000)
+     .style("stroke-width", "5px");
  }
  // ...

(Also: you don't have to return the selection from within lifecycle events.)

Does this help?

jugglinmike commented 10 years ago

It's been a few months, so I'm going to close this issue. Hope my suggestion helped, @first-developer!