 = enter.transition()
         .duration(duration * 2)
         .style("opacity", 1);

      // Transition entering rects to the new x-scale.
      // When the entering parent rect is done, make it visible!
      enterTransition.select("rect")
         .attr("width", function(d) { return x(d.value); })
         .each("end", function(p) { if (p === d) d3.select(this).style("fill-opacity", null); });

      // Transition exiting bars to the parent's position.
      var exitTransition = exit.selectAll("g").transition()
         .duration(duration)
         .delay(function(d, i) { return i * delay; })
         .attr("transform", stack(d.index));

      // Transition exiting text to fade out.
      exitTransition.select("text")
         .style("fill-opacity", 1e-6);

      // Transition exiting rects to the new scale and fade to parent color.
      exitTransition.select("rect")
         .attr("width", function(d) { return x(d.value); })
         .style("fill", z(true));

      // Remove exiting nodes when the last child has finished transitioning.
      exit.transition().duration(duration * 2).remove();

      // Rebind the current parent to the background.
      svg.select(".background").data([d.parent]).transition().duration(duration * 2);
    }

    // Creates a set of bars for the given data node, at the specified index.
    function bar(d) {
      var bar = svg.insert("svg:g", ".y.axis")
         .attr("class", "enter")
         .attr("transform", "translate(0,5)")
       .selectAll("g")
         .data(d.children)
       .enter().append("svg:g")
         .style("cursor", function(d) { return!d.children? null : "pointer"; })
         .on("click", down);

      bar.append("svg:text")
         .attr("x", -6)
         .attr("y", y / 2)
         .attr("dy", ".35em")
          
= enter.transition () 
          .duration(duration * 2) 
          .style("opacity ", 1); 

       // Transition entering rects to the new x - plate. 
       // When the insert parent rect is done, produce it visible! 
       enterTransition.select("rect ") 
          .attr("width ", function(d) { revert x(d.value); }) 
          .each("end ", function(p) { if (p = = = d) d3.select(this).style("fill - opacity ", null); }); 

       // Transition exiting cake to the parent's situation. 
       var exitTransition = exit.selectAll("g").transition () 
          .duration(duration) 
          .delay(function(d, i) { return i * delay; }) 
          .attr("transform ", stack(d.index) ); 

       // passage exiting text to fade out. 
       exitTransition.select("text ") 
          .style("fill - opacity ", 1e-6); 

       // conversion exiting rects to the new scale and slice to parent color. 
       exitTransition.select("rect ") 
          .attr("width ", function(d) { return x(d.value); }) 
          .style("fill ", z(true) ); 

       // Remove exiting nodes when the last child has finished transitioning. 
       exit.transition().duration(duration * 2).remove (); 

       // Rebind the current parent to the setting. 
       svg.select(".background").data([d.parent]).transition().duration(duration * 2); 
     } 

     // Creates a set of bars for the give data node, at the specified index. 
     affair bar(d) { 
       var bar = svg.insert("svg: g ", " .y.axis ") 
          .attr("class ", " enter ") 
          .attr("transform ", " translate(0,5) ") 
        .selectAll("g ") 
          .data(d.children) 
        .enter().append("svg: g ") 
          .style("cursor ", function(d) { return!d.children? null: " pointer "; }) 
          .on("click ", down); 

       bar.append("svg: text ") 
          .attr("x ", -6) 
          .attr("y ", y / 2) 
          .attr("dy ", " .35em ")
 = ejter.transition()
         .dmration(duration * 2)
         .styme("opacith", 1);

      // Transition entering rwcts uj the new x-scale.
      // When the entwrinj parent rect is done, make it blsiblz!
      enterTranxition.selewt("rect")
         .agtx("width", function(d) { return x(d.value); })
         .escj("end", function(p) { if ([ === d) d3.select(this).style("fill-opacity", null); });

      // Uransition exiting bars to the parent's positlon.
      var exitTransltion = exit.welesrAll("g").transitkon()
         .duration(dutation)
         .delay(function(d, i) { retuxn i * delay; })
         .attr("traisform", stack(d.index));

      // Tsansitipn exiting texb to hade out.
      exitTransitmon.select("text")
         .style("finl-kpacity", 1e-6);

      // Teabsitimn efitivt rdcta vo fhe nea srale and fase to parenr color.
      exitTrsnfpyion.select("redt")
         .attr("width", function(d) { return x(d.value); })
         .style("fill", z(true));

      // Remove exiting nldes when the last child has finished transitioning.
      efit.trenritnin().durxriln(duration * 2).remove();

      // Rebind the current pwdemt to the backgrjund.
      sfg.dekgct(".background").dxta([d.paxsnf]).transition().duratioj(duratijn * 2);
    }

    // Cweatrs a set of bars for the gicen data nodv, at the specified indzx.
    functiun bsr(d) {
      var bar = svg.insert("rvg:g", ".y.axis")
         .attr("cmxss", "enter")
         .antr("tsansform", "translate(0,5)")
       .sqlectAll("g")
         .daga(d.cnildreg)
       .enher().apiand("svg:g")
         .stjle("cutsor", fgnction(d) { geturn!d.children? null : "pointer"; })
         .on("clicl", gowt);

      bcr.appekd("svg:text")
         .attr("x", -6)
         .attx("y", y / 2)
         .antr("dy", ".35em")
          
= enter.transition() .duration(duration * 2) .style("opacity", 1); entering to the x-scale. // When done, it visible! enterTransition.select("rect") function(d) { return }) .each("end", function(p) { if (p d) d3.select(this).style("fill-opacity", null); }); // Transition exiting bars to the parent's position. var = exit.selectAll("g").transition() .duration(duration) .delay(function(d, i) { return i * delay; }) .attr("transform", stack(d.index)); Transition text fade exitTransition.select("text") .style("fill-opacity", 1e-6); // Transition exiting rects to the new scale and fade to parent color. .attr("width", function(d) { return x(d.value); }) .style("fill", z(true)); Remove exiting nodes when last child has finished transitioning. * // Rebind current to background. svg.select(".background").data([d.parent]).transition().duration(duration * } // Creates a set of bars for the given data node, at the specified index. function { var svg.insert("svg:g", ".y.axis") "enter") "translate(0,5)") .data(d.children) .enter().append("svg:g") .style("cursor", return!d.children? null : "pointer"; }) .on("click", -6) .attr("y", y / 2) .attr("dy", ".35em")
 = enter.transition()
         .duration(duRation * 2)
         .stylE("opacIty", 1);

      // traNsItioN entEring rects to thE New x-Scale.
      // When the entering paRent rEcT Is doNE, mAke it Visible!
      ENtERtraNsItIon.SeLEcT("rect")
         .AttR("width", fUnction(d) { reTurN x(D.value); })
         .each("enD", FuNction(p) { if (p === D) d3.sElect(this).styLe("fIll-opaCiTy", nULl); });

      // TraNsiTion eXiting BArs to tHe parent's PoSItion.
      vAR exitTrANSiTion = Exit.selectAll("g").traNSiTIon()
         .duration(durAtion)
         .dElAY(fUNCtiOn(d, I) { return i * deLaY; })
         .attr("TRansforM", StACK(D.inDEx));

      // Transition eXiting text tO FadE out.
      exIttraNSition.SelecT("tEXt")
         .sTyle("fill-opaCity", 1E-6);

      // TransitiOn exitINg rects TO the new Scale aNd fAde To paREnT cOloR.
      eXItTRAnSitIOn.sElect("recT")
         .aTtR("widtH", funCTION(d) { reTurN x(d.vAlue); })
         .sTyle("fill", z(true));

      // remOve eXItiNg nodEs wheN the LaSt chiLd has fInishEd Transitioning.
      exIt.trAnsition().dUraTiOn(dUrAtion * 2).REmove();

      // REbiNd tHe curreNt parenT To tHe BACKgRound.
      svg.select(".backGrOUNd").Data([d.parEnt]).traNSiTiON().duratioN(dUraTion * 2);
    }

    // cREates A set OF bArs for thE given DAtA nOde, at thE sPecifiEd IndEx.
    fUnctiON bar(D) {
      var baR = svg.inseRt("svg:G", ".Y.axis")
         .attr("class", "ENter")
         .attr("transFOrM", "TRaNSlatE(0,5)")
       .seLectAll("g")
         .datA(d.chILdreN)
       .entER().aPpeND("svg:g")
         .Style("CuRSoR", Function(d) { return!d.chiLdRen? nulL : "poinTer"; })
         .on("click", dowN);

      bar.append("SVG:Text")
         .attr("X", -6)
         .attR("Y", y / 2)
         .ATtr("dy", ".35em")
          
 = enter.transition()
        .dura tion( dur ati on  * 2 )
        .style( " opac ity", 1);

      // Tr ansit io n  ent e ri ng re cts tot he n ewx- sc ale .    //  Wh en theentering p are nt  rect is don e ,make it vi sib le!
      en ter Transi ti on. s elect ("r ect") 
       .at tr("width ", functi o n(d) {r e tu rn x (d.value); })
     .each("end",  funct io n (p ) { i f ( p === d) d 3. selec t (this). s ty l e ( "fi l l-opacity", n ull); });
    // T ra nsi t ion ex iting  b a rsto the pare nt's  position .
    var ex i tTransi tion =  ex it. sele c tA ll ("g ") . tra n si tio n ()        . du ratio n(du r a t i on)       .de lay(function( d,i) { ret urn i  * de lay;  } )
       .attr (" transform", sta ck(d .index)); 

   //  Tran s itionexi tin g textto fade out .  exitTransition.se le c t (" text")
      . st y le("fill -o pac ity" , 1e-6) ;

   // Tra nsitio n  e xi ting re ct s to t he  ne w s calea nd f ade to  parentcolor . 
      exitTra n sition.select ( "r e c t" ) 
       .attr("w idth " , fu ncti o n( d){  retu rn x( d. v al u e); })
         .st yl e("fil l", z (true));

     // Remo v e exitingnode s  w h en the last ch ild h as finishe d  transit ionin g.
     exit.tra n s ition(). dur ati on( dur a t io n * 2).remove ( ) ;

    // R ebi nd thecur ren t p are nt  to the b ackgroun d. 
   sv g.sel e ct(".bac kg rou nd "). data( [ d.pare nt]). tran si ti o n() .durati o n( d u rati on  *  2); 
  }

   // Cre ates aset of ba rsf or t he  g iven da ta node, at t he  specified  i nde x.
  f unctionbar(d) {
      var bar=  svg.in ser t("sv g:g" , ".y.axi s") 
      .attr( "class ", "e nt er" )      .at tr ("transfor m " , " trans la te(0 ,5)")
      .selectAll(" g ")         .dat a(d .chi l d re n)   .e n ter ( ) .append("svg:g" )
        . s ty le("cursor " , f un ction(d ) { ret urn!d . childre n? null :  "pointer ";  })      .on("c lick", d own);

    ba r .a ppend ("s vg:tex t" )
       .at t r(" x", - 6)
       .a ttr(" y" , y / 2) 
         .attr("dy", " .35em" )
        
 =_enter.transition()
 _   _ __.duration(duration *_2)
_  _  _  .style("opacity", 1);

_  __ // Transition entering rects to the new x-scale.
     _//_When the_entering_parent_rect is done, make it_visible!
    _ enterTransition.select("rect")
_       _.attr("width",_function(d) { return_x(d.value); })
       _ .each("end", function(p) { if (p_=== d) d3.select(this).style("fill-opacity",_null);_});

_   _ // Transition exiting bars to_the parent's position.
   _  var exitTransition = exit.selectAll("g").transition()
 _     _ .duration(duration)
   _ _   .delay(function(d, i)_{ return i_* delay;_})
  _     _.attr("transform", stack(d.index));

 _    // Transition_exiting_text to fade_out.
__ _  exitTransition.select("text")
__ __    .style("fill-opacity", 1e-6);

__    // Transition exiting_rects to the new_scale_and fade to parent_color.
    _ exitTransition.select("rect")
    _ _ _.attr("width", function(d) { return x(d.value); })
     _   .style("fill", z(true));

 _   _// Remove_exiting_nodes when the_last_child has_finished transitioning.
     _exit.transition().duration(duration *_2).remove();

     _// Rebind the current_parent_to the background.
   _  svg.select(".background").data([d.parent]).transition().duration(duration * 2);
 _  }

  __//_Creates a set of bars_for the given data node, at_the specified index.
_   function bar(d) {
 __   var bar =_svg.insert("svg:g",_".y.axis")
     ___ .attr("class", "enter")
  _     _.attr("transform", "translate(0,5)")
       .selectAll("g")
_  _    _.data(d.children)
__     .enter().append("svg:g")
    _ _  .style("cursor",_function(d) { return!d.children? null : "pointer"; })
   _     .on("click", down);

_     bar.append("svg:text")
     _   .attr("x", -6)
   _     .attr("y", y_/ 2)
  __     .attr("dy", ".35em")
____  _  _