Using transition.transition to chain transitions and transition.each to apply a transition to a selection. Compare to using explicit delays. In response to a Stack Overflow question.
          Last active
          February 9, 2016 02:03 
        
      - 
      
- 
        Save mbostock/5779690 to your computer and use it in GitHub Desktop. 
    Exit, Update, Enter II
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | license: gpl-3.0 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <!DOCTYPE html> | |
| <meta charset="utf-8"> | |
| <style> | |
| div { | |
| background: white; | |
| border: solid 1px #ccc; | |
| padding: 20px; | |
| margin: 20px; | |
| } | |
| </style> | |
| <div>update</div> | |
| <div>exit</div> | |
| <script src="//d3js.org/d3.v3.min.js"></script> | |
| <script> | |
| var duration = 750; | |
| var div = d3.select("body").selectAll("div") | |
| .data(["enter", "update"], function(d) { return d || this.textContent; }); | |
| // 1. exit | |
| var exitTransition = d3.transition().duration(750).each(function() { | |
| div.exit() | |
| .style("background", "red") | |
| .transition() | |
| .style("opacity", 0) | |
| .remove(); | |
| }); | |
| // 2. update | |
| var updateTransition = exitTransition.transition().each(function() { | |
| div.transition() | |
| .style("background", "orange"); | |
| }); | |
| // 3. enter | |
| var enterTransition = updateTransition.transition().each(function() { | |
| div.enter().append("div") | |
| .text(function(d) { return d; }) | |
| .style("opacity", 0) | |
| .transition() | |
| .style("background", "green") | |
| .style("opacity", 1); | |
| }); | |
| </script> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            