lollipop_chart = {
replay;
const container = d3.create("svg")
.attr("height", h + margin.top + margin.bottom)
.attr("width", width)
const title = container.append("text")
.text("Population by Countries in (please click the buttons above)")
.attr("fill", "grey")
.attr("font-family", "Helvetica Neue, Arial")
.attr("font-size", 30)
.attr("font-weight", "bold")
.attr("transform", "translate(" + (width/2) + ", 40)")
.style("text-anchor", "middle")
const chart = container.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
chart.append("g")
.attr("transform", "translate(0," + h + ")")
.call(d3.axisBottom(xScale))
.selectAll("text")
.attr("transform", "rotate(-45)translate(-5,0)")
.attr("text-anchor", "end")
.style("font-size", "10px")
.style("font-family", "Helvetica Neue, Arial")
chart.append("g")
.call(d3.axisLeft(yScale))
.selectAll("text")
.style("font-size", "12px")
.style("font-family", "Helvetica Neue, Arial")
const lines = chart.selectAll("myline")
.data(gapminder_2005)
.join("line")
.attr("x1", xScale(0))
.attr("x2", d => xScale(0))
.attr("y1", d => yScale(d.country))
.attr("y2", d => yScale(d.country))
.attr("stroke", "grey")
const circles = chart.selectAll("mycircle")
.data(gapminder_2005)
.join("circle")
.attr("cx", d => xScale(0))
.attr("cy", d => yScale(d.country))
.attr("r", "6")
.attr("fill", "grey")
function update(data) {
title
.text("Population by Countries in " + (data === gapminder_1955 ? "1955" : "2005"))
.transition()
.duration(1000)
.attr("fill", data === gapminder_1955 ? "yellowgreen" : "turquoise")
lines
.data(data)
.transition()
.duration(1000)
.attr("x2", d => xScale(d.pop))
.attr("stroke", data === gapminder_1955 ? "yellowgreen" : "turquoise")
circles
.data(data)
.transition()
.duration(1000)
.attr("cx", d => xScale(d.pop))
.attr("r", "6")
.attr("fill", data === gapminder_1955 ? "yellowgreen" : "turquoise")
}
return Object.assign(container.node(), { update })
}