Module:Bar percent

require "Module:ColourGen" require "Module:SortedKeys" function _BarPercent(name,color,barwidth,width,percentage) local to_return = " " .. name .. "  &thinsp;  " if percentage == nil or percentage == 0 or percentage == "0" then if width == nil or width == 0 or width == "0" then to_return = to_return .. "0%"		else to_return = to_return .. width .. "%"		end else to_return = to_return .. percentage end to_return = to_return .. " "	return to_return end

function GenerateBar(tabula,barwidth) local to_return = "" local colours = Colgen(#tabula) local i = 0 for k,v in pairs(tabula) do   	i = i + 1 to_return = to_return .. _BarPercent(k,colours[i],barwidth,v,0) end return to_return --return colours[i] end

function ConstructPercentBar(tabula,barwidth) local to_return = "" local size = 0 for _ in pairs(tabula) do		size = size + 1 end --local colours = Colgen(#tabula) --table.sort(tabula, function(a,b) return a < b end) local colours = Colgen(size) local total = 0 for k,v in pairs(tabula) do   	total = total + v	end local temp_tbl = { } local i = 0 for k,v in pairs(tabula) do   	i = i + 1 temp_tbl[i] = {k, (math.ceil(v/total*10000))/100 } end table.sort(temp_tbl, function(a,b) return a[2] > b[2] end) for k,v in pairs(temp_tbl) do to_return = to_return .. _BarPercent(v[1],colours[k],barwidth,v[2],0) end return to_return --return colours[i] end

local p = { } function p.BarPercent(frame) return _BarPercent(frame.args[1],frame.args[2],frame.args[3],frame.args[4],frame.args[5]) end function p.code_BarPercent(frame) local to_return = " " return to_return end function p.GenerateBar(frame) --local tbl = { 10, 20, 30, 40, 50, 60 } local tbl = { } tbl["Area"] = 55 tbl["Bar"] = 66 tbl["Cic"] = 88 return ConstructPercentBar(tbl,frame.args[1]) end return p