function renderLegend(svg, colorscale, heightLegend, widthLegend, barHeight, legendTicks, legendTickformat, id) {
const defs = svg.append("defs");
const linearGradient = defs.append("linearGradient")
.attr("id", id);
linearGradient.selectAll("stop")
.data(colorscale.ticks().map((t, i, n) => ({ offset: `${100*i/n.length}%`, color: colorscale(t) })))
.enter().append("stop")
.attr("offset", d => d.offset)
.attr("stop-color", d => d.color);
svg.append('g')
.attr("transform", `translate(0,${heightLegend})`)
.append("rect")
.attr("width", widthLegend)
.attr("height", barHeight)
.style("fill", "url(#"+id+")");
const axisScale = d3.scaleLinear()
.domain(colorscale.domain())
.range([0, widthLegend])
const axisBottom = g => g
.attr("class", `legx-axis`)
.attr("transform", `translate(0,${heightLegend+barHeight})`)
.call(d3.axisBottom(axisScale)
.ticks(legendTicks)
.tickSize(-barHeight)
.tickFormat(d3.format(legendTickformat)))
svg.append('g')
.call(axisBottom);
}