I am not sure what I said that “is not quite right”, if i look at the generated svg it contains a lot of id attributes set and they must be unique, and are not as soon as you display a second diagram. I am not contesting anything else you said including in your most recent reply.
I would be happy for someone to contest what I did say, if its wrong.