Zum Inhalt springen

Modul:Infobox Wahl

aus Wikipedia, der freien Enzyklopädie

Die Dokumentation für dieses Modul kann unter Modul:Infobox Wahl/Doku erstellt werden

local p = {}
local farbe = require('Modul:Partei').farbe
local hellere = require('Modul:Partei').hell
local sitze = require('Modul:Partei').parteisitze
local alt = require('Modul:Partei').alt
local erste = require('Modul:Verwaltungseinheit').erste
local erstelink = require('Modul:Verwaltungseinheit').erstelink
local zweite = require('Modul:Verwaltungseinheit').zweite
local zweitelink = require('Modul:Verwaltungseinheit').zweitelink
local dritte = require('Modul:Verwaltungseinheit').dritte
local drittelink = require('Modul:Verwaltungseinheit').drittelink
local vierte = require('Modul:Verwaltungseinheit').vierte
local viertelink = require('Modul:Verwaltungseinheit').viertelink
local getArgs = require('Modul:Arguments').getArgs

local function form(num)
	return (tonumber(num) and mw.getLanguage('de'):formatNum(tonumber(num))) or '–'
end

function p.gewahlt(frame)
	local args = getArgs(frame)
	if args['align'] then option = '<div style="text-align:'..args['align']..'">' close = '</div>' else option = '<span style="padding-left:0.6em">' close = '</span>' end
	if args[1] == 'N' then color = 'FF4A45' line = 'E30000' text = 'nicht&nbsp;gewählt'
		else color = args['farbe'] or '4BBD71' line = args['border'] or '3A9157' text = args[1] or 'gewählt'
	end
	return ''..option..'<span style="background-color:#'..color..';padding-left:6px;padding-right:6px;padding-top:1px;padding-bottom:1px;line-height:8px;border-radius:4px 4px 4px;font-size:80%;border:0.1px solid #'..line..';text-align:center;font-weight:bold;color:#FFFFFF;">'..text..'</span>'..close
end

function p.mandate(frame)
	local args = getArgs(frame)
	local index, data = {}, {}
	local num = 1
	local gesamt = 0
	local i = 0
	for a = 1, 30 do i = i + 1
		if args['m'..i] then table.insert(index, i) end
	end
	while (args['m'..num]) do
		data[num] = {
			s = tonumber(args['m'..num]),
		}				
		gesamt = gesamt + data[num].s
		num = num+1
	end	
	
	local root = mw.html.create('table'):addClass('wikitable'):css('margin-top', '2px'):css('margin-bottom', '1px')
	for k, v in ipairs(index) do
		rwo = root:tag('tr')
		if args['l'..v] then
			rwo:tag('td')
				:wikitext(args['l'..v])
				:css('text-align', 'left')
				:css('width', '45%')
				:css('border-bottom', '0.1px solid #C0C0C0')
				:css('border-right', '0.1px solid #F0F0F0')
			rwo:tag('td')
				:wikitext('<div style="width:100px;border:0.1px solid #D0D0D0;background-color:#FFF;height:1.2em;position:relative;"><div style="background-color:#' ..farbe({(args['l'..v])})..';width:'.. args['m'..v]*100/gesamt ..'px;height:1.2em"></div></div>')
				:css('border-bottom', '0.1px solid #C0C0C0')
				:css('border-right', '0.1px solid #F0F0F0')
			rwo:tag('td')
				:wikitext(args['m'..v]..' / '..gesamt)
				:css('border-bottom', '0.1px solid #C0C0C0')
		end
	end
end

local function konv(w)
	local t = w
	local x = mw.ustring.find(t, '%,')
	if x then
	y = mw.ustring.sub(t, 1, x-1)
	z = mw.ustring.sub(t, x+1, x+1)
	return tonumber(y) + 0.1*tonumber(z) else return t end
end

