vis4 = {
const target = html`<svg id="target" viewBox="-20 -20 ${width} ${height}"></svg>`;
const svg = d3.select(target);
const WIDTH = 410;
const HEIGHT = 310;
const MARGIN = { top: 10, right: 10, bottom: 10, left: 10 };
const INNER_WIDTH = WIDTH - MARGIN.left - MARGIN.right;
const INNER_HEIGHT = HEIGHT - MARGIN.top - MARGIN.bottom;
const x = d3.scaleLinear().domain([1, 8]).range([0, INNER_WIDTH]);
const y = d3.scaleLinear().domain([0, 100]).range([INNER_HEIGHT, 0]);
const xAxis = d3.axisBottom(x).ticks(8);
const yAxis = d3.axisRight(y).ticks(10);
const xAxisGrid = d3
.axisBottom(x)
.tickSize(-INNER_HEIGHT)
.tickFormat("")
.ticks(8);
const yAxisGrid = d3
.axisRight(y)
.tickSize(-INNER_WIDTH)
.tickFormat("")
.ticks(10);
svg
.append("g")
.attr("class", "x axis-grid")
.attr("transform", `translate(0, ${INNER_HEIGHT})`)
.call(xAxisGrid);
svg
.append("g")
.attr("class", "y axis-grid")
.attr("transform", `translate(${INNER_WIDTH},0)`)
.call(yAxisGrid);
svg
.append("g")
.attr("class", "x axis")
.attr("transform", `translate(0, ${INNER_HEIGHT})`)
.call(xAxis);
svg
.append("g")
.attr("class", "y axis")
.attr("transform", `translate(${INNER_WIDTH},0)`)
.call(yAxis);
svg
.selectAll("circle.median")
.data(visitors)
.join("circle")
.attr("class", "tweets")
.attr("r", 5)
.attr("cx", (d) => x(d.day))
.attr("cy", (d) => y(d.median))
.style("fill", "darkgray");
svg
.selectAll("g.box")
.data(visitors)
.join("g")
.attr("class", "box")
.attr("transform", (d) => `translate(${x(d.day)}, ${y(d.median)})`)
.each(function (d, i) {
d3.select(this)
.append("line")
.attr("class", "range")
.attr("x1", 0)
.attr("x2", 0)
.attr("y1", y(d.max) - y(d.median))
.attr("y2", y(d.min) - y(d.median))
.style("stroke", "black")
.style("stroke-width", "4px");
d3.select(this)
.append("line")
.attr("class", "max")
.attr("x1", -10)
.attr("x2", 10)
.attr("y1", y(d.max) - y(d.median))
.attr("y2", y(d.max) - y(d.median))
.style("stroke", "black")
.style("stroke-width", "4px");
d3.select(this)
.append("line")
.attr("class", "min")
.attr("x1", -10)
.attr("x2", 10)
.attr("y1", y(d.min) - y(d.median))
.attr("y2", y(d.min) - y(d.median))
.style("stroke", "black")
.style("stroke-width", "4px");
d3.select(this)
.append("rect")
.attr("class", "range")
.attr("width", 20)
.attr("x", -10)
.attr("y", y(d.q3) - y(d.median))
.attr("height", y(d.q1) - y(d.q3))
.style("fill", "white")
.style("stroke", "black")
.style("stroke-width", "2px");
d3.select(this)
.append("line")
.attr("x1", -10)
.attr("x2", 10)
.attr("y1", 0)
.attr("y2", 0)
.style("stroke", "darkgray")
.style("stroke-width", "4px");
});
return target;
}