Ero sivun ”Moduuli:Paikkataulukko” versioiden välillä

Wikipediasta
Siirry navigaatioon Siirry hakuun
Poistettu sisältö Lisätty sisältö
(ei mitään eroa)

Versio 21. huhtikuuta 2017 kello 16.21

Tämän moduulin ohjeistuksen voi tehdä sivulle Moduuli:Paikkataulukko/ohje

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 partiet = require('Modul:Partier fi')
 
    text = mw.text.tag( 'th', {style="width:4em;"}, mw.text.tag('span', {style = "cursor: help; border-bottom: 1px dotted;", title = 'Valåret'}, 'Valår') )
 
    local i = 1
 
    while args[i] and args[i] ~= '' do
        local kort = args[i]
        frame.args = { kort }
        local vector = partiet.partisnack(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="Grafisk presentation av mandatfördelning och valdeltagande"}, 'Grafisk presentation, mandat och valdeltagande')
    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="Totalt antal mandat"}, "TOT")
    text = text .. mw.text.tag('th', {style="width:2.1em;"}, t4)
    t4 = mw.text.tag('span',{style="cursor: help; border-bottom: 1px dotted;", title="Valdeltagande"}, '%')
    text = text .. mw.text.tag('th', {style="width:2.5em;"}, t4)
    t4 = mw.text.tag('span',{style="cursor: help; border-bottom: 1px dotted;", title="Könsfördelning av ledamöter, män/kvinnor"}, "Könsfördelning ([[Man|M]]/[[Kvinna|K]])")
    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 partiet = require('Modul:Partier fi')
    local bredd = args.bredd
    if bredd == nil then
    	bredd = '400'
    end
    local sum = args[2]
    local valdelt = args.valdelt or ''
    local valdelt2 = tonumber(valdelt)
    local y = ''
    if valdelt2 == nil then
        local y1 = string.find(valdelt, ',')
        if y1 then
            valdelt2 = string.sub(valdelt,1,y1-1).. '.' .. string.sub(valdelt,y1+1,string.len(valdelt))
        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 = partiet.partisnack(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 valdelt2 ~= 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="Valdeltagande: " .. valdelt .. "%", style="padding:0;background-color:#b0b0b0;height:4px;width:" .. math.floor(tonumber(bredd)*valdelt2/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 'Hej'
end
 
function mqstapel(tot, kvinnor, tom)
 
    local stylus = 'padding:0;border:0;background:#C0C0FF;width:' .. math.floor(120*(tot-tom-kvinnor)/tot) .. 'px;'
    local d = ''
    if 120*(tot-tom-kvinnor) > 16 then
        d = tostring(tot-tom-kvinnor)
    end
    local text = mw.text.tag('td', {style=stylus, title = tostring(tot-tom-kvinnor)}, 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 kvinnor ~= 0 then
       stylus = 'padding:0;border:0;background:#FFC0C0;width:' .. math.floor(120*kvinnor/tot) .. 'px;'
       d = ''
       if 120*kvinnor/tot > 16 then
           d = tostring(kvinnor)
       end
       text = text .. mw.text.tag('td', {style=stylus, title = tostring(kvinnor)}, 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 valdelt = args.valdelt 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;"}, 'FEL ANTAL MANDAT'))
    end
    text = text .. mw.text.tag('td', {}, args[2])
    if valdelt ~= nil then
        text = text .. mw.text.tag('td', {}, valdelt)
    else
    	text = text .. mw.text.tag('td', {}, '')
    end
    if args.kvinnor ~= nil and args.kvinnor ~= '' then
        text = text .. mw.text.tag('td', {}, mqstapel(tonumber(args[2]), tonumber(args.kvinnor), 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;"}, "Data hämtat från <i>[http://pxnet2.stat.fi/PXWeb/pxweb/sv/StatFin/StatFin__vaa__kvaa/?rxid=2e71e7bb-f33f-4b22-bf59-24ebb2e5597c Statistikcentralen]</i> och <i>[http://www.doria.fi/handle/10024/88401 Doria.fi, Statistikcentralens digitaliserade historiska statistik]</i>")
    text = text .. mw.text.tag('tr', {}, t)
    return text
end
 
return p