tChart = (hypothese, tour) => {
let data = [...hypothese.candidats]
let plot = Plot.plot({
caption: html`
Intentions de vote pour le ${tour.tour.toLowerCase()} de l'élection présidentielle 2022<br>
${ hypothese.sous_echantillon } répondant·e·s pour un échantillon de ${ sondage.echantillon } personnes (soit ${hypothese.sous_echantillon/sondage.echantillon * 100}%)<br>
Source : <a href="https://twitter.com/nsppolls">NspPolls</a> · <a href="${ sondage.lien }">${sondage.nom_institut} ${sondage.id}</a> · Visualisation : <a href="https://twitter.com/taniki">@taniki</a>
`,
marginLeft: 150,
x: {
label: 'intentions de vote',
domain: [0, d3.max([35, ...data.map(c => c.erreur_sup)])],
nice: true,
axis:'top',
grid: true,
tickFormat: t => `${t}%`
},
y: {
axis: false,
domain: data.sort((a,b) => b.intentions - a.intentions).map(c => c.candidat)
},
marks: [
Plot.barX(data, { y: 'candidat', x1: 'erreur_inf', x2: 'erreur_sup', rx: 10}),
Plot.dot(data, { y: 'candidat', x: 'intentions', fill: 'white', stroke: 'black', r: 5}),
Plot.text(data, { y: 'candidat', x: 'erreur_inf', text: 'candidat', textAnchor: 'end', dx: -6})
]
})
return plot
}