function p.bar(frame)
	local args = getArgs(frame)
	local index, data = {}, {}
	local num = 1
	local i = 0
	for a = 1, 30 do i = i + 1
		if args['prozent'..i] or args['prozentz'..i] then table.insert(index, i) end
	end

	maxvalue = args['prozentz1'] and konv(args['prozentz1']) or konv(args['prozent1'])
	
	if args['zeile'] == '1' then zeile = true end
	sep = zeile and '<br/>' or '&#32;'
	
	local root = mw.html.create('table'):css('border-collapse', 'collapse')
	
	for k, v in ipairs(index) do
		if args['kandidat'..v] then
			rwo = root:tag('tr'):css('border-bottom', '1px solid silver')		
			color = farbe({args['partei'..v]})
			colour = hellere({col = color, h = 0.4})
			breite = konv(args['prozent'..v])*100/maxvalue
			breitez = args['prozentz'..v] and konv(args['prozentz'..v])*100/maxvalue
			erste = '<div style="margin-left:-0.1em;border-top:0.1px solid #D0D0D0;border-bottom:0.1px solid #D0D0D0;border-right:0.1px solid #D0D0D0;background-color:#'..(args['prozentz'..v] and colour or color)..';width:'..breite..'px;min-width:1px;height:'..(args['prozentz'..v] and '1.4' or (zeile and '1.8' or 1.5))..'em;'..(args['prozentz'..v] and 'margin-top:0.1em' or '')..'"><div class="hintergrundfarbe1" style="word-wrap:normal;margin-left:'..(breite + 10)..'px">'..args['prozent'..v]..'</div></div>'
			zweite = args['prozentz'..v] and '<div style="margin-left:-0.1em;border-top:0.1px solid #D0D0D0;border-bottom:0.1px solid #D0D0D0;border-right:0.1px solid #D0D0D0;background-color:#'..color..';width:'..breitez..'px;min-width:1px;height:1.4em"><div class="hintergrundfarbe1" style="word-wrap:normal;margin-left:'..(breitez + 10)..'px">'..args['prozentz'..v]..'</div></div>'
			rwo:tag('td')
				:wikitext(args['kandidat'..v]..sep..'('..args['partei'..v]..')')
				:css('line-height', '1.2em')
				:css('text-align', 'left')
				:css('max-width', '250px')
				:css('padding-top', '0.3em')
				:css('padding-bottom', '0.2em')
				:css('padding-right', '0.8em')
				:css('border-right', '0.1px solid #D0D0D0')
			rwo:tag('td')
				:wikitext((args['prozentz'..v] and zweite or '')..erste)
				:css('padding-top', '0.3em')
				:css('padding-bottom', '0.2em')

		end
	end
	rwo = root:tag('tr'):css('border-top', '0.1px solid silver')
		if args['sonstige'] then
			breites = konv(args['sonstige'])*100/maxvalue
			rwo:tag('td')
				:wikitext('Sonstige'..(args['ak'] and ' < '..args['ak']..' %' or ''))
				:css('text-align', 'left')
				:css('padding-right', '0.4em')
				:css('padding-top', '0.3em')
				:css('padding-bottom', '0.2em')
				:css('border-right', '0.1px solid #D0D0D0')
			rwo:tag('td')
				:wikitext('<div style="margin-left:-0.1em;border-top:0.1px solid #D0D0D0;border-bottom:0.1px solid #D0D0D0;border-right:0.1px solid #D0D0D0;background-color:#DABAD0;width:'..breites..'px;min-width:1px;height:1.5em;"><div class="hintergrundfarbe1" style="word-wrap:normal;margin-left:'..(breites + 10)..'px">'..args['sonstige']..'</div></div>')
				:css('padding-top', '0.3em')
				:css('padding-bottom', '0.2em')
				:css('width', '140px')
		end
		
	local roos = mw.html.create('table'):addClass('wikitable')
		if args['titel'] then
			ros = roos:tag('tr') 
				ros:tag('th')
					:wikitext(args['titel'])
		end
		ros = roos:tag('tr') 
			ros:tag('td')
				:wikitext(tostring(root))
				:css('position', 'relative')
			
	return tostring(roos)
end

