chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const dateFr = d => d.toLocaleString("fr-FR", {
day:'numeric',
month:'long',
})
const col_lenght = 10;
const padding_bottom = 40,
padding_left= 85,
circle_size = 5,
circle_padding = 12;
const parti_color = {
"RENAISSANCE": "#F6B923",
"MODEM" : "#ED9627",
"HORIZONS" : "#7D9BCB",
"LR" : "#1C4EA6",
"RN" : "#1D2344",
"FI" : "#E8182C",
"PS" : "#EE718A",
"ECOLOS" : "#42B38E",
"COMMUNISTES" : "#8F1F1B",
"LIOT" : "#D0B197",
"NI" : "#BBBABA"
}
svg.append("g")
.call(xAxis)
.attr('class', 'x_axis')
.classed('axis', true);
svg.append("g")
.call(yAxis)
.attr('class', 'y_axis')
.classed('axis', true);
svg.selectAll('path.domain')
.attr('stroke-width', 0)
svg.selectAll('g.x_axis g.tick line')
.attr('stroke-width', 0)
svg.selectAll('g.x_axis g.tick text')
.text(d => dateFr(d))
svg.selectAll('g.y_axis g.tick text')
.text(d => d)
svg.selectAll('g.y_axis g.tick line')
.attr('x1', -6)
.attr('x2', width)
.attr('stroke', '#ddd')
let g_bar = svg.append('g')
.selectAll('g.bar')
.data(modalites)
.enter()
.append('g')
.attr('class', d=> 'bar_' + d)
g_bar
.selectAll('circle')
.data(function (d) {
return data_par_dep.filter(e=>e.vote == d)
})
.enter()
.append('circle')
.attr('r', circle_size)
.attr('fill', function (d) {
console.log(d.vote)
return parti_color[d.parti]
})
.attr('cx', function (d,i) {
return x(d.vote) + padding_left + (i % col_lenght)*circle_padding
})
.attr('cy', function (d,i) {
return height - padding_bottom - (Math.floor(i/col_lenght)*circle_padding)
})
return svg.node();
}