Modul:Benutzer:Zukunft99
Zur Navigation springen
Zur Suche springen
Die Dokumentation für dieses Modul kann unter Modul:Benutzer:Zukunft99/Doku erstellt werden
local p = {}
local getArgs = require('Module:Arguments').getArgs
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 = 1
while (args['w'..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(math.abs(minvalue)/scale)*scale) + math.ceil(math.abs(minvalue)/scale)
else minneg = 0
end
local anzahl = math.max((string.len(maxvalue)), string.len(minvalue))
local root = mw.html.create('div'):css('font-size', '80%')
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 = math.abs(tonumber(args['w'..v]) or 0)*unit + math.ceil(math.abs(tonumber(args['w'..v]) or 0)/scale)
if args['w'..v] then
root:tag('div')
:wikitext('<div style="text-align:center;margin-top:-20px"><div style="height:20px">'.. (tonumber(args['w'..v]) and (tonumber(args['w'..v]) >= 0 and mw.getLanguage('de'):formatNum(tonumber(args['w'..v])) or (args['d'..v] or '')) or 'N/A')..'</div></div>')
:wikitext('<div style="text-align:center;margin-top:'..height..'px"><div style="height:20px">'..(tonumber(args['w'..v]) and (tonumber(args['w'..v]) >= 0 and (args['d'..v] or '') or mw.getLanguage('de'):formatNum(tonumber(args['w'..v]))) or args['d'..v])..'</div></div>')
:css('position', 'absolute')
:css('margin-top', (tonumber(args['w'..v]) and tonumber(args['w'..v]) > 0 and - (unit * args['w'..v] + math.ceil(args['w'..v]/scale) + zelle + minneg)..'px') or - zelle - minneg..'px')
:css('margin-left', (-40 + 8 * anzahl + v * 45)..'px')
:css('width', '40px')
:css('height', height..'px')
:css('background-color', '#'..(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(math.abs(minvalue)/scale))* scale else lowest = 0 end
local indez = {}
local t = -1
for datum = 1, 100000 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
if ((math.ceil(maxvalue/scale)) * scale - scale * v) == 0 then line = '#000000' else line = '#CCCCCC' end
rootdiv:tag('div')
:wikitext('<div style="position:relative;height:'..zelle..'px;width:200px;border-top:1px solid'..line..';"><div style="position:absolute;bottom:'..(zelle - 9)..'px;background-color:#FFFFFF;font-size:10px; padding:0 2px 0 0; color:#777;"> '..mw.getLanguage('de'):formatNum(((math.ceil(maxvalue/scale)) * scale - scale * v))..'</div></div>')
:done()
end
return tostring(rootdiv)..tostring(root)
end
return p