Module:Progress pie chart

For {{progress pie chart}}.


local p = {} --p stands for package

local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local chart = require('Module:Graph').chart

function p._progress_pie_chart(args)
	-- args
	local size = args.size or 120
	
	local legend
	if yesno(args.no_legend or 'no') then
		legend = 0
	else
		legend = args.legend or "Legend"
	end
	
	local existing_only = yesno(args.existing_only or 'no')
	
	local x = "Validated,Proofread,Problematic,Not Proofread,Without text"
	if not existing_only then
		x = x .. ",Not yet created"
	end
	
	local total = tonumber(args.total) or 0
	local validated = tonumber(args.validated) or 0
	local proofread = tonumber(args.proofread) or 0
	local problematic = tonumber(args.problematic) or 0
	local not_proofread = tonumber(args.not_proofread) or 0
	local notext = tonumber(args.notext) or 0
	
	local statuses = {
		validated, proofread, problematic, not_proofread, notext
	}
	if not existing_only then
		table.insert(statuses, total - (validated + proofread + problematic + not_proofread + notext))
	end
	local y1 = table.concat(statuses, ",")
	
	local colors = args.colors or "#80FF80,#FFFF80,#B0B0FF,#FFA0A0,#DDDDDD,#FFFFFF"
	
	-- chart
	local chartArgs = {
		width = size,
		height = size,
		['type'] = "pie",
		legend = legend,
		x = x,
		y1 = y1,
		colors = colors,
		linecolor = "#a0a0a0"
	}
	return chart({args = chartArgs})
end

function p.progress_pie_chart(frame)
	return p._progress_pie_chart(getArgs(frame))
end

return p