From 821a3f94e5a46b46c4da0b50b3b2349fcd573e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Thu, 28 Sep 2023 21:49:31 +0200 Subject: [PATCH] Sort commitees by ideology --- src/data.ts | 13 +++++++++++-- src/display.ts | 13 +++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/data.ts b/src/data.ts index e2563ee..a042c2e 100644 --- a/src/data.ts +++ b/src/data.ts @@ -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', diff --git a/src/display.ts b/src/display.ts index e7251ff..a3ec149 100644 --- a/src/display.ts +++ b/src/display.ts @@ -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);