Module:Sandbox/Julio974fr/parliament diagram explained

local p =

local parliament_diagram = require('Module:Parliament diagram')local positions = require('Module:Sandbox/Julio974fr/positions')

local function insertPartyPosition(partiesPositions, party, year) if party.seats <= 0 then return partiesPositions end local partyAttributes = if not party.partyArticle then partyAttributes.color = party.color end table.insert(partiesPositions, partyAttributes) return partiesPositionsend

local function getpartiesPositions(partiesData, year) local partiesPositions = for _, party in ipairs(partiesData) do insertPartyPosition(partiesPositions, party, year) end return partiesPositionsend

local function sortPartiesPositions(partiesPositions) local function comparePartiesByPosition(partyA, partyB) if partyA.position < partyB.position then return true else return false end end table.sort(partiesPositions, comparePartiesByPosition) return partiesPositionsend

function p.makeParliamentDiagram(partiesData, year) -- 1. Get the positions for each party local partiesPositions = getpartiesPositions(partiesData, year) -- 2. Sort the new array by positions local partiesPositions = sortPartiesPositions(partiesPositions) -- 3. Get the parliament diagram made local partiesPositionsIndexed = for i, v in ipairs(partiesPositions) do partiesPositionsIndexed['p'..i] = v.name partiesPositionsIndexed['n'..i] = v.seats partiesPositionsIndexed['c'..i] = v.color end partiesPositionsIndexed.background = '#F8F9FA' return parliament_diagram._parliament(partiesPositionsIndexed)end

return p