Modul:Achsendiagramm
Die Dokumentation für dieses Modul kann unter Modul:Achsendiagramm/Doku erstellt werden
local p = {}
local getArgs = require('Module:Arguments').getArgs
local function fnum(a)
return (a and tonumber(a)) and mw.getLanguage('de'):formatNum(a)
end
function p.diagramm(frame)
local args = getArgs(frame)
unit = tonumber(args['unit']) or 6
scale = tonumber(args['scale']) or 5
zelle = unit * scale
local data = {}
local maxvalue = 0
local minvalue = 0
local num = args['gruppe'] and 2 or 1
while (args['w'..num] or args['g'..num]) do
data[num] = {w = tonumber(args['w'..num]) or 0}
maxvalue = math.max(maxvalue, data[num].w)
minvalue = math.min(minvalue, data[num].w)
num = num+1
end
if minvalue < 0 then minneg = unit * (math.ceil(-minvalue/scale)) * scale + math.ceil(-minvalue/scale)
else minneg = 0
end
local anzahl = math.max((string.len(maxvalue)), string.len(math.abs(minvalue)))
local root = mw.html.create('div'):css('font-size', '80%'):css('padding-bottom', args['gruppe'] and '40px')
local index = {}
local i = 0
for datum = 1, 50 do i = i + 1
if args['w'..i] then table.insert(index, i) end
end
for k, v in pairs(index) do
height = unit * math.abs(tonumber(args['w'..v]) or 0) + math.floor(math.abs(tonumber(args['w'..v]) or 0)/scale)
gruppe = tonumber(args['gruppe'])
if args['gruppe'] then k = v - (math.floor((v-1)/(gruppe + 1))) * (gruppe + 1) end
if args['w'..v] then
breite = 8 * anzahl + 12 - (args['gruppe'] and 45 or 0) + v * 45
root:tag('div')
:wikitext('<div style="text-align:center;margin-top:-20px;height:20px">'.. (tonumber(args['w'..v]) and (tonumber(args['w'..v]) >= 0 and fnum(tonumber(args['w'..v])) or (args['d'..v] or '')) or 'N/A')..'</div>')
:wikitext('<div style="text-align:center;margin-top:'..height..'px;height:20px">'..(tonumber(args['w'..v]) and (tonumber(args['w'..v]) >= 0 and (args['d'..v] or '') or fnum(tonumber(args['w'..v]))) or args['d'..v])..'</div>')
:wikitext((args['w'..v] and args['g'..tonumber(v-1)]) and '<div class="hintergrundfarbe5" style="text-align:center;font-weight:bold;border:1px solid #C0C0C0;margin-top:'..minneg..'px;height:20px;width:'..(45 * tonumber(args['gruppe']) - 5)..'px;">'..(args['g'..tonumber(v-1)] or '')..'</div>' or '')
:css('position', 'absolute')
:css('margin-top', (tonumber(args['w'..v]) and tonumber(args['w'..v]) > 0 and - (height + 1 + 10 + minneg)..'px') or -10 - minneg..'px')
:css('margin-left', (8 * anzahl + 10 - (args['gruppe'] and 45 or 0) + (v - 1) * 45)..'px')
:css('width', '40px')
:css('height', height..'px')
:css('background-color', '#'..(args['gruppe'] and args['f'..k] or args['f'..v] or '6495ED'))
:done()
end
end
local rootdiv = mw.html.create('div'):css('font-size', '90%'):css('padding-top', '20px')
if tonumber(minvalue) < 0 then lowest = - (math.ceil(-minvalue/scale)) * scale else lowest = 0 end
local indez = {}
local t = -1
for datum = 1, 50 do t = t + 1
if lowest <= (math.ceil(maxvalue/scale)) * scale - (scale * t) then table.insert(indez, t) end
end
for k, v in pairs(indez) do
a = ((math.ceil(maxvalue/scale)) * scale - scale * v)
if args['infra'] and tonumber(args['infra']) == a then colorline = true end
line = ((math.ceil(maxvalue/scale)) * scale - scale * v) == 0 and '#000000' or (args['infra'] and tonumber(args['infra']) == a) and '#50C878' or '#CCCCCC'
space = (args['infra'] and tonumber(args['infra']) == a) and zelle - 3 or (lowest >= (math.ceil(maxvalue/scale)) * scale - (scale * v)) and 10 or zelle
border = (args['infra'] and tonumber(args['infra']) == a) and 3 or 1
rootdiv
:wikitext('<div style="position:relative;height:'..space..'px;width:'..breite..'px;border-top:'..border..'px solid'..line..';"><div class="hintergrundfarbe1" style="position:absolute;bottom:'..(space - 9)..'px;font-size:10px;padding-right:2px;"> '..fnum(a)..'</div></div>')
:done()
end
if tonumber(args['infra']) and not colorline then
rootdiv
:wikitext('<div style="position:absolute;margin-left:2.5px;margin-top:-'..(scale * unit * ((math.ceil(math.abs(minvalue)/scale) -1) + 1 + (args['infra']/scale)) + 10 + math.ceil(math.abs(minvalue)/scale) + math.floor(args['infra']/scale) + 1.5)..'px;width:'..(breite - 2.5)..'px;height:3px;background-color:#50C878"><div class="hintergrundfarbe1" style="position:absolute;bottom:-6.5px;font-size:10px;padding-right:2px;">'..fnum(tonumber(args['infra']))..'</div></div>')
:done()
end
return tostring(rootdiv)..tostring(root)
end
local function form(num)
return (tonumber(num) and mw.getLanguage('de'):formatNum(tonumber(num))) or '–'
end
function p.balken(frame)
local args = getArgs(frame)
local data, index = {}, {}
local i = 0
for a = 1, 30 do i = i + 1
if args['w' .. i] then table.insert(index, i) end
if args['a' .. i] then anmerkung = true end
end
local maxvalue = 0
local num = 1
while (args['w'..num]) do
data[num] = {w = tonumber(args['w'..num]),}
maxvalue = math.max(maxvalue, data[num].w)
num = num+1
end
local root = mw.html.create('table'):addClass('wikitable sortable'):css('font-size', '90%')
row = root:tag('tr')
row:tag('th')
:wikitext(args['titel'])
:attr('colspan', 3)
row = root:tag('tr')
row:tag('th')
:wikitext(args['untertitel1'])
:css('background-color', '#F0F0F0')
:css('font-size', '90%')
row:tag('th')
:wikitext(args['untertitel2'])
:attr('colspan', 2)
:css('background-color', '#F0F0F0')
:css('font-size', '90%')
for k, v in pairs(index) do
if args['a'..v] then anm = ' <sup>'..args['a'..v]..'</sup>' else anm = '' end
if args['d'..v] then
row = root:tag('tr')
row:tag('td')
:wikitext(args['d'..v].. anm)
:css('padding-right', '20px')
end
if args['w' .. v] then
row:tag('td')
:wikitext('<div style="margin-left:-6px;background-color:#'..(args['f'..v] or '6495ED')..';width:'.. args['w'..v]*(args['width'] or 100)/maxvalue..'px;height:1.2em"></div>')
:css('border-right', '0.1px solid #F0F0F0')
row:tag('td')
:wikitext(form(args['w'..v]))
:css('text-align', 'right')
:css('padding-left', '20px')
:css('padding-right', '20px')
end
end
if args['url'] and args['quelle'] then quelle = 'Quelle: ['..args['url']..' '..args['quelle']..']' end
if anmerkung or quelle then
row = root:tag('tr'):addClass('sortbottom')
row:tag('td')
:attr('colspan', '3')
end
for k, v in pairs(index) do
if (args['a'..v] and args['t'..v]) then
row = root:tag('tr'):addClass('sortbottom')
row:tag('td')
:wikitext('<sup>'..args['a'..v]..'</sup> '..args['t'..v]..'')
:attr('colspan', 3)
end
end
if quelle then
row = root:tag('tr'):addClass('sortbottom')
row:tag('td')
:wikitext(quelle)
:attr('colspan', 3)
end
return root
end
return p