Jump to content

Module:Mandatetable FI

From Wikipedia, the free encyclopedia
local p = {}
 
function p.start(frame)
    local pFrame = frame:getParent();
    local args = pFrame.args;
    for k,v in pairs( frame.args ) do
        args[k] = v;
    end

    local text = ''
    local party = require('Module:Parties fi')
 
    text = mw.text.tag( 'th', {style="width:4em;"}, mw.text.tag('span', {style = "cursor: help; border-bottom: 1px dotted;", title = 'Election year'}, 'Election year') )
 
    local i = 1
 
    while args[i] and args[i] ~= '' do
        local kort = args[i]
        frame.args = { kort }
        local vector = party.parties(frame) 
        if vector == nil then
             return 'ERROR'
        end
        local a = vector['a']
        local t = vector['t']
        local n = vector['n']
        local f = vector['f']
        local l = vector['l']
        local t4 = mw.text.tag('span', {style="color:" .. t .. ";"}, a)
        t4 = mw.text.tag('th', {style = "background:" .. f .. ";min-width:2.1em;max-width:2.3em;", title = n}, "[[" .. l .. "|" .. t4 .. "]]")
        text = text .. t4
        i = i + 1
    end
    i = i*2.1+60.5
 
 
    t4 = mw.text.tag('span',{style="cursor: help; border-bottom: 1px dotted;", title="Graphic representation of seat distribution and voting percentage"}, 'Graphic representation, places and voting percentage')
    text = text .. mw.text.tag('th', {style="box-sizing:content-box;width:400px;"},t4)
 
    t4 = mw.text.tag('span',{style="cursor: help; border-bottom: 1px dotted;", title="Paikkojen kokonaismäärä"}, "Yht.")
    text = text .. mw.text.tag('th', {style="width:2.1em;"}, t4)
    t4 = mw.text.tag('span',{style="cursor: help; border-bottom: 1px dotted;", title="Äänestysprosentti"}, '%')
    text = text .. mw.text.tag('th', {style="width:2.5em;"}, t4)
    t4 = mw.text.tag('span',{style="cursor: help; border-bottom: 1px dotted;", title="Valtuutettujen sukupuolijakauma, miehiä/naisia"}, "Sukupuolijakauma ([[Mies|M]]/[[Nainen|N]])")
    text = text .. mw.text.tag('th', {style="box-sizing:content-box;width:120px;"}, t4)
 
    text = mw.text.tag('tr', {}, text)
    --text = mw.text.tag('table', {class="wikitable", border="1", style="text-align:center;font-size:88%;width:" .. i .. "em;"}, text)
    return text 
 
end
 
function p.relativmandatstapel(frame)
    local pFrame = frame:getParent();
    local args = pFrame.args;
    for k,v in pairs( frame.args ) do
        args[k] = v;
    end
 
    local text = ''
    local party = require('Module:Parties fi')
    local bredd = args.bredd
    if bredd == nil then
    	bredd = '400'
    end
    local sum = args[2]
    local prosentti = args.prosentti or ''
    local prosentti2 = tonumber(prosentti)
    local y = ''
    if prosentti2 == nil then
        local y1 = string.find(prosentti, ',')
        if y1 then
            prosentti2 = string.sub(prosentti,1,y1-1).. '.' .. string.sub(prosentti,y1+1,string.len(prosentti))
        end
    end
 
    local i = 3
    while (args[i] and args[i] ~= '') or args[i+1] do
        local kort = args[i]
        frame.args = { kort }
        local vector = party.parties(frame) 
        if tonumber( args[i+1] ) == nil then
        	args[i+1] = '0'
        end
        if vector == nil then
             return 'ERROR'
        end
        local t = vector['t']
        local f = vector['f']
        local stylus = ''
        local content = ''
        if (tonumber(args[i+1]) or 0) > 0 then
            stylus = 'padding:0;border:0;background:' .. f .. ';color:' .. t .. ';width:' .. math.floor(tonumber(bredd)*tonumber(args[i+1])/tonumber(sum) + 0.5) .. 'px;'
            if tonumber(bredd)*tonumber(args[i+1])/tonumber(sum) > 16 then
            	content = args[i+1]
            end
            text = text .. mw.text.tag('td', {style = stylus, title = args[i+1]}, content)
        end
        y = text
        i = i + 2
    end
    text = mw.text.tag('tr', {}, text)
    text = mw.text.tag('table', {cellspacing="0",cellpadding="0", border="0", style="border:0;width:"..bredd.."px; text-align:center;line-height:1.3em;padding:0;"}, text)
    if prosentti2 ~= nil then
    	local div = mw.text.tag( 'div', {style="width:1px;height:4px;position:absolute;top:0;left:25%;z-index:10;background-color:#666666;"}, '')
    	div = div .. mw.text.tag('div', {style="width:1px;height:4px;position:absolute;top:0;left:50%;z-index:10;background-color:#666666;"}, '')
    	div = div .. mw.text.tag('div', {style="width:1px;height:4px;position:absolute;top:0;left:75%;z-index:10;background-color:#666666;"}, '')
    	div = div .. mw.text.tag('div', {title="Prosenttiosuus: " .. prosentti .. "%", style="padding:0;background-color:#b0b0b0;height:4px;width:" .. math.floor(tonumber(bredd)*prosentti2/100+0.5) .. "px;"}, '')
    	div = mw.text.tag('div', {style="margin:2px 0 0 0;padding:0;position:relative;height:4px;width:"..bredd.."px;"}, div)
    	text = text .. div
    end
    y = text
    return y or 'Hei'
