Use escamas dinámicas

d3.scaleLinear()
    .domain([0, d3.max(dataset, (d) => d[1])])
    .range([h - padding, padding])

// That's all you need to do
Bored Boar