A quick v4 update to this v3 block.
There are a few changes to facilitate the use of a title centered on the convex hull centroid:
// create a polygon
var polygon = d3.polygonHull(vertices.map(function(d) { return d; }) );
// use the polygon to update the convex hull
hull.datum(polygon).attr("d", function(d) { return "M" + d.join("L") + "Z"; });
// also use it to place the text (raise so it stays above new nodes)
text.attr("transform","translate("+d3.polygonCentroid(polygon)+")").raise();
https://d3js.org/d3.v4.min.js