function scaleFn(coords, w, h) {
const [xMin, xMax] = d3.extent(coords, (p) => p[0]);
const [yMin, yMax] = d3.extent(coords, (p) => p[1]);
const scaleFactor = Math.min(w / (xMax - xMin), h / (yMax - yMin));
return ([x, y]) => [scaleFactor * (x - xMin), h - scaleFactor * (y - yMin)];
}