function p.tab(frame)
	local args = getArgs(frame)
	cspan = args['stimmen3'] and 4 or args['stimmen2'] and 3 or 2
	cpan = cspan - 1
	if args['stimmen3'] and (args['stimmenz3'] or not args['stimmenz1']) then spaltedrei = true end
	
	local root = mw.html.create('table'):css('clear', 'left'):css('float', 'right'):css('text-align', 'center'):css('font-size', '96%'):css('border', '0.1px solid silver'):css('border-collapse', 'collapse')
	row = root:tag('tr')
		row:tag('td')
			:wikitext(args['name'] or mw.title.getCurrentTitle().prefixedText)
			:css('background-color', '#CCF')
			:css('text-align', 'center')
			:css('font-weight', 'bold')
			:css('min-width', '20em')
			:css('font-size', '106%')
			:attr('colspan', cspan)

		row = root:tag('tr'):css('border-bottom', '0.1px solid #E6E6E6')
			row:tag('td')
				:wikitext('Staat')
				:css('font-weight', 'bold')
				:css('text-align', 'left')
				:css('background-color', 'rgb(170 170 170 / 0.1)')
				:css('color', 'var(--color-base, #202122)')
				:css('padding-left', '3px')
				:css('min-width', '110px')
			row:tag('td')
				:wikitext(frame:expandTemplate{title = args['staat']} or '')
				:attr('colspan', cpan)
				:css('text-align', 'left')
				:css('min-width', '110px')
		
		if args['einheit1'] then
			row = root:tag('tr'):css('border-bottom', '0.1px solid #E6E6E6')			
				row:tag('td')
					:wikitext(args['ebene1'] or erste({args['staat'], args['einheit1']}))
					:css('font-weight', 'bold')
					:css('text-align', 'left')
					:css('background-color', 'rgb(170 170 170 / 0.1)')
					:css('color', 'var(--color-base, #202122)')
					:css('padding-left', '3px')
				row:tag('td')
					:wikitext(args['ebene1'] and args['einheit1'] or erstelink({args['staat'], args['einheit1']}))
					:attr('colspan', cpan)
					:css('text-align', 'left')
		end
		if args['einheit2'] then
			row = root:tag('tr'):css('border-bottom', '0.1px solid #E6E6E6')
				row:tag('td')
					:wikitext(args['ebene2'] or zweite({args['staat'], args['einheit2'], args['einheit1']}))
					:css('font-weight', 'bold')
					:css('text-align', 'left')
					:css('background-color', 'rgb(170 170 170 / 0.1)')
					:css('color', 'var(--color-base, #202122)')
					:css('padding-left', '3px')
				row:tag('td')
					:wikitext(args['ebene2'] and args['einheit2'] or zweitelink({args['staat'], args['einheit2'], args['einheit1']}))
					:attr('colspan', cpan)
					:css('text-align', 'left')
		end
		if args['einheit3'] then
			row = root:tag('tr'):css('border-bottom', '0.1px solid #E6E6E6')
				row:tag('td')
					:wikitext(args['ebene3'] or dritte({args['staat'], args['einheit3'], args['einheit1']}))
					:css('font-weight', 'bold')
					:css('text-align', 'left')
					:css('background-color', 'rgb(170 170 170 / 0.1)')
					:css('color', 'var(--color-base, #202122)')
					:css('padding-left', '3px')
				row:tag('td')
					:wikitext(args['ebene3'] and args['einheit3'] or drittelink({args['staat'], args['einheit3'], args['einheit1']}))
					:attr('colspan', cpan)
					:css('text-align', 'left')
		end
		if args['einheit4'] then
			row = root:tag('tr'):css('border-bottom', '0.1px solid #E6E6E6')
				row:tag('td')
					:wikitext(args['ebene4'] or vierte({args['staat'], args['einheit4'], args['einheit1']}))
					:css('font-weight', 'bold')
					:css('text-align', 'left')
					:css('background-color', 'rgb(170 170 170 / 0.1)')
					:css('color', 'var(--color-base, #202122)')
					:css('padding-left', '3px')
				row:tag('td')
					:wikitext(args['ebene4'] and args['einheit4'] or viertelink({args['staat'], args['einheit4'], args['einheit1']}))
					:attr('colspan', cpan)
					:css('text-align', 'left')
		end
		if args['datum'] then
			row:tag('tr')
			row = root:tag('tr'):css('border-bottom', '0.1px solid #E6E6E6')
				row:tag('td')
					:wikitext('Datum')
					:css('font-weight', 'bold')
					:css('text-align', 'left')
					:css('background-color', 'rgb(170 170 170 / 0.1)')
					:css('color', 'var(--color-base, #202122)')
					:css('padding-left', '3px')
				row:tag('td')
					:wikitext((args['datumz'] and '1. Wahlgang: ' or '')..args['datum']..(args['datumz'] and '<br/>2. Wahlgang: '..args['datumz']..'' or ''))
					:attr('colspan', cpan)
					:css('text-align', 'left')
		end
		if args['wahlbeteiligung'] then
			row = root:tag('tr'):css('border-bottom', '0.1px solid #E6E6E6')
				row:tag('td')
					:wikitext('Wahlbeteiligung')
					:css('font-weight', 'bold')
					:css('text-align', 'left')
					:css('background-color', 'rgb(170 170 170 / 0.1)')
					:css('color', 'var(--color-base, #202122)')
					:css('padding-left', '3px')
				row:tag('td')
					:wikitext((args['wahlbeteiligungz'] and '1. Wahlgang: ' or '')..args['wahlbeteiligung']..' %'..(args['wahlbeteiligungz'] and '<br/>2. Wahlgang: '..args['wahlbeteiligungz']..' %' or ''))
					:attr('colspan', cpan)
					:css('text-align', 'left')
		end
		if args['kandidat1'] and args['stimmen1'] then
			if args['bild1'] or args['bild2'] or args['bild3'] then
			row = root:tag('tr')
					row:tag('td')
					row:tag('td')
					:wikitext(args['bild1'] and '[[Datei:'..args['bild1']..'|'..(spaltedrei and '112x150' or '140x185')..'px]]' or '')
				if args['kandidat2'] then
					row:tag('td')
						:wikitext(args['bild2'] and '[[Datei:'..args['bild2']..'|'..(spaltedrei and '112x150' or '140x185')..'px]]' or '')
				end
				if spaltedrei then
					row:tag('td')
						:wikitext(args['bild3'] and '[[Datei:'..args['bild3']..'|112x150px]]' or '')
				end
			end
			row = root:tag('tr')
				row:tag('td')
				row:tag('td')
					:css('background-color', '#'..(args['farbe1'] or farbe({args['koalition1'] or args['partei1']})))
					:css('height', '4px')
					:css('width', (spaltedrei and '110' or '138')..'px')
				if args['kandidat2'] then
					row:tag('td')
						:css('background-color', '#'..(args['farbe2'] or farbe({args['koalition2'] or args['partei2']})))
						:css('height', '4px')
						:css('width', (spaltedrei and '110' or '138')..'px')
				end
				if spaltedrei then
					row:tag('td')
						:css('background-color', '#'..(args['farbe3'] or farbe({args['koalition3'] or args['partei3'] or args['p3']})))
						:css('height', '4px')
						:css('width', '110px')
				end
			row = root:tag('tr'):css('border-bottom', '0.1px solid #E6E6E6')
				row:tag('td')
					:wikitext('Kandidaten')
					:css('font-weight', 'bold')
					:css('text-align', 'left')
					:css('background-color', 'rgb(170 170 170 / 0.1)')
					:css('color', 'var(--color-base, #202122)')
					:css('padding-left', '3px')
				row:tag('td')
					:wikitext(args['kandidat1'])
					:css('height', '4px')
					:css('max-width', (spaltedrei and '112' or '140')..'px')
				if args['kandidat2'] then
					row:tag('td')
						:wikitext(args['kandidat2'])
						:css('height', '4px')
						:css('max-width', (spaltedrei and '112' or '140')..'px')
				end
				if spaltedrei then
					row:tag('td')
						:wikitext(args['kandidat3'])
						:css('max-width', '112px')
				end
			if args['stellvertreter1'] then
				row = root:tag('tr'):css('border-bottom', '0.1px solid #E6E6E6')
					row:tag('td')
						:wikitext('Stellvertreter')
						:css('font-weight', 'bold')
						:css('text-align', 'left')
						:css('background-color', 'rgb(170 170 170 / 0.1)')
						:css('color', 'var(--color-base, #202122)')
						:css('padding-left', '3px')
					row:tag('td')
						:wikitext(args['stellvertreter1'])
					if args['stellvertreter2'] then
						row:tag('td')
							:wikitext(args['stellvertreter2'])
					end
					if spaltedrei then
						row:tag('td')
							:wikitext(args['stellvertreter3'])
					end
			end
			if args['partei1'] then
				row = root:tag('tr'):css('border-bottom', '0.1px solid #E6E6E6')
					row:tag('td')
						:wikitext('Parteien')
						:css('font-weight', 'bold')
						:css('text-align', 'left')
						:css('background-color', 'rgb(170 170 170 / 0.1)')
						:css('color', 'var(--color-base, #202122)')
						:css('padding-left', '3px')
					row:tag('td')
						:wikitext(args['partei1'])
						:css('max-width', (spaltedrei and '112' or '140')..'px')
					if args['partei2'] or args['stimmen2'] then
						row:tag('td')
							:wikitext(args['partei2'])
							:css('max-width', (spaltedrei and '112' or '140')..'px')
					end
					if spaltedrei then
						row:tag('td')
							:wikitext(args['partei3'])
							:css('max-width', '112px')
					end
			end
			if args['koalition1'] then
				row = root:tag('tr'):css('border-bottom', '0.1px solid #E6E6E6')
					row:tag('td')
						:wikitext('Koalitionen')
						:css('font-weight', 'bold')
						:css('text-align', 'left')
						:css('background-color', 'rgb(170 170 170 / 0.1)')
						:css('color', 'var(--color-base, #202122)')
						:css('padding-left', '3px')
					row:tag('td')
						:wikitext(args['koalition1'])
					if args['koalition2'] then
						row:tag('td')
							:wikitext(args['koalition2'])
					end
					if spaltedrei then
						row:tag('td')
							:wikitext(args['koalition3'])
					end
			end
			if args['stimmen1'] ~= '0' then
				row = root:tag('tr'):css('border-bottom', '0.1px solid #E6E6E6')
					row:tag('td')
						:wikitext('Stimmen'..(args['stimmenz1'] and ' –<br/> 1. Wahlgang' or ''))
						:css('font-weight', 'bold')
						:css('text-align', 'left')
						:css('background-color', 'rgb(170 170 170 / 0.1)')
						:css('color', 'var(--color-base, #202122)')
						:css('padding-left', '3px')
					row:tag('td')
						:wikitext(form(args['stimmen1'])..'<br/>'..args['prozent1']..' %')
					if args['stimmen2'] then
						row:tag('td')
							:wikitext(form(args['stimmen2'])..'<br/>'..args['prozent2']..' %')
					end
					if spaltedrei then
						row:tag('td')
							:wikitext(form(args['stimmen3'])..'<br/>'..args['prozent3']..' %')
					end
				if args['stimmenz1'] then
					row = root:tag('tr'):css('border-bottom', '0.1px solid #E6E6E6')
						row:tag('td')
							:wikitext('Stimmen –<br/>2. Wahlgang')
							:css('font-weight', 'bold')
							:css('text-align', 'left')
							:css('background-color', 'rgb(170 170 170 / 0.1)')
							:css('color', 'var(--color-base, #202122)')
							:css('padding-left', '3px')
						row:tag('td')
							:wikitext(form(args['stimmenz1'])..'<br/>'..args['prozentz1']..' %')
						if args['stimmenz2'] then
							row:tag('td')
								:wikitext(form(args['stimmenz2'])..'<br/>'..args['prozentz2']..' %')
						end
						if spaltedrei then
							row:tag('td')
								:wikitext(form(args['stimmenz3'])..'<br/>'..args['prozentz3']..' %')
						end
				end
				if args['mandate1'] then
					row = root:tag('tr'):css('border-bottom', '0.1px solid #E6E6E6')
						row:tag('td')
							:wikitext((args['staat'] == 'USA' and not args['einheit2']) and 'Wahlleute' or 'Mandate')
							:css('font-weight', 'bold')
							:css('text-align', 'left')
							:css('background-color', 'rgb(170 170 170 / 0.1)')
							:css('color', 'var(--color-base, #202122)')
							:css('padding-left', '3px')
						row:tag('td')
							:wikitext('<div align="center">'..sitze({args['mandate1'], args['gesamt'], f = args['farbe1'], (args['koalition1'] or args['partei1'])})..'</div>')
							:css('margin', 'auto')
						if args['mandate2'] then
							row:tag('td')
								:wikitext('<div align="center">'..sitze({args['mandate2'], args['gesamt'], f = args['farbe2'], (args['koalition2'] or args['partei2'])})..'</div>')
						end
						if spaltedrei then
							row:tag('td')
								:wikitext('<div align="center">'..sitze({args['mandate3'], args['gesamt'], f = args['farbe3'], (args['koalition3'] or args['partei3'])})..'</div>')
						end
				end
			end
		end
		if args['kandidat100'] then
			row:tag('tr')
				row:tag('td')
					:wikitext('Zusammenfassung der Stimmen')
					:attr('colspan', cspan)
					:css('font-weight', 'bold')
					:css('background-color', '#EBEBFF')
			row:tag('tr')
				row:tag('td')
					:wikitext(p.bar(frame))
					:attr('colspan', cspan)
		end
		if args['karte'] then
			row:tag('tr')
				row:tag('td')
					:wikitext(args['bildunterschrift'])
					:attr('colspan', cspan)
					:css('font-weight', 'bold')
					:css('background-color', '#EBEBFF')
			if args['kartez'] then
				row:tag('tr')
					row:tag('td')
						:wikitext('1. Wahlgang')
						:attr('colspan', cspan)
						:css('font-weight', 'bold')
						:css('background-color', '#F2F2F4')
			end
			row:tag('tr')
				row:tag('td')
					:wikitext('[[Datei:'..args['karte']..'|'..(args['kartenbreite'] or '270x270')..'px]]'..(args['karterechts'] and '[[Datei:'..args['karterechts']..'|'..(args['kartenbreite'] or '270x270')..'px]]' or ''))
					:attr('colspan', cspan)
			if args['kartez'] then
				row:tag('tr')
					row:tag('td')
						:wikitext('2. Wahlgang')
						:attr('colspan', cspan)
						:css('font-weight', 'bold')
						:css('background-color', '#F2F2F4')
				row:tag('tr')
					row:tag('td')
					:wikitext('[[Datei:'..args['kartez']..'|'..(args['kartenbreite'] or '270x270')..'px]]')
					:attr('colspan', cspan)
			end
		end
		if args['vorgänger'] then
			row:tag('tr')
				row:tag('td')
					:wikitext(args['amt'])
					:attr('colspan', cspan)
					:css('font-weight', 'bold')
					:css('background-color', '#EBEBFF')
			row:tag('tr')
				row:tag('td')
					:wikitext(args['vorgänger'])
					:attr('colspan', cspan)
		end
		if args['davor'] or args['nach'] then
			row:tag('tr')
				row:tag('td')
					:wikitext('<span style="float:left">← '..(args['davor'] or '-')..'</span> <span style="float:right">'..(args['nach'] or '-')..' →</span>')
					:attr('colspan', cspan)
					:css('vertical-align', 'middle')
					:css('font-weight', 'bold')
					:css('background-color', '#EBEBFF')
		end
		return root
	end
return p