function drawLength(data) {
const height = 500;
const mainWidth = 500;
const legendWidth = 300;
const width = mainWidth + legendWidth;
const margin = 45;
const svg = d3.create("svg").attr("width", width).attr("height", height);
const g = svg.append("g");
const nEpisodes = data["item"].length;
const dates = data["item"].map((d) => Date.parse(d.pubDate));
const st = d3
.scaleBand()
.domain(dates)
.range([margin, mainWidth - margin]);
const sDuration = d3
.scaleLinear()
.domain([0, 3600 * 3])
.range([height - margin, margin]);
const taxis = d3.axisBottom(st);
svg
.append("g")
.attr("transform", `translate(0, ${height - margin})`)
.call(taxis);
const yaxis = d3.axisLeft(sDuration);
svg
.append("g")
.attr("transform", `translate(${margin - 5}, 0)`)
.call(yaxis);
const title = g
.append("text")
.attr("x", margin)
.attr("y", margin + 20)
.attr("font-size", 25)
.attr("fill", "#222")
.text(data["title"]);
const subtitle = g
.append("text")
.attr("x", margin + 13 * data["title"].length)
.attr("y", margin + 20)
.attr("font-size", 15)
.attr("fill", "#777")
.text(data["description"]);
const selectedTitle = g
.append("text")
.attr("x", margin)
.attr("y", margin + 40)
.attr("font-size", 13)
.attr("fill", "#333");
const selectedSubtitle = g
.append("text")
.attr("x", margin)
.attr("y", margin + 40 + 13)
.attr("font-size", 10)
.attr("fill", "#777");
const episodes = g.append("g");
episodes
.selectAll("rect")
.data(data["item"])
.join("rect")
.attr("x", (d) => st(Date.parse(d["pubDate"])))
.attr("y", (d) => {
const second = duration2second(d["duration"]);
return second !== 0 ? sDuration(second) : 0;
})
.attr("width", st.bandwidth())
.attr("height", function (d) {
return sDuration(0) - d3.select(this).attr("y");
})
.attr("fill", "#0dd");
return svg.node();
}