Published
Edited
Apr 27, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
multiline = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width+margin.right, height])
.style("overflow", "visible");

svg.append("g").call(xAxis);
svg.append("g").call(yAxis);

const path = svg.append("g")
.attr('id', 'allpaths')
.attr("fill", "none")
.attr("stroke", colour)
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.selectAll("path")
.data(data.series)
.join("path")
.style("mix-blend-mode", "multiply")
.attr("id", d => replacePunct(d.name))
.attr("d", d => line(d.values));

svg.append('text')
.attr('x', x(data.dates.slice(-1)[0]))
.attr('y', 40)
.attr('dx', 40)
.attr('dy', '.05em')
.style('text-anchor', 'end')
.text('Confirmed and Probable Cases')
svg.call(hover, path);

// Annotation section
svg.append('rect').lower()
.attr('x', x(new Date(2020,2,24)))
.attr('y', 55)
.attr('width', x(new Date(2020,5,2)) - x(new Date(2020,2,24)))
.attr('height', y(1) - 55)
.attr('fill', '#f1f3ff')

svg.append('text')
.attr('x', x(new Date(2020,2,26)))
.attr('y', 70)
.text('Stay Home, Stay Safe')

svg.append('rect').lower()
.attr('x', x(new Date(2020,10,18)))
.attr('y', 55)
.attr('width', x(new Date(2021,1,1)) - x(new Date(2020,10,18)))
.attr('height', y(1) - 55)
.attr('fill', '#f1f3ff')

svg.append('text')
.attr('x', x(new Date(2020,10,20)))
.attr('y', 70)
.text('Pause to Save Lives')
function update(dropdown) {
d3.selectAll('path').attr('stroke-width', null)
d3.select(`#${replacePunct(dropdown)}`).raise()
.attr('stroke-width', highlightWidth)
.attr('stroke', highlightColor)
}
return Object.assign(svg.node(), {update} );
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
highlightColor = "#6a3d9a"
Insert cell
colour = "#cab2d6"
Insert cell
highlightWidth = 7
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more