Node text wrapping and resizing

I am trying to wrap text in graph nodes but doing quite a bad job! Here’s a simple example:

How can I get the text to wrap and resize to fit within the dimensions of the node?

See Fit Text to Circle / Mike Bostock | Observable

Also, Observable Plot has some heuristics to measure text and wrap it in SVG. They are used in the text and tip marks, but you can also copy from the source code if you like (provided you respect the license).

Thanks, Fil!