Published
Edited
Sep 28, 2020
Insert cell
md`# Coronavirus map per country
Confirmed cases

JHU modified data structure on 24.03.2020

Data as per ${llave}

Source: Johns Hopkins University`
Insert cell
chart = {
// create SVG element
var svg = d3.select(DOM.svg(width, height));

// construct the element
svg
.append('path')
.datum(countries)
.attr('d', pathGenerator)
.attr('class', 'country')
.attr('fill', 'gray')
.attr('opacity', 0.5)
.attr('stroke', 'black')
.attr('stroke-width', '0.5');

var circles = svg
.selectAll('path')
.data(LatLngs)
.enter()
.append('circle');

circles
.attr("cx", d => d[2][0])
.attr("cy", d => d[2][1])
.attr('r', d => Math.cbrt(d[3]) / 9)
.attr('class', 'circle')
.attr("fill", "#d60f23")
.attr('opacity', 0.3)
.on("click", function(d) {
div
.transition()
.duration(200)
.style("opacity", .9);
div
.html(
"<b>COUNTRY: </b>" +
d[0] +
"<br/><b>REGION: </b>" +
d[1] +
"</br><b>CONFIRMED CASES: </b>" +
d[3] +
"</br>AS OF " +
llave
)
.style("left", d3.event.pageX + "px")
.style("top", d3.event.pageY - 28 + "px");
})
.on("mouseout", function(d) {
div
.transition()
.duration(500)
.style("opacity", 0);
});

// pass to Observable to draw this block
return svg.node();
}
Insert cell
Insert cell
import { callout } from "@d3/line-chart-with-tooltip"
Insert cell
claves = Object.keys(dataraw[0]).slice(4)
Insert cell
html`<style>div.tooltip {position: absolute; text-align: left; width: 200px; height: 75px; padding: 15px;font: 14px calibri; background: #d60f23; color: white; border: 2px; border-radius: 8px; pointer-events: none;} </style>`
Insert cell
(Object.size = function(obj) {
var size = 0,
key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
})
Insert cell
ix = Object.size(dataraw[0]) - 1
Insert cell
llave = Object.keys(dataraw[0])[ix]
Insert cell
Secret('Mapbox')
Insert cell
{
for (var i = 0; i <= factor; i++) {
var LatLngElement = [
dataraw[i]['Country/Region'],
dataraw[i]['Province/State'],
projection([parseFloat(dataraw[i].Long), parseFloat(dataraw[i].Lat)]),
+dataraw[i][llave]
];
LatLngs[i] = LatLngElement;
}
}
Insert cell
div = d3
.select("body")
.append("div")
.attr("class", "tooltip")
.style("opacity", 0)
Insert cell
Insert cell
factor = dataraw.length - 1
Insert cell
format = d => `${d}`
Insert cell
Insert cell
populationin = d3.json(
"https://raw.githubusercontent.com/fullergalway/covid19js/master/dist/population.json"
)
Insert cell
populationout = Object.entries(populationin)
Insert cell
filtro = populationout.filter(name => {
return d => d.name;
})
Insert cell
populationout[0][1].name
Insert cell
dataraw[0]['Country/Region'].confirmed
Insert cell
nombres = {
for (var f = 0; f <= populationout.length - 1; f++) {
var name = populationout[f][1].name;
names.push(name);
}
}
Insert cell
names = []
Insert cell
{
for (var e = 0; e <= populationout.length - 1; e++) {
for (var i = 0; i <= LatLngs.length - 1; i++) {
if (populationout[e][1].name == LatLngs[i][0]) {
if (LatLngs[i][1] == "") {
var casos = +LatLngs[i][3];
var poblacion = populationout[e][1].totalPop;
var pais = LatLngs[i][0];

var rate = forrate(casos, poblacion);
}
}
}
rates.push({
country: pais,
cases: casos,
population: poblacion,
rate: rate
});
}
}
Insert cell
rates1 = []
Insert cell
rates = []
Insert cell
populationout[0][1].totalPop
Insert cell
typeof forrate(populationout[0][1].totalPop)
Insert cell
forrate(LatLngs[19][3], populationout[19][1].totalPop)
Insert cell
forrate = function(a, b) {
var rate = a / b / 10;
return rate;
}
Insert cell
topojson = require("topojson-client@3")
Insert cell
path = d3.geoPath().projection(projection)
Insert cell
pathGenerator = d3.geoPath().projection(projection)
Insert cell
height = 720
Insert cell
projection = d3
.geoMercator()
.scale(150)
.translate([width / 2, height / 1.5])
Insert cell
width = 980
Insert cell
d3gr = require("d3-array@^2.2")
Insert cell
d3 = require("d3@5")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more