Published
Edited
Apr 9, 2020
2 stars
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
legendRadii = [10, 100, 1000, 10000]
Insert cell
function placeName(d) {
if (d.county === "New York City") return "New York City";
const loc = getLocation(d);
return `${loc.properties.name} ${
d.state === "Louisiana" ? "Parish" : "County"
}`;
}
Insert cell
function getLocation(d) {
let location = regionMap.get(d.subjectnam);
//if (!location && d.county === "New York City")
//location = countyMap.get("36061");
//if (!location) location = stateMap.get(d.state);
//if (!location) console.warn("No location found for: " + JSON.stringify(d));
return location;
}
Insert cell
chart1.update(index3)
Insert cell
chart.update(index2)
Insert cell
map1.update(index1)
Insert cell
map.update(index)
Insert cell
w = 975
Insert cell
h = 610
Insert cell
projection = d3.geoAlbers()
.rotate([-105, 0])
.center([-10, 65])
.parallels([52, 64])
.scale(700)
.translate([w / 2, h/ 2]);
Insert cell
albersProjection1 = {
// XXX super hacky
const proj = d3.geoAlbers()
.rotate([-105, 0])
.center([-10, 65])
.parallels([52, 64])
.scale(700)
//.translate([w / 2, h / 2]);
return function(coords) {
const [x, y] = proj(coords);
return [x + 0.06, y + 0.054];
};
}
Insert cell
maxLegend = Math.round(maxCases / magnitude) * magnitude
Insert cell
magnitude = toMagnitude(maxCases)
Insert cell
regionMap =new Map(
rus
.features.map(d => [d.properties.full_name, d])
)
Insert cell
function toMagnitude(n) {
var order = Math.floor(Math.log(n) / Math.LN10 + 0.000000001);
return Math.pow(10, order);
}
Insert cell
mutable index = 0
Insert cell
mutable index1 = 0
Insert cell
mutable index2 = 0
Insert cell
mutable index3 = 0
Insert cell
{
mutable index3 = dates.indexOf(day3);
}
Insert cell
{
mutable index2 = dates.indexOf(day2);
}
Insert cell
{
mutable index1 = dates.indexOf(day1);
}
Insert cell
{
mutable index = dates.indexOf(day);
}
Insert cell
radius = d3
.scaleSqrt()
.domain([0, maxCases])
.range([0, maxRadius])
Insert cell
colorScale = d3
.scaleSqrt()
.domain([0, maxCases])
.range([`hsla(57, 100%, 50%, 0.36)`, `hsla(7, 100%, 50%, 0.57)`])
Insert cell
delayChart=700
Insert cell
delay = 500
Insert cell
maxCases = d3.max(recentData.map(d => +d.count))
Insert cell
excludeTerritories = new Set(["Москва"])
Insert cell
//max=d3.max(tmp,d=>d.count)
Insert cell
//tmp=data[data.length - 1].sort((a, b) => +b.count - +a.count).slice(0,3)
Insert cell
data = d3
.nest()
.key(d => d.date)
.entries(rawData.filter(d => !excludeTerritories.has(d.subjectnam)))
.map(d => d.values)
.filter(d => d[0].date >= startDate)
Insert cell
//rawData = d3.csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv")
Insert cell
//rawData1=d3.csv('https://gist.githubusercontent.com/IgorGlushkov/43d125ab095e53c8cbdf2104bb1b8b51/raw')
Insert cell
rawData.forEach(d => {
d.arable = +d.arable,
d.not_arable = +d.not_arable,
d.other = +d.other,
d.count = +d.count,
d.count = isNaN(d.count) ? 0 : d.count,
d.doy = +d.doy
});
Insert cell
//rawData=d3.csv('https://igorglushkov.static.observableusercontent.com/files/831fb7416111aaac50c6b9bb2a96131de244a11972dac6ae6b1eddde61a5f85c2ac06502c45bd068ab9309246ad5ccd6d618a9d3c299393bb96f9b02e84818fb?response-content-disposition=attachment%3Bfilename*%3DUTF-8%27%27hotspots2020.csv&Expires=1585915200000&Key-Pair-Id=APKAJCHFJLLLU4Y2WVSQ&Signature=ECS6a2XhQHeVXfnFunS9WlU~eht2VAWD3LhWVsd-gWHNSyH~5gsIQneoYrhy8yWrO4wgwwP2rlaPFvDcvtWA3oI4LpHXCGAGlU2JvuM-qlgbsoUgW5IoSUrAz9LPlcb6fiAIipZSS2P77cs1qAShXkF1c8BEEE5h0mE30vgvTmuQ9~n3kdEob1b-U717qQk6M-1RQTa2rOcDTBcVKJ3RHduEfMrgBbx5qM6PKM04PFv9Z9SWvhR99NW--PUvhtmykiREa5ZucX~-lH94L0Y2XfAmUVXU3nQ8MBOdILP~OA9DvNCHTaBzln4S2tr7~JucExVXpDgp8x9TZja~~y0Txw__')
Insert cell
rawData=d3.csv('https://gist.githubusercontent.com/IgorGlushkov/43d125ab095e53c8cbdf2104bb1b8b51/raw')
Insert cell
maxRadius = 30
Insert cell
recentData = data[data.length - 1]
Insert cell
startDate = "2020-02-20"
Insert cell
dates = data.map(d => d[0].date).map(d => new Date(`${d}`))
Insert cell
cities = places.filter(d => !excludeCities.has(d.City));
Insert cell
excludeCities = new Set(["Уфа","Челябинск","Новосибирск","Ростов-на-Дону","Воронеж","Улан-Удэ"])
Insert cell
places = d3.tsv('https://gist.githubusercontent.com/IgorGlushkov/dcdc4bc9a905b5e72c3636ed991b34db/raw')
Insert cell
//places = d3.tsv('https://igorglushkov.static.observableusercontent.com/files/6298609232193183651e8a9c583773276dc0c7bd8bfcf2290cc496f0fab9130d706e2f69ffe6ea5813d4d2767dac8f03771998f624ed2226fcddf667a202c8cc?response-content-disposition=attachment%3Bfilename*%3DUTF-8%27%27cities.tsv&Expires=1585915200000&Key-Pair-Id=APKAJCHFJLLLU4Y2WVSQ&Signature=Qg~o3voFhy9PgfZU44kP9wxtlJ1rsgPzK46JLOFay-oAjdEAnnyCn~SGpbjfwwCQrwckqk6lJ1T-Bxs4-o~To46bIZytvM0738MYlk0gTWFeqGrXf2915oXiBrEBZBDnGkkaU~mY9PxnGTVIOa2xXLwVFKr5~mcsKHA086VDKIcohIou22P725ogcVfcJ8bvJ4dzYjvBnOUsxe-FYPzLampofGobupoE3l6X-NDphdnqpMY8eVtzjF62uW01mclEkPjgRtmVdj3ppBSQPGt69Kl4KT8Aq5M8xPIsQQTyKrik043TyUrVZaV37yXtT64jrQOD1ar8-0UX~zWGe4~RIw__')
Insert cell
sFormat = d3.format(".1s")
Insert cell
numFormat = d3.format("")
Insert cell
rus=d3.json('https://gist.githubusercontent.com/IgorGlushkov/ad2864b6191a4ff20ab26311765d9977/raw')
Insert cell
//rus=d3.json('https://igorglushkov.static.observableusercontent.com/files/38f6c8d959aed0ece28f86b3b0898e28dc6d1946b6ac9ad7c54ff8af6ecba61f8c574abc09c66091004cfa95686f69817311ab111c627c5d8f0994674b20056f?response-content-disposition=attachment%3Bfilename*%3DUTF-8%27%27russia_geojson_wgs84sim1.geojson&Expires=1585915200000&Key-Pair-Id=APKAJCHFJLLLU4Y2WVSQ&Signature=VgC7HtTETiSx0FpImR5PEg3nJ4O-1xLNcqDMc9tXqfug3BmzO3OUC0i5o~0eIzOBv8ThOH65s1vGx1mqUH1QwQ~oKULSvaP60iJgpFPlTak92PESuYgIT2yjJKqoXMhPTnYWn7~3VdVc3Ud3assRfeOJosum7rUeP1C64C3ebXKjSnWTDsE68p2syCn98omGlhIsuD8dok~m4113RAhJ9dzZCSQOWjFfAtCr~0c-q679XooNj6urs3Rp1gRNYiZqlhQsgFcdDELC12~G34w1~ggWgAvN6rozFB6DB7EGHSMwseo7YS2~7xj3kYDHz43g2tQ1wvvq2OxDtvtqVmFADw__')
Insert cell
Insert cell
topojson = require("topojson-client@3")
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