Accepted answer

the problem here is this line:

 var layer = svg.selectall(".layer")

the first time you run changepangolin there is no element with a class layer, and the path is appended as expected. however, from the second time on, as there is already an element with a class named "layer" in the dom, your "enter" selection will be always empty.


append your path outside the changepangolin function:

var layer = svg.append("path")
    .attr("fill", "none")
    .attr("stroke", "black")
    .attr("stroke-width", "2px");;

and, inside changepangolin, simply change it:

    .attr("d", area(

Related Query