Sort commitees by ideology

pull/15/head
Michał Górny 2023-09-28 21:49:31 +02:00
rodzic c1a6969fd7
commit 821a3f94e5
2 zmienionych plików z 18 dodań i 8 usunięć

Wyświetl plik

@ -29,8 +29,8 @@ export const committees: Committee[] = [
},
{
id: 'lewica',
name: 'Lewica',
shortName: 'Lew.',
name: 'Nowa Lewica',
shortName: 'NL',
threshold: 5,
pastSupportEquivalence: [['lewica', 1]],
},
@ -57,6 +57,15 @@ export const committees: Committee[] = [
},
];
export const benchSort = [
'lewica',
'ko',
'mn',
'td',
'pis',
'konfederacja',
];
export const constituencies: Constituency[] = [
{
name: 'Legnica',

Wyświetl plik

@ -1,5 +1,5 @@
import {BarChart, PieChart} from 'chartist';
import {committees, constituencies} from './data';
import {benchSort, committees, constituencies} from './data';
import calculateMandates from './mandates';
import constituencyTemplate from './templates/constituency.pug';
import tableTemplate from './templates/table.pug';
@ -89,15 +89,16 @@ const displayBarChart = (support: number[]) => {
};
const displayPieChart = (mandates: number[]) => {
const sortedMandates = committees
const commiteesWithMandates = committees
.map((c, i) => ({
id: c.id,
label: c.shortName,
mandates: {value: mandates[i], className: c.id},
}))
.filter((m) => m.mandates.value && m.mandates.value > 0)
.sort((a, b) => b.mandates.value - a.mandates.value);
.filter((m) => m.mandates.value && m.mandates.value > 0);
commiteesWithMandates.sort((a, b) => (benchSort.indexOf(a.id) > benchSort.indexOf(b.id) ? 1 : -1));
const chartData = {
series: sortedMandates.map((sm) => sm.mandates),
series: commiteesWithMandates.map((sm) => sm.mandates),
};
const chartOptions = {
donut: true,
@ -105,7 +106,7 @@ const displayPieChart = (mandates: number[]) => {
startAngle: 270,
total: 460 * 2,
labelInterpolationFnc: (value: number, index: number) => (
value < 15 ? '' : `${sortedMandates[index].label} ${value}`
value < 15 ? '' : `${commiteesWithMandates[index].label} ${value}`
),
};
return new PieChart('#division-pie-chart', chartData, chartOptions);