Plot3 = {
const height = 500;
const margin = 20;
const svg = d3.create("svg").attr("width", width).attr("height", height);
svg.append('defs').append('marker').attr('id','arrowhead').attr('markerWidth',10).attr('markerHeight',7).attr('refX',10).attr('refY',3.5).attr('orient','auto').append('polygon').attr('points','0 0, 10 3.5, 0 7')
svg
.append("rect")
.attr("width", width)
.attr("height", width)
.attr("fill", "#aaaaaa");
svg
.selectAll(".lines")
.data(TimeSpentData)
.enter()
.append("line")
.attr("x1", (d) => dbXScale(d[2019]))
.attr("x2", (d) => dbXScale(d[2019]))
.attr("y1", (d) => dbYScale(d.Activity))
.attr("y2", (d) => dbYScale(d.Activity))
.attr('class','lines')
.attr('stroke-width',3)
.attr("stroke", "purple")
.attr("marker-end", "url(#endarrow)")
;
svg
.selectAll(".dots2020")
.data(TimeSpentData)
.enter()
.append("circle")
.attr("cx", (d) => dbXScale(d[2019]))
.attr("cy", (d) => dbYScale(d.Activity))
.attr('class','dots2020')
.attr("r", 3)
.attr("fill", "red");
svg
.selectAll(".dots2019")
.data(TimeSpentData)
.enter()
.append("circle")
.attr("cx", (d) => dbXScale(d[2019]))
.attr("cy", (d) => dbYScale(d.Activity))
.attr("r", 3)
.attr('class','dots2019')
.attr("fill", "blue")
svg.append('rect')
.attr('x',width - 8*margin)
.attr('y',height/2)
.attr('width',100)
.attr('height',20)
.attr('fill','coral')
.on('click', (e,d) => {
svg
.selectAll(".dots2020")
.data(TimeSpentData)
.transition()
.duration(2000)
.attr("r", 6)
.transition()
.duration(2000)
.attr("cx", (d) => dbXScale(d[2020]))
.transition()
.duration(2000)
.attr("r", 3)
svg
.selectAll(".lines")
.data(TimeSpentData)
.transition()
.delay(2000)
.duration(2000)
.attr("x2", (d) => dbXScale(d[2020]))
})
return svg.node();
}