end
 
function mqstapel(tot, naisia, tom)
 
    local stylus = 'padding:0;border:0;background:#C0C0FF;width:' .. math.floor(120*(tot-tom-naisia)/tot) .. 'px;'
    local d = ''
    if 120*(tot-tom-naisia) > 16 then
        d = tostring(tot-tom-naisia)
    end
    local text = mw.text.tag('td', {style=stylus, title = tostring(tot-tom-naisia)}, d)
    if tom ~= 0 then
       stylus = 'padding:0;border:0;background:#ffffff;width:' .. math.floor(120*tom/tot) .. 'px;'
       text = text .. mw.text.tag('td', {style=stylus, title = tostring(tom)}, '')
    end
    if naisia ~= 0 then
       stylus = 'padding:0;border:0;background:#FFC0C0;width:' .. math.floor(120*naisia/tot) .. 'px;'
       d = ''
       if 120*naisia/tot > 16 then
           d = tostring(naisia)
       end
       text = text .. mw.text.tag('td', {style=stylus, title = tostring(naisia)}, d)
    end 
    text = mw.text.tag('tr', {}, text)
    text = mw.text.tag('table', {cellspacing="0", cellpadding="0", border="0", style="border:0;width:120px; text-align:center;line-height:1.3em;padding:0;"}, text)
 
	return text
end
 
 
function p.rad(frame)
    local pFrame = frame:getParent();
    local args = pFrame.args;
    for k,v in pairs( frame.args ) do
        args[k] = v;
    end
    local text = ''
    text = text .. mw.text.tag('td', {}, args[1])
    local i = 3
    local u = 0
    local prosentti = args.prosentti or ''
 
    while tonumber(args[i+1]) ~= nil do
        local t = ''
        if tonumber(args[i+1]) > 0 then
            t = args[i+1]
        end
        text = text .. mw.text.tag('td', {}, t)
        u = u + tonumber(args[i+1])
        i = i + 2
    end
 
    if u == tonumber(args[2]) then
        text = text .. mw.text.tag('td', {}, p.relativmandatstapel(frame))
    else
        text = text .. mw.text.tag('td', {}, mw.text.tag('span', {style="color:red;"}, 'ERROR_IN_LOCATION'))
    end
    text = text .. mw.text.tag('td', {}, args[2])
    if prosentti ~= nil then
        text = text .. mw.text.tag('td', {}, prosentti)
    else
    	text = text .. mw.text.tag('td', {}, '')
    end
    if args.naisia ~= nil and args.naisia ~= '' then
        text = text .. mw.text.tag('td', {}, mqstapel(tonumber(args[2]), tonumber(args.naisia), tonumber(args.tom) or 0))
    else
    	text = text .. mw.text.tag('td', {}, '')
    end
    text = mw.text.tag('tr', {}, text)
 
    return text
end

function p.n(frame)
    local pFrame = frame:getParent();
    local args = pFrame.args;
    local i = 1
    while args[i] ~= nil do
        i = i + 1
    end
    local h = 2.1 * i + 58.4
    return h .. ''
end

function p.slut(frame)
    local pFrame = frame:getParent();
    local args = pFrame.args;
    local text = ''
    if args[1] ~= nil then
        local i = 2
        while args[i] ~= nil do
            text = text .. mw.text.tag('br') .. args[i]
            i = i + 1
        end
        text = mw.text.tag('td', {colspan="100", style="text-align:left;"}, args[1] .. text)
        text = mw.text.tag('tr', {}, text)
    end
    local t = mw.text.tag('td', {colspan="100", style="text-align:left;background:#eeeeee;"}, "Tiedot ovat peräisin <i>[http://pxdata.stat.fi/PXWeb/pxweb/fi/StatFin/StatFin__vaa__kvaa/?rxid=2e71e7bb-f33f-4b22-bf59-24ebb2e5597c Tilastokeskuksesta]</i> sekä <i>[http://www.doria.fi/handle/10024/88401 Kansalliskirjaston julkaisuarkisto Doriasta]</i>")
    text = text .. mw.text.tag('tr', {}, t)
    return text
end
 
return p