Die Dokumentation für dieses Modul kann unter Modul:Benutzer:Zukunft99/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]) 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, 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
		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;">&nbsp;'..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

return p