Public
Edited
Jun 24, 2023
1 fork
Insert cell
Insert cell
Insert cell
chart = {
const svg = d3.create("svg")
.attr("width", width)
.attr("height", width / 2);

svg.append('g').call(
d3ParliamentChart.parliamentChart()
.width(width)
.aggregatedData(parliamentSeats)
.sections(4)
.sectionGap(60)
.seatRadius(12)
.rowHeight(42)
// .debug(debug)
);
return svg.node();
}
Insert cell
parties.map(e=>e.prev_perc).reduce((partialSum, a) => partialSum + a, 0);
Insert cell
parties = [{name: "Νέα Δημοκρατία", color: "#71b7ff", prev_perc: 40.79},
{name: "ΣΥΡΙΖΑ", color: "#ff93b7", prev_perc: 20.07 },
{name: "ΠΑΣΟΚ", color: "#4cc882", prev_perc: 11.46 },
{name: "ΚΚΕ", color: "#fe4c4c", prev_perc: 7.23 },
{name: "Ελληνική Λύση", color: "#d8deee", prev_perc: 4.45 },
{name: "ΝΙΚΗ", color: "#da944f", prev_perc: 2.92 },
{name: "Πλεύση Ελευθερίας", color: "#a54aa7", prev_perc: 2.89 },
{name: "ΜέΡΑ25", color: "#d24c4d", prev_perc: 2.63 },
{name: "Άλλα κομματα", color: "#a5a5a5", prev_perc: 7.56 }
]
Insert cell
calculate_edres([0.25, 0.23, 0.22, 0.2, 0.05, 0.02, 0.02, 0.01])
Insert cell
function calculate_edres(list_of_perc){
// let list_of_perc = [0.3, 0.2, 0.2, 0.2, 0.05, 0.02, 0.02, 0.01]
const max_perc = Math.max(...list_of_perc)
let bonus = 0
if (max_perc>=0.25){
bonus = Math.min(20 + (max_perc-0.25)*100*2, 50)
}
const analogikes_edres = 300-bonus
const sum_of_perc_in_parliament = list_of_perc.filter(e => e>=0.03).reduce((partialSum, a) => partialSum + a, 0);
return list_of_perc.map(e => e>=0.03? Math.round(e/sum_of_perc_in_parliament * analogikes_edres) : 0)
}
Insert cell
d3ParliamentChart = require('d3-parliament-chart');
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