score:1

Accepted answer

you're attempting to append to a transition:

labelselection.enter() 
  .append('text') // returns a selection of newly entered text elements
  .style(...)     // returns that same selection
  .attr(... )     // returns that same selection
 //  ...
 .transition()    // returns a transition
 .duration(450)   // returns that same transition
 .ease(...)       // returns that same transition
  // ...
 .text(d => d.name) // returns that same transition
 .append(...)       // error

transitions and selections share a lot of methods (such as .style(), .attr(), and even .text()), so they can look very similar, but they don't share all methods.

you can do selection.append(), but not transition.append(). this is why you get your error message, append isn't a method of a transition, which explains your error message:

labelselection.enter(...).append(...).style(...).style(...).style(...).attr(...).style(...).transition(...).duration(...).ease(...).attr(...).attr(...).style(...).style(...).style(...).style(...).style(...).text(...).append is not a function

.text returns a transition in this case (as it was chained to a transition, as shown above in the first code block), so we can reduce this to "transition.append is not a function".

instead, you could break up your method chaining by keeping a reference to the relevant selection:

var labelenter = labelselection.enter() 
  .append('text') 
  .style(...)     
  .attr(... )     
 //  ...


 labelenter.transition()    
 .duration(450)   
 .ease(...)      
 //  ...

 labelenter.append("title")
   .text(...)

the alternative, which i would think makes your method chain unnecessarily long, is to use transition.selection(), which returns the selection that the transition corresponds to:

 labelselection.enter() 
  .append('text') 
  .style(...)     
  .attr(... )     
 //  ...
 .transition()    
 .duration(450)   
 .ease(...)      
  // ...
 .text(d => d.name); 
 .selection()   // return a selection instead of a transition
 .append("title")
   .text(...)

Related Query

More Query from same tag