Published
Edited
Dec 7, 2021
6 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
sourceDepartements = 'https://www.data.gouv.fr/fr/datasets/r/5c4e1452-3850-4b59-b11c-3dd51d7fb8b5'
Insert cell
sourceFrance = 'https://www.data.gouv.fr/fr/datasets/r/f335f9ea-86e3-4ffa-9684-93c009d5e617'
Insert cell
rawDepartments = d3.csv(sourceDepartements)
Insert cell
rawFrance = d3.csv(sourceFrance)
Insert cell
variables = {
let keys = Object.keys(rawDepartments[0])

/*
Données contextuelles

'date' = Date
'dep'= Département
'reg'= Région
'lib_dep'= libellé département
'lib_reg'= libellé région
*/
let hide = [ 'date', 'dep', 'reg', 'lib_dep', 'lib_reg' ]
return keys.filter(e=> !hide.includes(e))
}
Insert cell
md`## Functions`
Insert cell
// draw time axis
TimeAxis({
interval,
start,
stop,
width
})
Insert cell
interval = d3.utcDay.every(1)
Insert cell
stop = new Date(d3.max(rawDepartments, d => d.date))
Insert cell
start = new Date(d3.min(rawDepartments, d => d.date))
Insert cell
deptTimeChart('91','pos_7j')
Insert cell
d3.map(rawDepartments.filter(d => d.dep == '91'), d => {
return {
date: new Date(d['date']),
value: d['conf_j1']
}
})
Insert cell
varByDepartements = d3.group(rawDepartments, d => d.dep)
Insert cell
function deptTimeChart(departement, variable){
let data = d3.map(rawDepartments.filter(d => d.dep == departement), d => {
return {
date: new Date(d['date']),
value: parseFloat(d[variable])
}
})
return TimeChart(
data,
{
interval,
start,
stop,
width,
//band: 3,
title: `${varByDepartements.get(departement)[0]['lib_dep']} (${departement})`,
// max: d3.max(rawDepartments, d => parseFloat(d[variable])),
scheme: "reds"
})
}
Insert cell
franceTimeChart('tx_incid')
Insert cell
function franceTimeChart(variable){
let data = d3.map(rawFrance, d => {
return {
date: new Date(d['date']),
value: parseFloat(d[variable])
}
})
return TimeChart(
data,
{
interval,
start,
stop,
width,
//band: 3,
title: 'France',
// max: d3.max(rawDepartments, d => parseFloat(d[variable])),
scheme: "reds"
})
}
Insert cell
varByDepartements.get('91')
Insert cell
d3 = require('d3')
Insert cell
import { TimeAxis, TimeChart } from "@observablehq/timechart"
Insert cell
import {Select} from "@observablehq/inputs"
Insert cell
import {datasetCard} from '@taniki/datagouvfr-oembed'
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